/* ===================================================
   福祉Mk4 — シンプル & クリーンデザイン
   清潔感のある福祉システム向けトーン
   =================================================== */

:root {
  --color-bg: #f7f8fa;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-border-strong: #d1d5db;
  --color-text: #1f2937;
  --color-text-sub: #6b7280;
  --color-text-mute: #9ca3af;
  --color-primary: #1e3a5f;     /* ネイビー */
  --color-primary-hover: #15294a;
  --color-primary-light: #e8eef5;
  --color-accent: #0d9488;      /* teal (アクセント) */
  --color-success: #059669;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --color-info: #2563eb;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN',
               'Yu Gothic', 'Meiryo', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* スクロールバー */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ===== タイポグラフィ ===== */
.h1 { font-size: 20px; font-weight: 600; color: var(--color-text); margin: 0; letter-spacing: 0.01em; }
.h2 { font-size: 16px; font-weight: 600; color: var(--color-text); margin: 0; }
.h3 { font-size: 14px; font-weight: 600; color: var(--color-text); margin: 0; }
.text-sub { color: var(--color-text-sub); }
.text-mute { color: var(--color-text-mute); font-size: 12px; }

/* ===== レイアウト ===== */
.app-shell {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ===== トップヘッダー ===== */
.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: 30;
  padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.topbar-brand {
  display: flex; align-items: center; gap: 12px;
}
.topbar-logo {
  width: 36px; height: 36px;
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; letter-spacing: 0.05em;
}
.topbar-title { font-size: 15px; font-weight: 600; color: var(--color-text); }
.topbar-sub { font-size: 11px; color: var(--color-text-sub); margin-top: 1px; }

.topnav { display: flex; gap: 4px; }
.topnav a, .topnav button {
  background: transparent; border: 0; cursor: pointer;
  padding: 8px 14px; font-size: 13px; color: var(--color-text-sub);
  border-radius: var(--radius); font-weight: 500;
}
.topnav a:hover, .topnav button:hover { background: var(--color-bg); color: var(--color-text); }
.topnav .is-active { background: var(--color-primary-light); color: var(--color-primary); font-weight: 600; }

.topbar-user {
  display: flex; align-items: center; gap: 10px;
  padding-left: 16px;
  border-left: 1px solid var(--color-border);
  font-size: 13px; color: var(--color-text-sub);
}

/* ===== モバイル底部タブ ===== */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-list { display: grid; grid-template-columns: repeat(4, 1fr); }
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 8px 4px 6px;
  background: none; border: 0; cursor: pointer;
  color: var(--color-text-mute);
  font-size: 11px; font-weight: 500;
  min-height: 56px;
}
.bottom-nav-item i { font-size: 18px; margin-bottom: 2px; }
.bottom-nav-item.is-active { color: var(--color-primary); }

/* ===== メインコンテナ ===== */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}
.container-narrow { max-width: 900px; margin: 0 auto; padding: 20px; }

/* ===== パネル/カード ===== */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.panel-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-header .panel-title { font-size: 14px; font-weight: 600; color: var(--color-text); }
.panel-body { padding: 18px; }
.panel-body-flush { padding: 0; }

/* ===== KPIカード（シンプル化） ===== */
.kpi {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.kpi-label { font-size: 12px; color: var(--color-text-sub); margin-bottom: 4px; }
.kpi-value { font-size: 24px; font-weight: 600; color: var(--color-text); line-height: 1.2; }
.kpi-sub { font-size: 11px; color: var(--color-text-mute); margin-top: 4px; }

/* ===== ボタン ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500; line-height: 1.4;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.12s ease;
  text-decoration: none;
  min-height: 36px;
  user-select: none;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: white; color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-success { background: var(--color-success); color: white; }
.btn-success:hover { background: #047857; }
.btn-danger { background: var(--color-danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--color-text-sub); }
.btn-ghost:hover { background: var(--color-bg); color: var(--color-text); }
.btn-sm { padding: 5px 10px; font-size: 12px; min-height: 30px; }
.btn-lg { padding: 12px 22px; font-size: 14px; min-height: 44px; }
.btn-block { width: 100%; }
.btn-icon { padding: 6px 10px; min-height: 36px; }

/* ===== フォーム ===== */
.field { margin-bottom: 12px; }
.label {
  display: block; font-size: 12px; font-weight: 500;
  color: var(--color-text-sub); margin-bottom: 4px;
}
.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  font-size: 14px; line-height: 1.4;
  background: white; color: var(--color-text);
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.12);
}
.input:read-only { background: var(--color-bg); color: var(--color-text-sub); }
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

