/* ===== リセット & 基本 ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #2e7d5e;
  --primary-light: #4caf87;
  --primary-dark: #1b5e42;
  --secondary: #f5f9f7;
  --accent: #ff8f00;
  --accent-soft: #fff3e0;
  --danger: #d32f2f;
  --danger-soft: #ffebee;
  --info: #1565c0;
  --info-soft: #e3f2fd;
  --success: #2e7d32;
  --success-soft: #e8f5e9;
  --gray1: #f8f9fa;
  --gray2: #e9ecef;
  --gray3: #ced4da;
  --gray4: #6c757d;
  --gray5: #343a40;
  --white: #ffffff;
  --text: #2c3e50;
  --sidebar-w: 220px;
  --header-h: 58px;
  --header-h-mobile: 64px;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.10);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.08);
  --font: 'Noto Sans JP', 'Meiryo', 'Yu Gothic', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--secondary);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== ヘッダー ===== */
#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

#app-header .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--white);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

#app-header .logo span {
  font-size: 22px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#role-badge {
  background: rgba(255, 255, 255, 0.2);
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

#role-badge:hover {
  background: rgba(255, 255, 255, 0.35);
}

.header-date {
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
}

/* ===== サイドバー ===== */
#sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--gray2);
  overflow-y: auto;
  z-index: 90;
  transition: transform 0.3s;
}

#sidebar nav {
  padding: 14px 0;
}

.nav-section {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray4);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: var(--gray5);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-size: 14px;
  border-left: 3px solid transparent;
  user-select: none;
}

.nav-item:hover {
  background: var(--secondary);
  color: var(--primary);
}

.nav-item.active {
  background: #e8f5ef;
  color: var(--primary-dark);
  font-weight: 700;
  border-left-color: var(--primary);
}

.nav-item .icon {
  font-size: 18px;
  width: 22px;
  text-align: center;
}

.nav-item.admin-only,
.nav-item.keiri-only,
.nav-section.admin-only,
.nav-section.keiri-only {
  display: none;
}

body.role-admin .nav-item.admin-only,
body.role-admin .nav-item.keiri-only {
  display: flex;
}

body.role-admin .nav-section.admin-only,
body.role-admin .nav-section.keiri-only {
  display: block;
}

body.role-keiri .nav-item,
body.role-keiri .nav-section {
  display: none !important;
}

body.role-keiri .nav-item.keiri-only {
  display: flex !important;
}

body.role-keiri .nav-section.keiri-only {
  display: block !important;
}

body.role-helper .admin-only,
body.role-helper .keiri-only {
  display: none !important;
}

/* ===== メインコンテンツ ===== */
#main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--header-h);
  padding: 24px;
  min-height: calc(100vh - var(--header-h));
}

.page {
  display: none;
}

.page.active {
  display: block;
}

/* ===== ページタイトル ===== */
.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--gray2);
}

.page-title .icon {
  font-size: 22px;
}

/* ===== カード ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray2);
  padding: 20px;
  margin-bottom: 18px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ===== ダッシュボード ===== */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray2);
  text-align: center;
  transition: box-shadow 0.2s, transform 0.2s;
  cursor: default;
}

.stat-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.stat-card .num {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.1;
}

.stat-card .label {
  font-size: 12px;
  color: var(--gray4);
  margin-top: 4px;
}

.stat-card.orange .num {
  color: var(--accent);
}

.stat-card.red .num {
  color: var(--danger);
}

.stat-card.blue .num {
  color: var(--info);
}

/* ===== フォーム ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid.col3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.full {
  grid-column: 1 / -1;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray5);
}

label .req {
  color: var(--danger);
  margin-left: 3px;
}

input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--gray3);
  border-radius: 7px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--white);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(46, 125, 94, 0.12);
}

textarea {
  resize: vertical;
  min-height: 70px;
}

input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* チェックボックスグループ */
.check-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 6px 0;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
}

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border: none;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
  user-select: none;
}

.btn:hover {
  opacity: 0.85;
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-secondary {
  background: var(--gray2);
  color: var(--gray5);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 28px;
  font-size: 16px;
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 18px;
}

/* ===== テーブル ===== */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table th {
  background: var(--primary);
  color: #fff;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  position: sticky;
  top: 0;
}

table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--gray2);
  vertical-align: middle;
}

table tr:nth-child(even) td {
  background: var(--gray1);
}

