:root {
  color-scheme: light;
  --ink: #18202f;
  --muted: #667085;
  --line: #d7dde8;
  --surface: #f7f9fc;
  --accent: #0f766e;
  --accent-2: #b45309;
  --bg: #ffffff;
  --panel-bg: #ffffff;
  --input-bg: #ffffff;
  --table-head-bg: #f7f9fc;
  --error-color: #dc2626; /* IMP-83 */
  --error-ring: rgba(220,38,38,0.2); /* IMP-83 */
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
}
/* IMP-63: ダークモード */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #e2e8f0;
    --muted: #94a3b8;
    --line: #334155;
    --surface: #1e293b;
    --accent: #2dd4bf;
    --accent-2: #fbbf24;
    --bg: #0f172a;
    --panel-bg: #1e293b;
    --input-bg: #1e293b;
    --table-head-bg: #1e293b;
    --error-color: #f87171; /* IMP-83 */
    --error-ring: rgba(248,113,113,0.25); /* IMP-83 */
  }
}
[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --line: #334155;
  --surface: #1e293b;
  --accent: #2dd4bf;
  --accent-2: #fbbf24;
  --bg: #0f172a;
  --panel-bg: #1e293b;
  --input-bg: #1e293b;
  --table-head-bg: #1e293b;
  --error-color: #f87171; /* IMP-83 */
  --error-ring: rgba(248,113,113,0.25); /* IMP-83 */
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); }
.topbar {
  display: flex; align-items: end; justify-content: space-between; gap: 24px;
  padding: 24px 32px 18px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; }
h1 { margin: 0; font-size: 28px; line-height: 1.25; letter-spacing: 0; }
h2 { margin: 0 0 14px; font-size: 20px; letter-spacing: 0; }
h3 { margin: 0 0 8px; font-size: 15px; letter-spacing: 0; }
nav { display: flex; gap: 8px; flex-wrap: wrap; }
button {
  min-height: 36px; border: 1px solid var(--line); background: var(--panel-bg); color: var(--ink);
  border-radius: 6px; padding: 0 14px; font-weight: 700; cursor: pointer;
}
button.active, button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
main { padding: 28px 32px; }
.hidden { display: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.panel { border: 1px solid var(--line); border-radius: 8px; padding: 18px; background: var(--panel-bg); }
.metric { font-size: 32px; font-weight: 800; }
.muted { color: var(--muted); }
.list { display: grid; gap: 10px; }
.item { padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-bg); }
.item code { display: inline-block; margin-bottom: 4px; color: var(--accent-2); font-weight: 700; }
form { display: grid; gap: 10px; max-width: 760px; }
label { display: grid; gap: 4px; font-weight: 700; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px;
  font: inherit; background: var(--input-bg); color: var(--ink);
}
textarea { min-height: 108px; resize: vertical; }
table { width: 100%; border-collapse: collapse; background: var(--panel-bg); }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--table-head-bg); font-size: 13px; }
@media (max-width: 720px) {
  .topbar { align-items: stretch; flex-direction: column; padding: 18px; }
  main { padding: 18px; }
  h1 { font-size: 22px; }
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  align-items: end;
  gap: 10px;
  max-width: 720px;
  margin: 12px 0 16px;
}
.inline-form input { min-height: 36px; }
td button { min-height: 30px; padding: 0 10px; }