/* ===== バッジ ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px; font-weight: 500;
  border: 1px solid transparent;
  line-height: 1.5;
}
.badge-kourei { background: #eff6ff; color: #1e40af; border-color: #dbeafe; }
.badge-shougai { background: #fdf2f8; color: #9d174d; border-color: #fbcfe8; }
.badge-A { background: #ecfdf5; color: #065f46; border-color: #d1fae5; }
.badge-B { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.badge-active { background: #f0fdf4; color: #166534; border-color: #dcfce7; }
.badge-stopped { background: #fef2f2; color: #991b1b; border-color: #fee2e2; }
.badge-warn { background: #fffbeb; color: #92400e; border-color: #fef3c7; }
.badge-mute { background: #f3f4f6; color: #4b5563; border-color: #e5e7eb; }

/* ===== テーブル ===== */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th {
  background: var(--color-bg);
  color: var(--color-text-sub);
  font-weight: 600; font-size: 11px; letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.tbl td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.tbl tbody tr:hover { background: var(--color-bg); }
.tbl tbody tr.is-claim td:first-child { box-shadow: inset 3px 0 0 var(--color-warning); }
.tbl tbody tr.is-stopped td { color: var(--color-text-mute); }
.tbl-clickable tbody tr { cursor: pointer; }
.tbl-clickable tbody tr.is-selected { background: var(--color-primary-light) !important; }
.tbl tfoot td { background: var(--color-bg); font-weight: 600; }

.tbl-compact th, .tbl-compact td { padding: 6px 10px; font-size: 12px; }

.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ===== リストアイテム（モバイル名簿用） ===== */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  background: var(--color-surface);
  min-height: 56px;
}
.list-item:hover { background: var(--color-bg); }
.list-item.is-selected { background: var(--color-primary-light); }
.list-item-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--color-bg);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-sub);
  font-size: 13px; font-weight: 600;
  flex-shrink: 0;
  border: 1px solid var(--color-border);
}
.list-item.is-claim .list-item-avatar { background: #fffbeb; color: var(--color-warning); border-color: #fef3c7; }
.list-item.is-stopped .list-item-avatar { background: #fef2f2; color: var(--color-danger); border-color: #fee2e2; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-size: 14px; font-weight: 600; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub { font-size: 12px; color: var(--color-text-sub); margin-top: 1px; display: flex; gap: 6px; align-items: center; }
.list-item-trail { display: flex; align-items: center; gap: 6px; }

/* ===== タブ ===== */
.tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  background: transparent; border: 0;
  padding: 12px 18px;
  font-size: 13px; font-weight: 500;
  color: var(--color-text-sub); cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  min-height: 44px;
}
.tab:hover { color: var(--color-text); }
.tab.is-active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: 600;
}

