/* ==================================================================
   KOUBO KANRI 管理画面 共通シェル CSS v2.0

   ★ 2層レイヤー構造（DESIGN.md v2.0 準拠）
     Chrome（サイドバー・トップバー）= ダークネイビー
     Content（.page-wrap 以下）       = ライト背景 + 濃紺文字

   ★ 各ページは .card / .section-title / .kpi-tile 等を
     ここから継承する。ページ側 <style> で再定義しない。
   ================================================================== */

/* ==== トークン ==== */
:root {
  /* Chrome（ダーク） */
  --chrome-bg: #1e293b;
  --chrome-surface-2: #0f172a;
  --chrome-border: #334155;
  --chrome-hover: #334155;
  --chrome-text: #e2e8f0;
  --chrome-text-muted: #cbd5e1;
  --topbar-bg: rgba(30, 41, 59, 0.92);
  --topbar-text: #e2e8f0;
  --topbar-text-sub: #cbd5e1;
  --logo-grad: linear-gradient(135deg, #60a5fa, #a78bfa);

  /* Content（ライト） */
  --content-bg: #f8fafc;
  --content-surface: #ffffff;
  --content-surface-2: #f1f5f9;
  --content-surface-3: #e2e8f0;
  --content-border: #e2e8f0;
  --content-border-strong: #cbd5e1;
  --content-text: #0f172a;
  --content-text-muted: #475569;
  --content-text-soft: #64748b;

  /* アクセント */
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft-bg: #dbeafe;
  --accent-soft-text: #1e40af;
}

/* ==== Base ==== */
html, body {
  background: var(--content-bg);
  color: var(--content-text);
  color-scheme: light;
  margin: 0;
  font-family: 'Hiragino Kaku Gothic ProN', 'Noto Sans JP',
               -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  background: var(--content-bg);
}

/* ==== Chrome: Sidebar（ダーク） ==== */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--chrome-bg);
  border-right: 1px solid var(--chrome-border);
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  color: var(--chrome-text);
  z-index: 30;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--chrome-border);
  cursor: pointer; transition: opacity 0.15s;
}
.sidebar-brand:hover { opacity: 0.8; }
.sidebar-brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--logo-grad);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.sidebar-brand h1 {
  font-size: 15px; font-weight: 700;
  color: var(--chrome-text);
  line-height: 1.1; margin: 0;
}
.sidebar-brand p {
  font-size: 10.5px; color: var(--chrome-text-muted);
  margin: 2px 0 0;
}
.sidebar-nav {
  padding: 10px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-nav .nav-group-title {
  font-size: 10.5px; color: var(--chrome-text-muted);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 12px 10px 6px; font-weight: 600;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--chrome-text-muted);
  font-size: 13px; font-weight: 500;
  background: transparent; border: none; cursor: pointer;
  text-align: left; width: 100%;
  transition: background .12s, color .12s;
  text-decoration: none;
}
.nav-btn:hover { background: var(--chrome-hover); color: var(--chrome-text); }
.nav-btn.active { background: var(--accent); color: #fff; }
.nav-btn.active:hover { background: var(--accent-hover); color: #fff; }
.nav-btn.danger { color: #fca5a5; }
.nav-btn.danger:hover { background: rgba(239, 68, 68, 0.18); color: #fecaca; }
.nav-btn.active.danger { background: #991b1b; color: #fff; }
.nav-btn.active.danger:hover { background: #991b1b; color: #fff; }
.nav-btn .nav-ico {
  width: 18px; font-size: 14px;
  display: inline-flex; justify-content: center;
}
.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--chrome-border);
  font-size: 11px;
  color: var(--chrome-text-muted);
}

/* ==== Chrome: Main & TopBar ==== */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--content-bg);
}
.top-bar {
  position: sticky; top: 0; z-index: 40;
  background: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--chrome-border);
  padding: 10px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  color: var(--topbar-text);
}
.top-bar .page-title {
  font-size: 15px; font-weight: 700; color: var(--topbar-text);
}
.top-bar .page-sub {
  font-size: 11.5px; color: var(--topbar-text-sub); margin-top: 2px;
}

/* ==== Content エリア ==== */
.page-wrap {
  padding: 20px 24px 40px;
  max-width: 1400px;
  color: var(--content-text);
  background: var(--content-bg);
}

/* ==== 共通コンポーネント（ここが唯一のソース） ==== */

/* Card */
.card {
  background: var(--content-surface);
  border: 1px solid var(--content-border);
  border-radius: 12px;
  padding: 16px 20px;
}

/* Section title */
.section-title {
  font-size: 15px; font-weight: 700;
  color: var(--content-text);
  line-height: 1.4;
  margin: 0 0 12px;
}

/* KPI tile */
.kpi-tile {
  background: var(--content-surface);
  border: 1px solid var(--content-border);
  border-radius: 12px;
  padding: 16px 20px;
}
.kpi-tile .kpi-label {
  font-size: 12px;
  color: var(--content-text-muted);
  font-weight: 500;
}
.kpi-tile .kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--content-text);
  line-height: 1.0;
  margin-top: 4px;
}
.kpi-tile .kpi-unit {
  font-size: 12px;
  color: var(--content-text-muted);
  margin-left: 2px;
}

