/* ============================================================
   Design tokens — シャープ・ビジネス・シンプル
   ============================================================ */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --faint: #9ca3af;

  --nav-bg: #0d1628;
  --nav-text: #b8c1d3;
  --nav-active: #ffffff;
  --nav-hover: #18233a;

  --brand: #1d3f8f;
  --brand-2: #2f6fed;
  --brand-soft: #eaf1ff;

  --good: #067a55;
  --good-soft: #e6f5ef;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --info: #475467;
  --info-soft: #eef1f5;

  --c1: #1d3f8f; --c2: #4f8df7; --c3: #12a594; --c4: #9aa4b2;
  --c5: #e5a00d; --c6: #d6456b; --c7: #7c5cdb; --c8: #3aa757;

  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
  --font: "Segoe UI", "Yu Gothic UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 13px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
.num, td.n, .kpi-value { font-variant-numeric: tabular-nums; }

/* ============================================================ Layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.nav {
  background: var(--nav-bg); color: var(--nav-text); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; overflow-y: auto;
}
.brand { padding: 18px 18px 14px; display: flex; align-items: center; gap: 10px; color: #fff; cursor: pointer; }
.brand:hover .brand-name { text-decoration: underline; text-underline-offset: 3px; }
.brand:focus-visible { outline: 2px solid #4f8df7; outline-offset: -4px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 6px; background: linear-gradient(135deg, #2f6fed, #12a594);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: -.5px;
}
.brand-name { font-weight: 650; font-size: 14px; letter-spacing: .2px; }
.brand-sub { font-size: 10.5px; color: #7e8aa3; margin-top: -2px; }
.nav-group { padding: 10px 10px 4px; }
.nav-label { font-size: 10.5px; letter-spacing: .08em; color: #5f6b82; padding: 6px 10px; text-transform: uppercase; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 5px; color: var(--nav-text);
  font-size: 13px; text-decoration: none; margin: 1px 0;
}
.nav a svg { width: 16px; height: 16px; flex: none; opacity: .8; }
.nav a:hover { background: var(--nav-hover); color: #fff; }
.nav a.active { background: #1b2a48; color: var(--nav-active); box-shadow: inset 2px 0 0 #4f8df7; }
.nav a.active svg { opacity: 1; }
.nav .badge { margin-left: auto; background: #c62828; color: #fff; font-size: 10.5px; padding: 0 6px; border-radius: 9px; line-height: 17px; }
.nav-foot { margin-top: auto; padding: 14px 18px; font-size: 11px; color: #5f6b82; border-top: 1px solid #1a253b; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border); padding: 10px 24px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.page-title { font-size: 17px; font-weight: 650; letter-spacing: .2px; margin-right: auto; display: flex; align-items: baseline; gap: 10px; }
.page-title small { font-size: 12px; color: var(--muted); font-weight: 400; }
.content { padding: 20px 24px 48px; max-width: 1480px; width: 100%; }
.menu-btn { display: none; }

/* ============================================================ Controls */
.ctrl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 5px 11px; cursor: pointer; font-size: 12.5px; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--brand); color: #fff; }
.select, .input {
  height: 30px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: #fff; padding: 0 9px; font-size: 12.5px;
}
.select { padding-right: 26px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b7280' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; }
.select:focus, .input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand-2); }
.btn {
  height: 30px; padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: #fff;
  cursor: pointer; font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 14px; height: 14px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #17357a; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: default; }
.ws-switch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--brand-soft); color: var(--brand); border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 12px; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--brand); width: 18px; height: 18px; border-radius: 9px; line-height: 1; }
.chip button:hover { background: #d6e3ff; }
.period-note { font-size: 11.5px; color: var(--muted); }

/* ============================================================ Cards & grid */
.grid { display: grid; gap: 14px; }
.g-kpi { grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); }
.g-2 { grid-template-columns: 1fr 1fr; }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-21 { grid-template-columns: 2fr 1fr; }
.g-12 { grid-template-columns: 1fr 2fr; }
.mt { margin-top: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px 0; min-height: 40px; }
.card-t { font-size: 13.5px; font-weight: 650; color: var(--text); }
.card-s { font-size: 11.5px; color: var(--muted); }
.card-h .right { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.card-b { padding: 12px 16px 16px; }
.card-b.flush { padding: 8px 0 0; }

.kpi { padding: 14px 16px 13px; position: relative; }
.kpi-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 23px; font-weight: 650; letter-spacing: -.3px; margin-top: 4px; color: var(--text); line-height: 1.25; }
.kpi-value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.kpi-sub { margin-top: 6px; font-size: 11.5px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.kpi .bar { height: 4px; background: #eef0f3; border-radius: 2px; margin-top: 9px; overflow: hidden; }
.kpi .bar i { display: block; height: 100%; background: var(--brand-2); border-radius: 2px; }
.kpi .bar i.over { background: var(--good); }
.kpi .bar i.under { background: var(--warn); }

.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--muted); }