/* ── ドメインエンティティ バッジ ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 700; }
.badge-active, .badge-accepted, .badge-enrolled, .badge-certified, .badge-approved, .badge-registered, .badge-valid { background: #dcfce7; color: #166534; }
.badge-closed, .badge-withdrawn, .badge-completed, .badge-expired { background: #f3f4f6; color: #374151; }
.badge-pending, .badge-submitted, .badge-applied, .badge-received, .badge-investigating { background: #fef9c3; color: #854d0e; }
.badge-rejected, .badge-cancelled, .badge-suspended { background: #fee2e2; color: #991b1b; }
.badge-birth, .badge-new, .badge-new_certification { background: #dbeafe; color: #1e40af; }
.badge-marriage, .badge-renewal { background: #f3e8ff; color: #6b21a8; }
.badge-death { background: #fee2e2; color: #991b1b; }
.badge-divorce, .badge-address_change, .badge-name_change, .badge-transfer { background: #fff7ed; color: #c2410c; }
.badge-adoption { background: #ecfdf5; color: #065f46; }
.badge-levied, .badge-paid, .badge-billed { background: #e0f2fe; color: #075985; }
.badge-specific_health, .badge-cancer_screening { background: #fce7f3; color: #9d174d; }
.badge-physical, .badge-intellectual, .badge-mental, .badge-developmental { background: #f0f9ff; color: #0c4a6e; }
details summary { user-select: none; }
details[open] summary { margin-bottom: 8px; }

/* IMP-59: オフラインバナー */
#offline-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: #fef08a;
  color: #713f12;
  text-align: center;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 14px;
  border-bottom: 2px solid #ca8a04;
}
#offline-banner.visible { display: block; }
body.offline-mode { padding-top: 40px; }