/* Info row (label/value) */
.info-row {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--content-border);
  font-size: 13px;
}
.info-row:last-child { border-bottom: none; }
.info-row .info-label {
  flex-shrink: 0;
  width: 140px;
  color: var(--content-text-muted);
  font-weight: 500;
}
.info-row .info-value {
  flex: 1;
  color: var(--content-text);
}

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--content-surface);
  color: var(--content-text);
  border: 1px solid var(--content-border-strong);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s;
}
.btn-secondary:hover { background: var(--content-surface-2); }

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent-soft-bg);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--accent-soft-bg); }

.btn-danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #ef4444;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger:hover { background: #fecaca; }

/* Badge（semantic） */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600;
  line-height: 1.4;
}
.badge-success { background: #d1fae5; color: #065f46; border: 1px solid #10b981; }
.badge-warning { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }
.badge-error   { background: #fee2e2; color: #991b1b; border: 1px solid #ef4444; }
.badge-info    { background: #dbeafe; color: #1e40af; border: 1px solid #3b82f6; }
.badge-neutral { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

/* Table */
.content-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.content-table thead th {
  background: var(--content-surface-2);
  color: var(--content-text-muted);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--content-border);
}
.content-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--content-border);
  color: var(--content-text);
}
.content-table tbody tr:hover { background: var(--content-surface-2); }

/* Input */
.form-input, .form-select, .form-textarea {
  background: var(--content-surface);
  color: var(--content-text);
  border: 1px solid var(--content-border-strong);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color .12s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* ==== 防御的オーバーライド（ライト前提を守る） ==== */
/* Tailwind の bg-slate-900 / bg-stone-900 など濃色を Content エリアで使わせない */
.page-wrap .bg-slate-900,
.page-wrap .bg-slate-800,
.page-wrap .bg-stone-900,
.page-wrap .bg-stone-800,
.page-wrap .bg-gray-900,
.page-wrap .bg-gray-800 {
  background-color: var(--content-surface) !important;
  color: var(--content-text) !important;
}

/* Content エリア内の白寄り文字を濃紺に引き戻す */
.page-wrap .text-white,
.page-wrap .text-slate-50,
.page-wrap .text-slate-100,
.page-wrap .text-slate-200,
.page-wrap .text-stone-50,
.page-wrap .text-stone-100,
.page-wrap .text-stone-200 {
  color: var(--content-text) !important;
}
/* ダーク地・濃色地のボタン/バッジ内の白文字は保持する */
.page-wrap .btn-primary.text-white,
.page-wrap .btn-primary .text-white,
.page-wrap .badge .text-white,
.page-wrap [style*="background:#2563eb"] .text-white,
.page-wrap [style*="background: #2563eb"] .text-white,
/* Tailwind colored buttons keep their white text */
.page-wrap [class*="bg-blue-5"].text-white,
.page-wrap [class*="bg-blue-6"].text-white,
.page-wrap [class*="bg-blue-7"].text-white,
.page-wrap [class*="bg-blue-8"].text-white,
.page-wrap [class*="bg-blue-9"].text-white,
.page-wrap [class*="bg-red-5"].text-white,
.page-wrap [class*="bg-red-6"].text-white,
.page-wrap [class*="bg-red-7"].text-white,
.page-wrap [class*="bg-red-8"].text-white,
.page-wrap [class*="bg-red-9"].text-white,
.page-wrap [class*="bg-green-5"].text-white,
.page-wrap [class*="bg-green-6"].text-white,
.page-wrap [class*="bg-green-7"].text-white,
.page-wrap [class*="bg-green-8"].text-white,
.page-wrap [class*="bg-emerald-5"].text-white,
.page-wrap [class*="bg-emerald-6"].text-white,
.page-wrap [class*="bg-emerald-7"].text-white,
.page-wrap [class*="bg-amber-5"].text-white,
.page-wrap [class*="bg-amber-6"].text-white,
.page-wrap [class*="bg-amber-7"].text-white,
.page-wrap [class*="bg-amber-8"].text-white,
.page-wrap [class*="bg-orange-5"].text-white,
.page-wrap [class*="bg-orange-6"].text-white,
.page-wrap [class*="bg-violet-5"].text-white,
.page-wrap [class*="bg-violet-6"].text-white,
.page-wrap [class*="bg-purple-5"].text-white,
.page-wrap [class*="bg-purple-6"].text-white,
.page-wrap [class*="bg-indigo-5"].text-white,
.page-wrap [class*="bg-indigo-6"].text-white,
.page-wrap [class*="bg-rose-5"].text-white,
.page-wrap [class*="bg-rose-6"].text-white,
.page-wrap [class*="bg-pink-5"].text-white,
.page-wrap [class*="bg-pink-6"].text-white,
.page-wrap [class*="bg-cyan-5"].text-white,
.page-wrap [class*="bg-cyan-6"].text-white,
.page-wrap [class*="bg-teal-5"].text-white,
.page-wrap [class*="bg-teal-6"].text-white,
.page-wrap [class*="bg-slate-5"].text-white,
.page-wrap [class*="bg-slate-6"].text-white,
.page-wrap [class*="bg-slate-7"].text-white,
.page-wrap [class*="bg-slate-8"].text-white,
.page-wrap [class*="bg-slate-9"].text-white,
.page-wrap [class*="bg-gray-5"].text-white,
.page-wrap [class*="bg-gray-6"].text-white,
.page-wrap [class*="bg-gray-7"].text-white,
.page-wrap [class*="bg-gray-8"].text-white,
.page-wrap [class*="bg-gray-9"].text-white,
.page-wrap [class*="bg-stone-5"].text-white,
.page-wrap [class*="bg-stone-6"].text-white,
.page-wrap [class*="bg-stone-7"].text-white,
.page-wrap [class*="bg-stone-8"].text-white,
.page-wrap [class*="bg-stone-9"].text-white,
.page-wrap [class*="bg-zinc-5"].text-white,
.page-wrap [class*="bg-zinc-6"].text-white,
.page-wrap [class*="bg-zinc-7"].text-white,
.page-wrap [class*="bg-zinc-8"].text-white,
.page-wrap [class*="bg-zinc-9"].text-white,
.page-wrap [class*="bg-neutral-5"].text-white,
.page-wrap [class*="bg-neutral-6"].text-white,
.page-wrap [class*="bg-neutral-7"].text-white,
.page-wrap [class*="bg-neutral-8"].text-white,
.page-wrap [class*="bg-neutral-9"].text-white {
  color: #fff !important;
}

/* ==== 防御的オーバーライド: 薄い文字色 → コントラスト十分に ====
   Content エリア（ライト）で text-*-200/300/400 の薄い Tailwind 色は
   そのままだと 4.5:1 を切るので、700 相当に引き下げる。
   ただし .auto-draft-banner や bg-slate-900 等のダーク地に載っている
   ものはそのままで読めるので除外（is-dark-context クラスで明示的にopt-out）*/
.page-wrap .text-red-200:not(.keep-light),
.page-wrap .text-red-300:not(.keep-light),
.page-wrap .text-red-400:not(.keep-light) { color: #b91c1c !important; }
.page-wrap .text-blue-200:not(.keep-light),
.page-wrap .text-blue-300:not(.keep-light),
.page-wrap .text-blue-400:not(.keep-light) { color: #1d4ed8 !important; }
.page-wrap .text-green-200:not(.keep-light),
.page-wrap .text-green-300:not(.keep-light),
.page-wrap .text-green-400:not(.keep-light) { color: #15803d !important; }
.page-wrap .text-emerald-200:not(.keep-light),
.page-wrap .text-emerald-300:not(.keep-light),
.page-wrap .text-emerald-400:not(.keep-light) { color: #047857 !important; }
.page-wrap .text-amber-200:not(.keep-light),
.page-wrap .text-amber-300:not(.keep-light),
.page-wrap .text-amber-400:not(.keep-light) { color: #b45309 !important; }
.page-wrap .text-yellow-200:not(.keep-light),
.page-wrap .text-yellow-300:not(.keep-light),
.page-wrap .text-yellow-400:not(.keep-light) { color: #a16207 !important; }
.page-wrap .text-violet-200:not(.keep-light),
.page-wrap .text-violet-300:not(.keep-light),
.page-wrap .text-violet-400:not(.keep-light) { color: #6d28d9 !important; }
.page-wrap .text-purple-200:not(.keep-light),
.page-wrap .text-purple-300:not(.keep-light),
.page-wrap .text-purple-400:not(.keep-light) { color: #7e22ce !important; }
.page-wrap .text-indigo-200:not(.keep-light),
.page-wrap .text-indigo-300:not(.keep-light),
.page-wrap .text-indigo-400:not(.keep-light) { color: #4338ca !important; }
.page-wrap .text-rose-200:not(.keep-light),
.page-wrap .text-rose-300:not(.keep-light),
.page-wrap .text-rose-400:not(.keep-light) { color: #be123c !important; }
.page-wrap .text-pink-200:not(.keep-light),
.page-wrap .text-pink-300:not(.keep-light),
.page-wrap .text-pink-400:not(.keep-light) { color: #be185d !important; }
.page-wrap .text-cyan-200:not(.keep-light),
.page-wrap .text-cyan-300:not(.keep-light),
.page-wrap .text-cyan-400:not(.keep-light) { color: #0e7490 !important; }
.page-wrap .text-teal-200:not(.keep-light),
.page-wrap .text-teal-300:not(.keep-light),
.page-wrap .text-teal-400:not(.keep-light) { color: #0f766e !important; }
.page-wrap .text-orange-200:not(.keep-light),
.page-wrap .text-orange-300:not(.keep-light),
.page-wrap .text-orange-400:not(.keep-light) { color: #c2410c !important; }
.page-wrap .text-slate-300:not(.keep-light),
.page-wrap .text-slate-400:not(.keep-light),
.page-wrap .text-gray-300:not(.keep-light),
.page-wrap .text-gray-400:not(.keep-light),
.page-wrap .text-stone-300:not(.keep-light),
.page-wrap .text-stone-400:not(.keep-light) { color: #475569 !important; }

/* ダーク地パネル（バナー・プレビュー等）に載る薄色文字は守る */
.page-wrap .auto-draft-banner [class*="text-"] { color: revert !important; }
.page-wrap .auto-draft-banner .text-blue-200,
.page-wrap .auto-draft-banner .text-blue-300,
.page-wrap .auto-draft-banner .text-blue-400 { color: #93c5fd !important; }
.page-wrap .auto-draft-banner .text-white { color: #fff !important; }

/* Tailwind の色付き bg（-500〜-900）の内側は白寄り文字を保持する */
.page-wrap [class*="bg-red-5"] [class*="text-red-"],
.page-wrap [class*="bg-red-6"] [class*="text-red-"],
.page-wrap [class*="bg-red-7"] [class*="text-red-"],
.page-wrap [class*="bg-red-8"] [class*="text-red-"],
.page-wrap [class*="bg-red-9"] [class*="text-red-"],
.page-wrap [class*="bg-blue-7"] [class*="text-blue-"],
.page-wrap [class*="bg-blue-8"] [class*="text-blue-"],
.page-wrap [class*="bg-blue-9"] [class*="text-blue-"],
.page-wrap [class*="bg-amber-7"] [class*="text-amber-"],
.page-wrap [class*="bg-amber-8"] [class*="text-amber-"],
.page-wrap [class*="bg-amber-9"] [class*="text-amber-"],
.page-wrap [class*="bg-green-7"] [class*="text-green-"],
.page-wrap [class*="bg-green-8"] [class*="text-green-"],
.page-wrap [class*="bg-green-9"] [class*="text-green-"],
.page-wrap [class*="bg-emerald-7"] [class*="text-emerald-"],
.page-wrap [class*="bg-emerald-8"] [class*="text-emerald-"],
.page-wrap [class*="bg-emerald-9"] [class*="text-emerald-"] { color: revert !important; }

/* ==== テーマスイッチャー（非表示化） ==== */
#themeSwitcher { display: none !important; }