.chart { width: 100%; height: 300px; }
.chart.sm { height: 220px; }
.chart.lg { height: 360px; }

/* ============================================================ Insights & alerts */
.insights { display: flex; flex-direction: column; }
.insight { display: grid; grid-template-columns: 4px 1fr; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--border); }
.insight:first-child { border-top: 0; }
.insight .rail { border-radius: 2px; background: var(--info); }
.insight.good .rail { background: var(--good); }
.insight.bad .rail { background: var(--bad); }
.insight.warn .rail { background: var(--warn); }
.insight-t { font-weight: 600; font-size: 12.5px; display: flex; gap: 8px; align-items: center; }
.insight-x { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }
.insight a { font-size: 11.5px; margin-left: auto; font-weight: 400; }
.alert-list { display: flex; flex-direction: column; }
.alert-item { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--border); cursor: pointer; }
.alert-item:hover { background: var(--surface-2); }
.alert-item:first-child { border-top: 0; }
.alert-count { min-width: 34px; height: 28px; border-radius: 5px; display: grid; place-items: center; font-weight: 700; background: var(--bad-soft); color: var(--bad); }
.alert-item .lbl { font-weight: 600; font-size: 12.5px; }
.alert-item .sub { color: var(--muted); font-size: 11.5px; }
.alert-item .amt { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 12.5px; }