table tr:hover td {
  background: #e8f5ef;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}

.badge-plan {
  background: var(--info-soft);
  color: var(--info);
}

.badge-done {
  background: var(--success-soft);
  color: var(--success);
}

.badge-partial {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-miss {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-pending {
  background: var(--gray2);
  color: var(--gray4);
}

.badge-body {
  background: #e8eaf6;
  color: #3949ab;
}

.badge-life {
  background: #f3e5f5;
  color: #7b1fa2;
}

.badge-ride {
  background: #fff8e1;
  color: #f57f17;
}

/* ===== ステータスドット ===== */
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
}

.dot-plan {
  background: var(--info);
}

.dot-done {
  background: var(--success);
}

.dot-miss {
  background: var(--danger);
}

/* ===== カレンダー ===== */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.cal-header h3 {
  font-size: 17px;
  color: var(--primary-dark);
  font-weight: 700;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-day-label {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 0;
  color: var(--gray4);
}

.cal-day-label:first-child {
  color: #d32f2f;
}

.cal-day-label:last-child {
  color: #1565c0;
}

.cal-cell {
  min-height: 80px;
  background: var(--white);
  border-radius: 7px;
  border: 1px solid var(--gray2);
  padding: 5px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.cal-cell:hover {
  background: var(--secondary);
}

.cal-cell.today {
  border-color: var(--primary);
  border-width: 2px;
}

.cal-cell.empty {
  background: none;
  border-color: transparent;
  cursor: default;
}

.cal-date {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray5);
  margin-bottom: 3px;
}

.cal-cell.sun .cal-date {
  color: #d32f2f;
}

.cal-cell.sat .cal-date {
  color: #1565c0;
}

.cal-event {
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 4px;
  margin-bottom: 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cal-event.plan {
  background: var(--info-soft);
  color: var(--info);
}

.cal-event.done {
  background: var(--success-soft);
  color: var(--success);
}

.cal-event.miss {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ===== フィルタバー ===== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  background: var(--white);
  border: 1px solid var(--gray2);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
}

.filter-bar .form-group {
  min-width: 160px;
}

.filter-bar .form-group label {
  font-size: 12px;
}

.filter-bar .form-group select,
.filter-bar .form-group input {
  font-size: 13px;
  padding: 7px 10px;
}

/* ===== 実績入力 ===== */
.record-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.record-card {
  background: var(--white);
  border: 1.5px solid var(--gray2);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s;
}

.record-card.selected {
  border-color: var(--primary);
  background: var(--secondary);
}

.record-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  cursor: pointer;
}

.record-card-header h4 {
  font-size: 15px;
  color: var(--primary-dark);
  font-weight: 700;
}

.record-expand {
  font-size: 11px;
  color: var(--gray4);
  display: flex;
  align-items: center;
  gap: 5px;
}

.record-detail {
  display: none;
}

.record-detail.open {
  display: block;
}

.vital-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 10px 0;
}

.vital-item label {
  font-size: 12px;
}

.vital-item input {
  padding: 7px 10px;
}

/* ===== 印刷 ===== */
@media print {

  #app-header,
  #sidebar,
  .no-print {
    display: none !important;
  }

  #main-content {
    margin: 0;
    padding: 0;
  }

  .page {
    display: block !important;
  }

  table th {
    background: #ddd !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .btn {
    display: none !important;
  }

  body {
    font-size: 11px;
  }
}

/* ===== タブ ===== */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gray2);
  margin-bottom: 18px;
  overflow-x: auto;
  /* スマホ等で溢れた場合に横スクロール可能にする */
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

.tab-bar::-webkit-scrollbar {
  display: none;
  /* スクロールバー自体は隠す（デザイン優先） */
}

.tab-btn {
  padding: 9px 22px;
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--gray4);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
  flex: 0 0 auto;
  /* 横並び時に縮まないように固定 */
}

.tab-btn.active {
  color: var(--primary-dark);
  border-bottom-color: var(--primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--white);
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
  padding: 28px;
  width: 92%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary-dark);
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--gray4);
  padding: 0 4px;
}

/* ===== トースト ===== */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--primary-dark);
  color: #fff;
  padding: 13px 22px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.2);
  display: none;
  z-index: 999;
  animation: slideup 0.3s ease;
}

@keyframes slideup {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ===== ロール切替ダイアログ ===== */
#role-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
}

#role-dialog.open {
  display: flex;
}

.role-box {
  background: var(--white);
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
  width: 340px;
}

.role-box h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 10px;
}

.role-box p {
  color: var(--gray4);
  font-size: 13px;
  margin-bottom: 22px;
}