/* ===== チップ群（月切替など） ===== */
.chip-group { display: inline-flex; gap: 4px; padding: 3px; background: var(--color-bg); border-radius: var(--radius); }
.chip {
  background: transparent; border: 0;
  padding: 6px 14px;
  font-size: 13px; font-weight: 500; color: var(--color-text-sub);
  border-radius: 4px; cursor: pointer;
  min-height: 32px;
}
.chip:hover { color: var(--color-text); }
.chip.is-active { background: white; color: var(--color-primary); box-shadow: var(--shadow-sm); font-weight: 600; }

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 540px;
  max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.18s ease;
}
.modal-lg { max-width: 720px; }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--color-border); }
.modal-title { font-size: 16px; font-weight: 600; color: var(--color-text); margin: 0; }
.modal-body { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--color-border); display: flex; gap: 8px; justify-content: flex-end; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: translateY(4px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ===== トースト ===== */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: var(--color-text); color: white;
  padding: 10px 18px;
  border-radius: var(--radius);
  z-index: 200;
  box-shadow: var(--shadow-lg);
  font-size: 13px; font-weight: 500;
  animation: slideDown 0.25s ease;
}
.toast-success { background: var(--color-success); }
.toast-error { background: var(--color-danger); }
@keyframes slideDown { from { transform: translate(-50%, -100%); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }

/* ===== グリッド ===== */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

/* ===== ユーティリティ ===== */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 0; }
.w-full { width: 100%; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-mono { font-family: 'SF Mono', Monaco, 'Courier New', monospace; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-5 { margin-bottom: 20px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.p-3 { padding: 12px; } .p-4 { padding: 16px; }
.hidden { display: none; }

/* ===== サマリーボックス（注文合計など） ===== */
.summary {
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
}
.summary-item { min-width: 0; }
.summary-label { font-size: 11px; color: var(--color-text-sub); margin-bottom: 2px; }
.summary-value { font-size: 18px; font-weight: 600; color: var(--color-text); }
.summary-value.is-warn { color: var(--color-warning); }
.summary-value.is-danger { color: var(--color-danger); }
.summary-value.is-primary { color: var(--color-primary); }

/* ===== 注意ボックス ===== */
.notice {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px; line-height: 1.6;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
}
.notice-info { background: #eff6ff; border-color: #dbeafe; color: #1e40af; }
.notice-warn { background: #fffbeb; border-color: #fef3c7; color: #92400e; }
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.notice li { margin: 2px 0; }

/* ===== 区切り ===== */
.divider { height: 1px; background: var(--color-border); margin: 16px 0; }

/* ===== クレーム/履歴 カード ===== */
.note-card {
  border-left: 3px solid var(--color-warning);
  background: #fffbf3;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.note-card-meta { font-size: 11px; color: var(--color-text-sub); display: flex; justify-content: space-between; margin-bottom: 4px; }
.note-card-body { font-size: 13px; color: var(--color-text); }

/* ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
   レスポンシブ — スマートフォン最適化 (max-width: 768px)
   ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== */
@media (max-width: 768px) {
  body { font-size: 14px; }

  /* トップヘッダーは縮める、ナビは底部タブへ */
  .topbar { padding: 10px 14px; }
  .topbar-title { font-size: 14px; }
  .topbar-sub { display: none; }
  .topnav { display: none; }
  .topbar-user { display: none; }
  .topbar-user-mobile { display: flex; }

  /* 底部タブバー表示 */
  .bottom-nav { display: block; }

  /* 下方向の余白（底部タブの分） */
  .app-shell { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

  /* コンテナ */
  .container, .container-narrow { padding: 14px; }

  /* グリッドを2列以下に */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid-stack-sm { grid-template-columns: 1fr !important; }

  /* KPIをコンパクトに */
  .kpi { padding: 12px; }
  .kpi-value { font-size: 20px; }

  /* パネル */
  .panel-body { padding: 14px; }
  .panel-header { padding: 12px 14px; }

  /* サマリーを2列に */
  .summary { grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 12px; }
  .summary-value { font-size: 16px; }

  /* テーブルを横スクロール */
  .tbl-wrap { margin: 0 -14px; padding: 0 14px; }

  /* モーダル */
  .modal { max-height: 95vh; }
  .modal-body { padding: 16px; }
  .modal-header { padding: 14px 16px; }
  .modal-footer { padding: 12px 16px; }

  /* タブ */
  .tab { padding: 12px 14px; font-size: 12px; }

  /* ボタン: タップしやすく */
  .btn { min-height: 40px; padding: 9px 16px; }
  .btn-sm { min-height: 32px; }
}

/* 小さい画面 (480px以下) */
@media (max-width: 480px) {
  .topbar-logo { width: 32px; height: 32px; font-size: 12px; }
  .topbar-title { font-size: 13px; }
  .h1 { font-size: 18px; }
  .summary { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* スマホ表示時のみ表示する要素 */
.topbar-user-mobile { display: none; }
.show-mobile { display: none; }
@media (max-width: 768px) {
  .show-mobile { display: block; }
  .show-mobile-flex { display: flex !important; }
  .hide-mobile { display: none !important; }
}

/* ===== ログイン画面 ===== */
.login-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-bg);
  padding: 20px;
}
.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-md);
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-logo {
  width: 56px; height: 56px;
  margin: 0 auto 12px;
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; letter-spacing: 0.05em;
}
.login-title { font-size: 18px; font-weight: 600; color: var(--color-text); margin: 0; }
.login-sub { font-size: 12px; color: var(--color-text-sub); margin-top: 4px; }
.login-foot { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--color-border); font-size: 11px; color: var(--color-text-mute); text-align: center; line-height: 1.7; }

@media (max-width: 480px) {
  .login-card { padding: 28px 22px; }
}

/* ===== 印刷スタイル ===== */
@media print {
  body { background: white; }
  .no-print, .topbar, .bottom-nav { display: none !important; }
  .panel, .kpi { border: none; box-shadow: none; }
  .container { padding: 0; max-width: 100%; }
  @page { size: A4; margin: 1cm; }
  .tbl th, .tbl td { border: 1px solid #999 !important; }
  .print-page-break { page-break-after: always; }
}

/* スマホ向け: 名簿の詳細ボトムシート表示 */
.detail-sheet {
  position: fixed; inset: 0;
  background: var(--color-surface);
  z-index: 50;
  display: flex; flex-direction: column;
  animation: slideUp 0.22s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.detail-sheet-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; background: var(--color-surface);
}
.detail-sheet-body { flex: 1; overflow-y: auto; }

/* デスクトップでは詳細シートはインライン化 */
@media (min-width: 769px) {
  .detail-sheet {
    position: static;
    box-shadow: none;
    animation: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
  }
  .detail-sheet-header.show-mobile-only { display: none; }
}