.tag { display: inline-block; padding: 0 7px; border-radius: 3px; font-size: 11px; line-height: 18px; font-weight: 600; background: var(--info-soft); color: var(--info); white-space: nowrap; }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.brand { background: var(--brand-soft); color: var(--brand); }
.tag.A { background: #e8eefc; color: #1d3f8f; }
.tag.B { background: #e5f6f3; color: #0d7f72; }
.tag.C { background: #f0f1f3; color: #667085; }

/* ============================================================ Tables */
.tbl-wrap { overflow-x: auto; }
.tbl-tools { display: flex; align-items: center; gap: 8px; padding: 0 16px 8px; }
.tbl-tools .count { font-size: 11.5px; color: var(--muted); }
.tbl-tools .right { margin-left: auto; display: flex; gap: 6px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; padding: 7px 10px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; cursor: pointer; user-select: none;
}
.tbl th.n, .tbl td.n { text-align: right; }
.tbl th:first-child, .tbl td:first-child { padding-left: 16px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 16px; }
.tbl th .arrow { color: var(--brand-2); margin-left: 3px; }
.tbl td { padding: 7px 10px; border-bottom: 1px solid #f0f2f5; white-space: nowrap; color: var(--text-2); }
.tbl td.wrap { white-space: normal; min-width: 180px; }
.tbl tbody tr:hover td { background: #f8faff; }
.tbl tr.click { cursor: pointer; }
.tbl tfoot td { font-weight: 650; color: var(--text); border-top: 1px solid var(--border-strong); background: var(--surface-2); }
.tbl .cellbar { position: relative; }
.tbl .cellbar i { position: absolute; right: 10px; bottom: 3px; height: 3px; background: #c9d8fb; border-radius: 2px; }
.more { text-align: center; padding: 8px; }
.unit-note { font-size: 11px; color: var(--faint); font-weight: 400; }

/* heatmap table */
.heat td.n { position: relative; }

/* ============================================================ Upload */
.drop {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 30px; text-align: center; background: var(--surface-2);
  transition: .15s; cursor: pointer;
}
.drop.over { border-color: var(--brand-2); background: var(--brand-soft); }
.drop h3 { margin: 6px 0 4px; font-size: 15px; }
.drop p { margin: 0; color: var(--muted); }
.drop svg { width: 34px; height: 34px; color: var(--brand-2); }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.step { padding: 14px 16px; display: flex; gap: 12px; }
.step + .step { border-left: 1px solid var(--border); }
.step b { width: 24px; height: 24px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 12px; flex: none; }
.step h4 { margin: 0 0 2px; font-size: 13px; }
.step p { margin: 0; font-size: 12px; color: var(--muted); }
.file { border-top: 1px solid var(--border); }
.file-h { display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
.file-h .name { font-weight: 600; }
.file-h svg, .notice svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
.notice svg { color: inherit; }
.sheet { display: grid; grid-template-columns: 180px 170px 1fr auto; gap: 12px; align-items: start; padding: 10px 16px 12px 40px; border-top: 1px dashed var(--border); }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px 12px; }
.map-row { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 6px; font-size: 12px; }
.map-row .req { color: var(--bad); }
.map-row .select { height: 26px; font-size: 12px; }
.preview { margin-top: 8px; font-size: 11.5px; }
.preview table { border-collapse: collapse; }
.preview td, .preview th { border: 1px solid var(--border); padding: 2px 6px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.preview th { background: var(--surface-2); font-weight: 600; }
.meter { height: 6px; width: 90px; background: #eef0f3; border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; }
.meter i { display: block; height: 100%; background: var(--good); }

/* ============================================================ Modal / toast / misc */
.modal-bg { position: fixed; inset: 0; background: rgba(13, 22, 40, .45); z-index: 50; display: flex; justify-content: flex-end; }
.modal { width: min(760px, 100%); height: 100%; background: var(--bg); overflow-y: auto; box-shadow: -8px 0 24px rgba(0,0,0,.12); animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: .4; } }
.modal-h { position: sticky; top: 0; background: #fff; border-bottom: 1px solid var(--border); padding: 14px 20px; display: flex; align-items: center; gap: 12px; z-index: 2; }
.modal-h h2 { margin: 0; font-size: 16px; }
.modal-b { padding: 16px 20px 40px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 9px 16px; border-radius: 6px; z-index: 60; font-size: 12.5px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }
.spin { width: 22px; height: 22px; border: 2px solid var(--border); border-top-color: var(--brand-2); border-radius: 50%; animation: sp .8s linear infinite; margin: 0 auto 10px; }
@keyframes sp { to { transform: rotate(360deg); } }
.notice { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-radius: var(--radius); background: var(--brand-soft); color: var(--brand); border: 1px solid #d5e2ff; }
.notice.warn { background: var(--warn-soft); color: var(--warn); border-color: #f6dfb8; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.legend-note { font-size: 11.5px; color: var(--muted); }
.setting-row { display: grid; grid-template-columns: 200px 1fr; gap: 16px; padding: 12px 0; border-top: 1px solid var(--border); align-items: center; }
.setting-row:first-child { border-top: 0; }
.setting-row .hint { font-size: 11.5px; color: var(--muted); }
.fill { display: inline-block; width: 60px; height: 5px; background: #eef0f3; border-radius: 3px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.fill i { display: block; height: 100%; background: var(--brand-2); }

/* ============================================================ Report (print) */
.report { background: #fff; border: 1px solid var(--border); padding: 28px 32px; max-width: 1060px; margin: 0 auto; }
.report h1 { font-size: 20px; margin: 0; }
.report .r-head { display: flex; align-items: flex-end; border-bottom: 2px solid var(--brand); padding-bottom: 10px; margin-bottom: 16px; }
.report .r-head .meta { margin-left: auto; text-align: right; font-size: 12px; color: var(--muted); }
.report h3 { font-size: 13.5px; margin: 18px 0 8px; padding-left: 8px; border-left: 3px solid var(--brand); }
.report .card { box-shadow: none; }

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .nav, .topbar, .no-print { display: none !important; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
  .report { border: 0; padding: 0; max-width: none; }
  .card { break-inside: avoid; }
}

/* ============================================================ Responsive */
@media (max-width: 1100px) {
  .g-3 { grid-template-columns: 1fr 1fr; }
  .g-21, .g-12 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: fixed; z-index: 40; width: 240px; transform: translateX(-100%); transition: .2s; }
  .nav.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 40px; }
  .g-2, .g-3 { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr; }
  .step + .step { border-left: 0; border-top: 1px solid var(--border); }
  .sheet { grid-template-columns: 1fr; padding-left: 16px; }
  .setting-row { grid-template-columns: 1fr; gap: 6px; }
}