.role-choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.role-btn {
  padding: 14px 20px;
  border-radius: 10px;
  border: 2px solid var(--gray2);
  background: var(--white);
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.role-btn:hover,
.role-btn.active {
  border-color: var(--primary);
  background: var(--secondary);
  color: var(--primary-dark);
}

.role-btn .ricon {
  font-size: 24px;
  margin-right: 8px;
}

/* ===== レスポンシブ ===== */
@media (max-width: 900px) {
  :root {
    --sidebar-w: 0px;
    --header-h: 58px;
  }

  #sidebar {
    position: sticky;
    top: var(--header-h);
    left: 0;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--gray2);
    transform: none !important;
    z-index: 80;
    background: var(--white);
    overflow-x: auto;
    overflow-y: hidden;
  }

  #sidebar nav {
    display: flex;
    flex-direction: row;
    padding: 0;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .nav-section {
    display: none !important;
    /* スマホ時はセクションラベルを隠す */
  }

  .nav-item.keiri-only {
    display: none !important;
  }

  .nav-item {
    flex: 0 0 auto;
    padding: 10px 16px;
    border-left: none;
    border-bottom: 3px solid transparent;
    font-size: 13px;
    gap: 6px;
  }

  .nav-item.active {
    border-left: none;
    border-bottom-color: var(--primary);
    background: var(--secondary);
  }

  .nav-item .icon {
    font-size: 16px;
    width: auto;
  }

  #main-content {
    margin-left: 0 !important;
    margin-top: 0 !important;
    /* sidebar is sticky, header is fixed */
    padding: 12px;
  }

  /* Fixed header + Sticky sidebar layout adjustment */
  body {
    padding-top: var(--header-h);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid.col3 {
    grid-template-columns: 1fr;
  }

  .dash-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .vital-row {
    grid-template-columns: 1fr;
  }

  #menu-toggle {
    display: none !important;
    /* ハンバーガーメニューは不要 */
  }
}

/* 非常に狭い画面（iPhone SE, 12/13/14/15/16 Pro 縦向きなど）向けのヘッダー微調整 */
@media (max-width: 440px) {
  :root {
    --header-h: var(--header-h-mobile);
  }

  #app-header {
    padding: 0 10px;
  }

  #app-header .logo {
    gap: 6px;
    font-size: 14px;
    line-height: 1.2;
    flex: 1;
    min-width: 0;
  }

  #app-header .logo span {
    font-size: 18px;
    flex-shrink: 0;
  }

  #office-name {
    white-space: normal;
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .header-right {
    gap: 8px;
    flex-shrink: 0;
  }

  #role-badge {
    padding: 3px 10px;
    font-size: 11px;
    border-width: 1px;
  }

  .header-date {
    display: none;
    /* 狭い画面では日付を非表示にしてスペースを確保 */
  }

  #sidebar {
    top: var(--header-h);
  }

  body {
    padding-top: var(--header-h);
  }
}

#menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  font-size: 22px;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
}

/* ===== 接続インジケータ ===== */
.conn-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  white-space: nowrap;
}

.conn-indicator:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.conn-dot-green {
  background: #4caf50;
  box-shadow: 0 0 6px rgba(76, 175, 80, 0.6);
  animation: conn-pulse 2s infinite;
}

.conn-dot-yellow {
  background: #ff9800;
  box-shadow: 0 0 6px rgba(255, 152, 0, 0.5);
}

.conn-dot-red {
  background: #f44336;
  box-shadow: 0 0 6px rgba(244, 67, 54, 0.5);
}

@keyframes conn-pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

.conn-label {
  font-size: 11px;
}

/* ===== 接続メニュー ===== */
.conn-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--white);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--gray2);
  min-width: 240px;
  z-index: 300;
  padding: 8px 0;
  animation: conn-menu-in 0.15s ease-out;
}

@keyframes conn-menu-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.conn-menu-status {
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray5);
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--gray2);
  margin-bottom: 4px;
}

.conn-menu-item {
  display: block;
  width: 100%;
  padding: 9px 16px;
  border: none;
  background: none;
  font-size: 13px;
  font-family: var(--font);
  color: var(--gray5);
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}

.conn-menu-item:hover {
  background: var(--secondary);
}

.conn-menu-primary {
  color: var(--primary);
  font-weight: 600;
}

.conn-menu-danger {
  color: var(--danger);
}

.conn-menu-danger:hover {
  background: var(--danger-soft);
}

/* ===== DB接続ダイアログ ===== */
.db-connect-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.25s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* ===== ローディングインジケータ ===== */
#global-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  backdrop-filter: blur(2px);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

#loading-msg {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-dark);
}

/* ===== レスポンシブ: 接続インジケータ ===== */
@media (max-width: 768px) {
  .conn-label {
    display: none;
  }

  .conn-indicator {
    padding: 4px 8px;
  }
}

.conn-disconnected {
  background: rgba(244, 67, 54, 0.15) !important;
  border-color: rgba(244, 67, 54, 0.4) !important;
  animation: conn-blink 2s ease-in-out infinite;
}

.conn-dot-yellow {
  background: #ffc107;
  box-shadow: 0 0 6px rgba(255, 193, 7, 0.6);
}

@keyframes conn-blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

/* ===== 計画登録ミニカレンダー ===== */
.plan-calendar {
  border: 1.5px solid var(--gray2);
  border-radius: var(--radius);
  background: var(--white);
  padding: 12px;
  margin-top: 8px;
}