/* IMP-69: 確認ダイアログ */
#confirm-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: rgba(0,0,0,0.4);
  align-items: center;
  justify-content: center;
}
#confirm-modal.visible { display: flex; }
.modal-dialog {
  background: var(--panel-bg, #fff);
  border-radius: 10px;
  padding: 24px 28px;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.modal-msg { margin: 0 0 20px; font-size: 1rem; font-weight: 600; color: var(--ink, #18202f); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* IMP-70: ローディングスピナー */
#loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0,0,0,0.15);
  align-items: center;
  justify-content: center;
}
#loading-overlay.visible { display: flex; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid rgba(255,255,255,0.4);
  border-top-color: #0f766e;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* IMP-83: フィールドエラークラス */
input.field-error, select.field-error, textarea.field-error {
  border-color: var(--error-color) !important;
  box-shadow: 0 0 0 2px var(--error-ring) !important;
}
/* IMP-66: トーストUI */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  min-width: 200px;
  max-width: 360px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  pointer-events: auto;
  animation: toast-in 0.25s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  word-break: break-word;
}
.toast-success { background: #dcfce7; color: #166534; border-left: 4px solid #16a34a; }
.toast-error { background: #fee2e2; color: #991b1b; border-left: 4px solid #dc2626; }
.toast-info { background: #dbeafe; color: #1e40af; border-left: 4px solid #2563eb; }
.toast-fade { animation: toast-out 0.3s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(30px); } }

/* IMP-60: 印刷スタイルシート */
@media print {
  #offline-banner, nav, .topbar button, .inline-form button, td button,
  details, .print-hide { display: none !important; }
  .topbar { border-bottom: 1px solid #999; background: none; padding: 8px; }
  h1 { font-size: 20px; }
  main { padding: 8px; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
  .hidden { display: block !important; }
  section.hidden { display: none !important; }
}


/* ════════ RESP-v1: レスポンシブ強化（スマホ/タブレット自動対応） ════════ */
html { -webkit-text-size-adjust: 100%; }
/* iOS等で入力時の自動ズームを防ぐ（フォント16px以上） */
input, select, textarea { font-size: 16px; }

/* タブレット幅 (<=900px) */
@media (max-width: 900px) {
  .topbar { padding: 20px 20px 14px; }
  main { padding: 22px 20px; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
}

/* スマホ幅 (<=640px) */
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 12px; padding: 16px; }
  nav { gap: 6px; }
  nav button { flex: 1 1 auto; min-height: 44px; }   /* タッチ操作向けに拡大 */
  main { padding: 16px 14px; }
  h1 { font-size: 20px; }
  h2 { font-size: 18px; }
  .grid { grid-template-columns: 1fr; }
  .metric { font-size: 28px; }
  form { max-width: none; }
  .inline-form { grid-template-columns: 1fr; max-width: none; }
  .inline-form button { width: 100%; }
  /* 横長テーブルは枠内で横スクロール（ページ全体のはみ出しを防ぐ） */
  table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  button { min-height: 44px; }
  td button { min-height: 36px; }
  /* トーストを画面幅に合わせる */
  #toast-container { left: 0; right: 0; padding: 0 14px; align-items: stretch; }
  .toast { max-width: none; }
}

/* 折りたたみデバイス・極小幅 (<=380px) */
@media (max-width: 380px) {
  h1 { font-size: 18px; }
  .eyebrow { font-size: 11px; }
}
/* ════════ /RESP-v1 ════════ */


/* ════════ RESP-v2: 追従ヘッダー・広い画面の可読性・タッチ/アクセシビリティ改善 ════════ */
html { scroll-behavior: smooth; }
/* 長い一覧でもナビ/タイトルに常時アクセスできるよう、ヘッダーを画面上部に追従 */
.topbar { position: sticky; top: 0; z-index: 50; }
/* ノッチ等のセーフエリアにタイトルがかぶらないように */
@supports (padding: max(0px)) {
  .topbar { padding-top: max(18px, env(safe-area-inset-top)); }
}
/* 超ワイド画面では本文幅を抑えて可読性を確保（中央寄せ） */
@media (min-width: 1400px) {
  main { max-width: 1320px; margin-left: auto; margin-right: auto; }
}
/* 長い文字列でセル・パネルが横にはみ出さないように折り返す */
td, .item, .panel { overflow-wrap: anywhere; }
/* キーボード操作時のフォーカスを明示（アクセシビリティ） */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
/* スマホでは入力欄も押しやすい高さに */
@media (max-width: 640px) {
  input, select, textarea { min-height: 44px; }
}
/* ════════ /RESP-v2 ════════ */


/* ════════ RESP-v3: タッチ操作・高コントラスト・省スペースの仕上げ ════════ */
/* タップ反応を速く・明確に（ダブルタップズーム遅延の回避＋押下フィードバック） */
button, a, .item, summary { -webkit-tap-highlight-color: rgba(15,118,110,.18); }
button { touch-action: manipulation; }
button:active { transform: translateY(1px); }
/* OSの高コントラスト設定時、境界線とフォーカスを強調（アクセシビリティ） */
@media (prefers-contrast: more) {
  button, input, select, textarea, .panel, .item, .card, th, td { border-color: CanvasText; }
  :focus-visible { outline-width: 4px; }
}
/* 横向きなど高さの低い画面では上下余白を圧縮して情報量を確保 */
@media (max-height: 520px) {
  .topbar { padding-top: 10px; padding-bottom: 10px; }
  main { padding-top: 12px; padding-bottom: 12px; }
}
/* ════════ /RESP-v3 ════════ */


/* ════════ RESP-v4: スキップリンク(a11y)・スクロール安定・フルハイト ════════ */
/* キーボード/スクリーンリーダー利用者向けの「本文へスキップ」リンク */
.skip-link { position: absolute; left: 8px; top: -48px; z-index: 100; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 0 0 8px 8px; font-weight: 700; transition: top .15s; }
.skip-link:focus { top: 0; }
/* スクロールバー出現時のレイアウトずれ防止 */
html { scrollbar-gutter: stable; }
/* 追従ヘッダー分のアンカー余白 */
:target { scroll-margin-top: 72px; }
/* ════════ /RESP-v4 ════════ */


/* ════════ STAFF-LOGIN: 職員用ログイン画面 ════════ */
.staff-login { position: fixed; inset: 0; z-index: 10050; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(135deg, #0f3a4d, #124559 55%, #0b2a38); }
.staff-login__card { width: 100%; max-width: 400px; background: var(--panel-bg, #fff); color: var(--ink, #18202f);
  border-radius: 14px; box-shadow: 0 18px 50px rgba(0,0,0,.4); padding: 28px 26px; }
.staff-login__eyebrow { margin: 0 0 6px; color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.staff-login__sys { margin: 0 0 2px; font-size: 20px; line-height: 1.3; }
.staff-login__title { margin: 0 0 18px; font-size: 14px; color: var(--muted); font-weight: 700; }
.staff-login form { display: grid; gap: 12px; }
.staff-login label { display: grid; gap: 4px; font-weight: 700; font-size: 14px; }
.staff-login input, .staff-login select { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--input-bg, #fff); color: var(--ink); font: inherit; }
.staff-login input:focus, .staff-login select:focus { outline: 3px solid var(--error-ring, rgba(15,118,110,.25)); border-color: var(--accent); }
.staff-login__err { margin: 0; color: var(--error-color, #dc2626); font-weight: 600; font-size: 13px; }
.staff-login button.primary { min-height: 46px; margin-top: 4px; }
.staff-login__demo { margin: 14px 0 0; font-size: 12px; color: var(--muted); }
/* ════════ /STAFF-LOGIN ════════ */


/* ════════ CALC-UI: クイック算定パネル ════════ */
.calc-form { display: grid; gap: 12px; max-width: 560px; margin: 8px 0 4px; }
.calc-form label { display: grid; gap: 4px; font-weight: 700; font-size: 14px; }
.calc-form input, .calc-form select, .calc-form textarea { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--input-bg, #fff); color: var(--ink); font: inherit; }
.calc-form button.primary { justify-self: start; min-height: 42px; padding: 0 22px; }
.calc-result { margin-top: 16px; }
.calc-primary { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 18px 20px; border-radius: 12px; background: linear-gradient(135deg, var(--accent), var(--accent-2, var(--accent))); color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.calc-primary.ng { background: linear-gradient(135deg, #b23a48, #7a2531); }
.calc-primary__label { font-size: 14px; font-weight: 700; opacity: .95; }
.calc-primary__value { font-size: 28px; font-weight: 800; line-height: 1.1; }
.calc-detail { width: 100%; margin-top: 12px; border-collapse: collapse; max-width: 560px; }
.calc-detail th, .calc-detail td { border-bottom: 1px solid var(--line); padding: 6px 10px; text-align: left; font-size: 13px; }
.calc-detail th { color: var(--muted); font-weight: 600; width: 45%; }
/* ════════ /CALC-UI ════════ */

.calc-result .calc-apply { margin-top: 14px; width: 100%; }

/* ダッシュボード可視化（状態別構成の横棒＋直近推移の縦棒）外部ライブラリ非依存 */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-panel h2 { font-size: 0.95rem; margin: 0 0 10px; }
.chart-bars { display: flex; flex-direction: column; gap: 8px; }
.chart-row { display: grid; grid-template-columns: 88px 1fr 40px; align-items: center; gap: 8px; }
.chart-label { font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-track { background: rgba(127,127,127,0.16); border-radius: 6px; height: 16px; overflow: hidden; }
.chart-fill { display: block; height: 100%; background: linear-gradient(90deg, #60a5fa, #2563eb); border-radius: 6px; min-width: 2px; }
.chart-value { font-size: 0.8rem; font-weight: 600; text-align: right; }
.chart-trend { display: flex; align-items: flex-end; gap: 4px; height: 120px; }
.chart-col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.chart-col-bar { width: 100%; height: 92px; position: relative; }
.chart-col-fill { position: absolute; left: 0; bottom: 0; width: 100%; background: linear-gradient(180deg, #60a5fa, #2563eb); border-radius: 3px 3px 0 0; min-height: 2px; }
.chart-col-label { font-size: 0.6rem; color: #6b7280; white-space: nowrap; }
@media (max-width: 720px) { .chart-grid { grid-template-columns: 1fr; } }

/* ── 中間サーバ照会パネル（算定画面） ── */
.linkage-box { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0 0 16px; background: var(--surface); }
.linkage-box h3 { margin: 0 0 4px; font-size: 1rem; }
.linkage-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.linkage-row label { display: flex; flex-direction: column; gap: 4px; }
.linkage-results { margin-top: 8px; display: grid; gap: 2px; }

/* SPEC-v1: 仕様機能タブ（APIカタログ＋実行コンソール） */
.spec-console { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.spec-console .spec-path { flex: 1; min-width: 240px; }
.spec-body { width: 100%; font-family: ui-monospace, monospace; }
.spec-out { background: rgba(0,0,0,.25); border: 1px solid rgba(128,128,128,.3); border-radius: 8px; padding: 10px; max-height: 320px; overflow: auto; white-space: pre-wrap; font-size: 12px; }
.spec-table { width: 100%; }
.spec-table td code { font-size: 12px; }
.spec-row { cursor: pointer; }
.spec-row:hover { background: rgba(128,160,255,.12); }
details.panel > summary { cursor: pointer; font-weight: 600; }
