/* ===== テーマ（役割ごとの色。ライト／ダークで値だけ切り替える） ===== */
:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --surface-1: #ffffff;
  --surface-2: #f8fafc;
  --line: #e4e8ef;
  --text-primary: #191919;
  --text-secondary: #5f6673;
  --text-muted: #8a909b;
  --brand: #0050a0;
  --brand-soft: #e8f0fa;
  --nav-bg: #0b1f3a;
  --nav-text: #b9c6d8;
  /* 単一色相の順序ランプ（ファネル・内訳・推移） */
  --seq-1: #84b9f3; --seq-2: #257de0; --seq-3: #0f4a96;
  /* ステータス（必ずアイコン＋ラベルと併用） */
  --good: #0aac23; --warning: #fbb315; --warning-ink: #a86f00; --critical: #dc3c3d;
  --critical-soft: #fdeceb; --good-soft: #e9f8ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 0.2143rem rgba(16, 24, 40, .08);
  --radius: 1rem;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111316;
  --surface-1: #191919;
  --surface-2: #202226;
  --line: #2c2f35;
  --text-primary: #efefef;
  --text-secondary: #a7adb7;
  --text-muted: #7d838d;
  --brand: #338ced;
  --brand-soft: #1b2a3d;
  --nav-bg: #0a0c10;
  --seq-1: #1757ac; --seq-2: #338ced; --seq-3: #84b9f3;
  --warning-ink: #fbb315;
  --critical-soft: #3a1d1d; --good-soft: #15291a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

/* ===== 骨組み ===== */
* { box-sizing: border-box; }
body {
  margin: 0; display: grid; grid-template-columns: 16.5714rem 1fr; min-height: 100vh;
  font-family: "Segoe UI", "Meiryo UI", "Yu Gothic UI", "Hiragino Sans", sans-serif;
  background: var(--bg); color: var(--text-primary); font-size: 1rem;
  font-feature-settings: "palt";
}
.num { font-variant-numeric: tabular-nums; font-family: "Segoe UI", system-ui, sans-serif; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 0.4286rem; }
a { color: var(--brand); }