.plan-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.plan-cal-header h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 0;
}

.plan-cal-header button {
  background: var(--gray2);
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--gray5);
  transition: background 0.15s;
}

.plan-cal-header button:hover {
  background: var(--gray3);
}

.plan-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.plan-cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray4);
  padding: 4px 0;
}

.plan-cal-dow:first-child {
  color: #d32f2f;
}

.plan-cal-dow:last-child {
  color: #1565c0;
}

.plan-cal-cell {
  text-align: center;
  padding: 7px 2px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, transform 0.1s;
  user-select: none;
  font-weight: 500;
  position: relative;
}

.plan-cal-cell:hover {
  background: var(--secondary);
  transform: scale(1.05);
}

.plan-cal-cell.empty {
  cursor: default;
  background: none;
}

.plan-cal-cell.empty:hover {
  transform: none;
}

.plan-cal-cell.today {
  font-weight: 800;
  box-shadow: inset 0 0 0 2px var(--primary-light);
}

.plan-cal-cell.preset-dow {
  background: var(--info-soft);
  border: 1.5px dashed var(--info);
}

.plan-cal-cell.preset-color-0 {
  background: #e3f2fd;
  border: 1.5px dashed #2196f3;
}

.plan-cal-cell.preset-color-1 {
  background: #e8f5e9;
  border: 1.5px dashed #4caf50;
}

.plan-cal-cell.preset-color-2 {
  background: #fff3e0;
  border: 1.5px dashed #ff9800;
}

.plan-cal-cell.preset-color-3 {
  background: #f3e5f5;
  border: 1.5px dashed #9c27b0;
}

.plan-cal-cell.preset-color-4 {
  background: #fce4ec;
  border: 1.5px dashed #e91e63;
}

.plan-cal-cell.selected {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.plan-cal-cell.selected:hover {
  background: var(--primary-dark);
}

.plan-cal-cell.sun {
  color: #d32f2f;
}

.plan-cal-cell.sat {
  color: #1565c0;
}

.plan-cal-cell.selected.sun,
.plan-cal-cell.selected.sat {
  color: #fff;
}

.plan-cal-cell.past {
  opacity: 0.4;
}

/* 日付チップ */
.date-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--info-soft);
  color: var(--info);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 14px;
  white-space: nowrap;
}

.chip-del {
  background: none;
  border: none;
  color: var(--info);
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  font-weight: 700;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.chip-del:hover {
  opacity: 1;
}

/* ===== 利用者モーダル: 基本計画セクション ===== */
.preset-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 2px solid var(--gray2);
}

.preset-section .section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dow-check-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.dow-check-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 36px;
  border: 1.5px solid var(--gray3);
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  color: var(--gray5);
  background: var(--white);
}

.dow-check-label:hover {
  border-color: var(--primary-light);
  background: var(--secondary);
}

.dow-check-label.checked {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.dow-check-label input[type="checkbox"] {
  display: none;
}

/* ===== 実績集計テーブル ===== */
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.stats-table th {
  text-align: center;
  white-space: nowrap;
  padding: 10px 8px;
  font-size: 11px;
}

.stats-table td {
  padding: 9px 8px;
}

.stats-table td:first-child {
  white-space: nowrap;
  min-width: 100px;
}

.num-cell {
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  min-width: 48px;
}

.num-cell.has-value {
  color: var(--primary-dark);
  font-weight: 700;
  background: rgba(46, 125, 94, 0.06);
}

.total-cell {
  font-weight: 800 !important;
  color: var(--primary-dark) !important;
  background: rgba(46, 125, 94, 0.08) !important;
  font-size: 15px;
}

.grand-total-row td {
  border-top: 2px solid var(--primary);
  background: var(--secondary) !important;
  font-weight: 700;
}

@media print {

  /* 印刷時は不要要素を非表示化 */
  #app-header,
  #sidebar,
  .no-print {
    display: none !important;
  }

  /* メインコンテンツエリアの余白をなくす */
  #main-content {
    margin: 0 !important;
    padding: 0 !important;
  }

  /* 非アクティブなページは確実に隠す */
  .page:not(.active) {
    display: none !important;
  }

  .stats-table th {
    background: #ddd !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .num-cell.has-value {
    color: #000;
    background: #e8f5e9 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .total-cell {
    background: #e0e0e0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .grand-total-row td {
    background: #d5d5d5 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ドラッグ＆ドロップ用スタイル */
.drag-handle {
  cursor: grab;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--gray4);
  font-size: 18px;
  user-select: none;
  margin-right: 8px;
  transition: color 0.2s;
}

.drag-handle:hover {
  color: var(--primary);
}

.drag-handle:active {
  cursor: grabbing;
}

tr.dragging {
  opacity: 0.5;
  background-color: var(--secondary) !important;
}

tr.drag-over {
  border-top: 3px solid var(--primary);
}