/* サイドバー */
aside { background: var(--nav-bg); color: var(--nav-text); padding: 1.4286rem 1rem; display: flex; flex-direction: column; gap: 1.2857rem; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 0.7143rem; color: #fff; font-weight: 700; font-size: 1.0714rem; padding: 0 0.5714rem; }
.logo-mark { width: 2.1429rem; height: 2.1429rem; border-radius: 0.6429rem; background: linear-gradient(135deg, #338ced, #0050a0); display: grid; place-items: center; font-size: 0.9286rem; }
.logo small { display: block; font-weight: 400; font-size: 0.7857rem; color: var(--nav-text); }
aside nav { display: flex; flex-direction: column; gap: 2px; }
aside nav a { display: flex; align-items: center; gap: 0.7143rem; padding: 0.6429rem 0.7143rem; border-radius: 0.5714rem; color: var(--nav-text); text-decoration: none; }
aside nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
aside nav a.active { background: rgba(51,140,237,.18); color: #fff; }
aside nav a .badge { margin-left: auto; background: var(--critical); color: #fff; border-radius: 0.7143rem; padding: 0 0.5rem; font-size: 0.7857rem; }
aside nav svg { width: 1.2857rem; height: 1.2857rem; flex: none; }
.plan { margin-top: auto; padding: 0.8571rem; border-radius: 0.7143rem; background: rgba(255,255,255,.05); font-size: 0.8571rem; line-height: 1.6; }
.plan b, .plan span#source { color: #fff; }
.dot-live { display: inline-block; width: 0.5714rem; height: 0.5714rem; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(10,172,35,.6); animation: pulse 2s infinite; margin-right: 0.4286rem; }
@keyframes pulse { 70% { box-shadow: 0 0 0 0.5rem rgba(10,172,35,0); } 100% { box-shadow: 0 0 0 0 rgba(10,172,35,0); } }
@media (prefers-reduced-motion: reduce) { .dot-live { animation: none; } }

/* 上部バー */
main { padding: 1.2857rem 2rem 2.8571rem; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 1.1429rem; margin-bottom: 1.2857rem; }
.crumb { color: var(--text-secondary); white-space: nowrap; }
.crumb b { color: var(--text-primary); font-size: 1.2857rem; margin-right: 0.5714rem; }
.ask { flex: 1; max-width: 40rem; margin: 0 0 0 auto; position: relative; }
.ask input { width: 100%; padding: 0.7143rem 5rem 0.7143rem 2.7143rem; border: 1px solid var(--line); border-radius: 0.7143rem; background: var(--surface-1); color: var(--text-primary); font-size: 1rem; box-shadow: var(--shadow); }
.ask svg { position: absolute; left: 0.8571rem; top: 50%; transform: translateY(-50%); width: 1.1429rem; height: 1.1429rem; color: var(--brand); }
.ask kbd { position: absolute; right: 0.7143rem; top: 50%; transform: translateY(-50%); font-size: 0.7857rem; color: var(--text-muted); border: 1px solid var(--line); border-radius: 0.3571rem; padding: 1px 0.4286rem; }
.meta { color: var(--text-secondary); font-size: 0.8571rem; white-space: nowrap; }
.iconbtn { border: 1px solid var(--line); background: var(--surface-1); color: var(--text-primary); border-radius: 0.7143rem; width: 2.7143rem; height: 2.7143rem; cursor: pointer; display: grid; place-items: center; }
.banner { padding: 0.7143rem 1.1429rem; margin-bottom: 1.1429rem; border-radius: 0.7143rem; background: #fff4e5; color: #8a4b00; border: 1px solid #f5c07a; }
footer { margin-top: 1.7143rem; color: var(--text-muted); font-size: 0.8571rem; text-align: center; }

/* ===== 共通部品 ===== */
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 1.1429rem; }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.2857rem 1.4286rem; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card h2 { font-size: 1rem; margin: 0 0 0.2857rem; display: flex; align-items: center; gap: 0.5714rem; }
.card .sub { color: var(--text-secondary); font-size: 0.8571rem; margin: 0 0 1rem; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; }
.status { display: inline-flex; align-items: center; gap: 0.4286rem; font-weight: 700; font-size: 0.8571rem; padding: 0.2143rem 0.7143rem; border-radius: 1.4286rem; background: var(--surface-1); border: 1px solid var(--line); white-space: nowrap; }
.status svg { width: 1rem; height: 1rem; }
.ai-chip { flex: none; font-size: 0.7857rem; font-weight: 700; color: var(--brand); background: var(--brand-soft); border-radius: 0.4286rem; padding: 2px 0.5rem; }
.btn { display: inline-block; text-align: center; text-decoration: none; border: 0; border-radius: 0.7143rem; padding: 0.7857rem 1.2857rem; font-weight: 700; cursor: pointer; font-size: 1rem; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.toggle-table, .more { margin-left: auto; font-size: 0.8571rem; font-weight: 400; background: none; border: 0; color: var(--brand); cursor: pointer; text-decoration: none; }
.empty { color: var(--text-muted); font-size: 0.9286rem; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.8571rem; }
table.data th, table.data td { padding: 0.3571rem 0.5714rem; border-bottom: 1px solid var(--line); text-align: right; }
table.data th:first-child, table.data td:first-child { text-align: left; }

/* ===== ダッシュボード ===== */
.hero { grid-column: span 12; display: grid; grid-template-columns: 1fr auto; gap: 1.4286rem; align-items: center;
  border-left: 0.3571rem solid var(--critical); background: linear-gradient(90deg, var(--critical-soft), var(--surface-1) 55%); }
.hero.calm { border-left-color: var(--good); background: linear-gradient(90deg, var(--good-soft), var(--surface-1) 55%); }
.hero h1 { font-size: 1.4286rem; margin: 0.5714rem 0 0.4286rem; }
.hero .ai { display: flex; gap: 0.7143rem; align-items: flex-start; color: var(--text-secondary); line-height: 1.6; max-width: 64.2857rem; }
.hero .ai .ai-chip { margin-top: 2px; }
.hero .facts { display: flex; flex-wrap: wrap; gap: 0.4286rem 1.2857rem; margin-top: 0.7143rem; font-size: 0.8571rem; color: var(--text-secondary); }
.hero .facts b { color: var(--text-primary); }
.hero .actions { display: flex; flex-direction: column; gap: 0.5714rem; }

.kpi .label { color: var(--text-secondary); font-size: 0.8571rem; }
.kpi .value { font-size: 2.1429rem; font-weight: 700; letter-spacing: -.5px; margin: 0.2857rem 0 2px; }
.kpi .value small { font-size: 0.9286rem; font-weight: 400; color: var(--text-secondary); margin-left: 0.2857rem; }
.kpi .delta { font-size: 0.8571rem; color: var(--text-secondary); }
.kpi svg.spark { width: 100%; height: 2.5714rem; margin-top: 0.5714rem; display: block; }
.ratio { margin-top: 1rem; height: 0.7143rem; border-radius: 0.3571rem; background: var(--seq-1); display: flex; overflow: hidden; }
.ratio div { background: var(--seq-3); border-right: 2px solid var(--surface-1); }
.ratio + .delta { margin-top: 0.4286rem; }

.funnel-row { display: grid; grid-template-columns: 12.1429rem 1fr 6.4286rem; align-items: center; gap: 0.8571rem; margin: 0.7143rem 0; }
.funnel-row .name { color: var(--text-secondary); font-size: 0.9286rem; }
.funnel-row .bar { height: 1.8571rem; border-radius: 0 0.2857rem 0.2857rem 0; min-width: 0.2857rem; }
.funnel-row .v { text-align: right; font-weight: 700; font-size: 1.1429rem; }
.funnel-note { display: flex; flex-wrap: wrap; gap: 0.5714rem 1.5714rem; padding-top: 0.8571rem; border-top: 1px dashed var(--line); margin-top: 1rem; font-size: 0.8571rem; color: var(--text-secondary); }
.funnel-note b { font-size: 1.2857rem; color: var(--text-primary); margin-right: 0.2857rem; }

.hbar { display: grid; grid-template-columns: 10.7143rem 1fr 4rem; align-items: center; gap: 0.7143rem; margin: 0.6429rem 0; font-size: 0.9286rem; }
.hbar .fill { height: 0.7143rem; background: var(--seq-2); border-radius: 0 0.2857rem 0.2857rem 0; min-width: 2px; }
.hbar .v { text-align: right; color: var(--text-secondary); }

.chart { position: relative; }
.chart svg { width: 100%; height: auto; aspect-ratio: 760 / 250; display: block; overflow: visible; }
.chart .axis { fill: var(--text-muted); font-size: 0.7143rem; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart path.col { fill: var(--seq-2); }
.chart path.col.today { fill: var(--seq-3); }
.chart rect.hit { fill: transparent; cursor: crosshair; }
.chart g.d:hover path.col { opacity: .75; }
.tooltip { position: absolute; pointer-events: none; background: var(--text-primary); color: var(--surface-1); padding: 0.5rem 0.7143rem; border-radius: 0.5714rem; font-size: 0.8571rem; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .1s; }

.site { display: grid; grid-template-columns: 1fr auto auto; gap: 0.8571rem; align-items: center; padding: 0.7143rem 2px; border-bottom: 1px solid var(--line); }
.site:last-child { border-bottom: 0; }
.site .n { font-weight: 600; }
.site .d, .site .c { color: var(--text-secondary); font-size: 0.8571rem; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 3.8571rem 1.5714rem 1fr; gap: 0.5714rem; padding: 0.5714rem 0.4286rem; align-items: start; cursor: pointer; border-radius: 0.5714rem; }
.feed li:hover { background: var(--surface-2); }
.feed time { color: var(--text-muted); font-size: 0.8571rem; padding-top: 2px; }
.feed .who { width: 1.5714rem; height: 1.5714rem; border-radius: 50%; display: grid; place-items: center; font-size: 0.7143rem; font-weight: 700; color: #fff; }
.who.AI { background: var(--brand); } .who.MKI { background: #6a4ce2; } .who.C { background: #5f6673; }
.feed .txt { line-height: 1.5; }
.feed .txt small { display: block; color: var(--text-secondary); }

.sign { padding: 0.8571rem 0; border-bottom: 1px solid var(--line); }
.sign:last-child { border-bottom: 0; }
.sign .t { display: flex; justify-content: space-between; gap: 0.5714rem; font-weight: 600; }
.sign .m { color: var(--text-secondary); font-size: 0.8571rem; margin-top: 0.2143rem; }
.sim { font-size: 0.8571rem; color: var(--brand); font-weight: 700; white-space: nowrap; }
.sim-track { height: 0.2857rem; background: var(--surface-2); border-radius: 2px; margin-top: 0.5714rem; }
.sim-track div { height: 0.2857rem; background: var(--seq-2); border-radius: 2px; }

/* ===== 対応履歴 ===== */
table.incidents { width: 100%; border-collapse: collapse; }
table.incidents th { background: var(--surface-2); color: var(--text-secondary); text-align: left; padding: 0.7143rem 0.8571rem; font-size: 0.8571rem; font-weight: 600; border-bottom: 1px solid var(--line); }
table.incidents td { padding: 0.7143rem 0.8571rem; border-bottom: 1px solid var(--line); font-size: 0.9286rem; }
table.incidents tbody tr:last-child td { border-bottom: 0; }
table.incidents tr[data-id] { cursor: pointer; }
table.incidents tr[data-id]:hover { background: var(--surface-2); }
table.incidents tr.selected { background: var(--brand-soft); box-shadow: inset 0.2143rem 0 0 var(--brand); }
tr.noneed td { color: var(--text-muted); }
.tag { margin-left: 0.5714rem; padding: 1px 0.4286rem; border-radius: 0.2857rem; background: var(--brand-soft); color: var(--brand); font-size: 0.7857rem; }
.sev { display: inline-block; padding: 1px 0.5714rem; border-radius: 0.7143rem; font-size: 0.8571rem; font-weight: 700; }
.sev-critical, .sev-high { color: var(--critical); background: var(--critical-soft); }
.sev-medium { color: var(--warning-ink); background: rgba(251, 179, 21, .15); }
.sev-low { color: var(--text-secondary); background: var(--surface-2); }

.detail { margin-top: 1.1429rem; }
.detail-title { font-size: 1.2143rem !important; color: var(--text-primary); }
.actors { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 1.1429rem; }
.actor { border: 1px solid var(--line); border-radius: 0.8571rem; padding: 0 1rem 0.8571rem; }
.actor h3 { font-size: 1rem; margin: 0.8571rem 0 0.5714rem; color: var(--brand); }
.actor-AI { background: var(--surface-2); }
.actor dl { margin: 0; font-size: 0.9286rem; }
.actor dt { font-weight: 700; margin-top: 0.5714rem; }
.actor dd { margin: 2px 0 0; line-height: 1.6; }
.actor dd ul { margin: 0; padding-left: 1.2857rem; }
.actor ol { padding-left: 1.2857rem; font-size: 0.9286rem; }
.actor time { color: var(--text-muted); font-size: 0.8571rem; margin-right: 0.2857rem; }
.note { color: var(--text-secondary); font-size: 0.8571rem; }

/* ===== 予兆 ===== */
.signs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1429rem; }
.sign-card { display: flex; flex-direction: column; gap: 0.4286rem; border-top: 0.2857rem solid var(--warning); }
.sign-card .status { align-self: flex-start; }
.sign-card .where { font-weight: 700; font-size: 1.0714rem; margin-top: 0.2857rem; }

/* ===== ログ調査 ===== */
.logsearch form { display: flex; gap: 0.5714rem; padding: 0.7143rem; }
.logsearch input { flex: 1; padding: 0.7143rem 0.8571rem; font-size: 1.0714rem; border: 1px solid var(--line); border-radius: 0.5714rem; background: var(--surface-1); color: var(--text-primary); }
.examples { display: flex; flex-wrap: wrap; gap: 0.5714rem; margin: 1rem 0; }
.example { background: var(--surface-1); border: 1px solid var(--line); color: var(--brand); border-radius: 1.1429rem; padding: 0.3571rem 0.8571rem; cursor: pointer; font-size: 0.9286rem; }
.example:hover { border-color: var(--brand); }
.answer .q { font-weight: 700; color: var(--text-primary); margin-bottom: 0.5714rem; }
.answer .a { display: flex; gap: 0.7143rem; align-items: flex-start; }
.answer .a p { margin: 0; line-height: 1.8; }
.answer .sources { color: var(--text-secondary); font-size: 0.8571rem; margin-top: 0.8571rem; border-top: 1px dashed var(--line); padding-top: 0.5714rem; }
.thinking { color: var(--brand); display: flex; gap: 0.7143rem; align-items: center; }

@media (max-width: 1200px) {
  .span-8, .span-7, .span-5, .span-4 { grid-column: span 12; }
  .span-3 { grid-column: span 6; }
  .actors, .signs { grid-template-columns: 1fr; }
}

/* ===== 表示設定（文字サイズ・テーマ） ===== */
.settings { position: relative; }
.settings summary { list-style: none; font-weight: 700; font-size: 0.9286rem; }
.settings summary::-webkit-details-marker { display: none; }
.settings[open] summary { border-color: var(--brand); color: var(--brand); }
.settings-panel { position: absolute; right: 0; top: calc(100% + 0.5rem); z-index: 10; width: 17rem; padding: 0.8571rem 1rem 1rem;
  background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16, 24, 40, .16); }
.settings-label { font-size: 0.8571rem; color: var(--text-secondary); margin: 0.5714rem 0 0.4286rem; }
.settings-label:first-child { margin-top: 0; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 0.7143rem; padding: 2px; gap: 2px; background: var(--surface-2); }
.seg button { flex: 1; border: 0; background: transparent; color: var(--text-primary); border-radius: 0.5714rem; padding: 0.4286rem 0; cursor: pointer; font-family: inherit; }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; font-weight: 700; }

/* 特大: 横に並べると狭くなるので段組みを減らす */
html[data-font="xl"] .span-8, html[data-font="xl"] .span-7, html[data-font="xl"] .span-5, html[data-font="xl"] .span-4 { grid-column: span 12; }
html[data-font="xl"] .span-3 { grid-column: span 6; }
html[data-font="xl"] .signs { grid-template-columns: repeat(2, 1fr); }
html[data-font="xl"] .actors { grid-template-columns: 1fr; }

/* 拠点の補足は1行（はみ出しは省略。全文は title で表示） */
.site > div:first-child { min-width: 0; }
.site .d { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 大: 推移と拠点は縦に並べる */
html[data-font="l"] .span-8, html[data-font="l"] .span-4 { grid-column: span 12; }

/* 対応履歴の表: 日時・重要度などは折り返さない（内容の列だけ折り返す） */
table.incidents th, table.incidents td { white-space: nowrap; }
table.incidents td:nth-child(4) { white-space: normal; }
table.incidents td:nth-child(4) { min-width: 16em; }
.card.flush:has(> table.incidents) { overflow-x: auto; }

/* ===== ログイン ===== */
.who { display: flex; align-items: center; gap: 0.5714rem; color: var(--text-secondary); font-size: 0.8571rem; white-space: nowrap; }
.who[hidden] { display: none; }
.iconbtn.logout { width: auto; padding: 0 0.8571rem; font-size: 0.8571rem; }
body.login { display: grid; grid-template-columns: 1fr; place-items: center; background: var(--nav-bg); }
.login-card { width: min(26rem, 92vw); background: var(--surface-1); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem; }
.login-card .logo { color: var(--text-primary); padding: 0; margin-bottom: 1.4286rem; }
.login-card .logo small { color: var(--text-secondary); }
.login-card h1 { font-size: 1.2857rem; margin: 0 0 0.4286rem; }
.login-card p.lead { color: var(--text-secondary); font-size: 0.9286rem; margin: 0 0 1.2857rem; line-height: 1.6; }
.login-card label { display: block; font-weight: 700; font-size: 0.9286rem; margin: 1rem 0 0.3571rem; }
.login-card input { width: 100%; padding: 0.7143rem; border: 1px solid var(--line); border-radius: 0.7143rem; background: var(--surface-1); color: var(--text-primary); font-size: 1rem; }
.login-card .btn { width: 100%; margin-top: 1.4286rem; }
.login-card .btn[disabled] { opacity: .6; cursor: wait; }
.login-card .error { margin-top: 1rem; padding: 0.7143rem; border-radius: 0.7143rem; background: var(--critical-soft); color: var(--critical); font-size: 0.9286rem; }
.login-card .note { margin-top: 1.4286rem; color: var(--text-muted); font-size: 0.7857rem; line-height: 1.6; }
