/* freee-ops — 会社の状態ダッシュボード
   色は dataviz の検証済みパレット（validate_palette.js で light/dark 双方 PASS）を使う。
   売上=青(slot1) / 費用=橙(slot2)、損益の符号は diverging の青↔赤、状態は status パレット。 */

:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface-1: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, .10);
  --series-1: #2a78d6; /* 売上 */
  --series-2: #eb6834; /* 費用 */
  --pos: #2a78d6;      /* 黒字 */
  --neg: #e34948;      /* 赤字 */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --success-text: #006300;
  --shadow: 0 1px 2px rgba(11, 11, 11, .04);
  --r: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface-1: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, .10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --pos: #3987e5;
    --neg: #e66767;
    --success-text: #0ca30c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface-1: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, .10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --pos: #3987e5;
  --neg: #e66767;
  --success-text: #0ca30c;
  --shadow: none;
}

* { box-sizing: border-box; }
/* hidden 属性は display 指定に負けるので明示的に止める */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--plane);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: .01em; }
button, select, input { font: inherit; color: inherit; }

/* ---- ヘッダー ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  max-width: 1180px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.topbar__id { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.topbar__id h1 { font-size: 17px; white-space: nowrap; }
.topbar__sub { color: var(--muted); font-size: 13px; }
.topbar__dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
  align-self: center; flex: none;
}
.topbar__dot.is-ok { background: var(--good); }
.topbar__dot.is-ng { background: var(--critical); }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.stamp { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }

.btn {
  border: 1px solid var(--border); background: var(--surface-1); color: var(--ink);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; box-shadow: var(--shadow);
}
.btn:hover { background: color-mix(in srgb, var(--surface-1) 90%, var(--ink)); }
.btn:disabled { opacity: .5; cursor: default; }
.btn--ghost { background: transparent; box-shadow: none; }
.btn--primary { background: var(--series-1); border-color: transparent; color: #fff; }

/* ---- レイアウト ---- */
main { max-width: 1180px; margin: 0 auto; padding: 0 20px 64px; }
.block { margin-top: 34px; }
.block__head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.block__head h2 { font-size: 15px; letter-spacing: .04em; }
.block__note { margin: 0; color: var(--muted); font-size: 12.5px; }

.filters {
  margin-top: 18px; padding: 12px 14px;
  display: flex; gap: 18px; flex-wrap: wrap; align-items: center;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r);
}
.field { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.field--v { display: block; }
.field--v span { display: block; margin-bottom: 4px; }
.field--v input, .field--v select { width: 100%; }
.field--check { gap: 6px; }
.field select, .field input {
  background: var(--plane); border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px;
}

/* ---- タイル ---- */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r);
  padding: 14px 15px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px;
  text-align: left; width: 100%;
}
.tile__label { color: var(--ink-2); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.tile__value { font-size: 25px; font-weight: 600; letter-spacing: -.01em; }
.tile__sub { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tile__delta { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tile__delta.is-up { color: var(--success-text); }
.tile__delta.is-down { color: var(--critical); }
.tile--link { cursor: pointer; }
.tile--link:hover { border-color: color-mix(in srgb, var(--ink) 25%, var(--border)); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.dot--good { background: var(--good); }
.dot--warning { background: var(--warning); }
.dot--serious { background: var(--serious); }
.dot--critical { background: var(--critical); }
.tiles--status .tile__value { font-size: 22px; }

/* ---- カード／チャート ---- */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); margin-top: 14px; }
@media (max-width: 900px) { .cards { grid-template-columns: 1fr; } }
.card {
  margin: 0; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r); padding: 14px 16px 10px; box-shadow: var(--shadow);
}
.card figcaption h3 { font-size: 14px; }
.card__sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.chart { margin-top: 10px; outline: none; }
.chart:focus-visible { box-shadow: 0 0 0 2px var(--series-1); border-radius: 6px; }
.chart svg { display: block; width: 100%; height: auto; }
.legend { display: flex; gap: 14px; margin-top: 8px; font-size: 12.5px; color: var(--ink-2); }
.legend__item { display: flex; align-items: center; gap: 6px; }
.legend__swatch { width: 10px; height: 10px; border-radius: 3px; }

.is-stale { opacity: .55; transition: opacity .2s; }

/* ---- 部門別の横棒 ---- */
.bars { display: grid; gap: 6px; }
.bars__row {
  display: grid; grid-template-columns: 7.5em 1fr 8.5em; align-items: center; gap: 10px;
  padding: 3px 0; border-radius: 6px;
}
.bars__row:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.bars__name { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars__track { position: relative; height: 18px; }
.bars__fill { position: absolute; top: 2px; height: 14px; border-radius: 0 4px 4px 0; }
.bars__fill.is-neg { border-radius: 4px 0 0 4px; }
.bars__val { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.bars__zero { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--axis); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.seg__btn { background: var(--surface-1); border: 0; padding: 5px 14px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.seg__btn + .seg__btn { border-left: 1px solid var(--border); }
.seg__btn.is-on { background: color-mix(in srgb, var(--series-1) 14%, var(--surface-1)); color: var(--ink); }

/* ---- 表 ---- */
.tablewrap {
  margin-top: 14px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r); padding: 10px 14px;
}
.tablewrap > summary { cursor: pointer; font-size: 13px; color: var(--ink-2); }
.scroller { overflow-x: auto; margin-top: 10px; }
.table { border-collapse: collapse; width: 100%; font-size: 13px; }
.table th, .table td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
.table th:first-child, .table td:first-child { text-align: left; }
.table thead th { color: var(--muted); font-weight: 500; font-size: 12px; }
.table td.num, .table th.num { font-variant-numeric: tabular-nums; }
.table tr.is-total td { font-weight: 600; border-top: 1px solid var(--axis); }
.table tbody tr:hover { background: color-mix(in srgb, var(--ink) 3%, transparent); }
.neg { color: var(--critical); }
.pos { color: var(--success-text); }
.sub { color: var(--muted); font-size: 12px; }
.chip {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11.5px;
  border: 1px solid var(--border); color: var(--ink-2);
}
.chip--critical { border-color: color-mix(in srgb, var(--critical) 45%, transparent); color: var(--critical); }
.chip--warning { border-color: color-mix(in srgb, var(--warning) 60%, transparent); color: var(--ink-2); }

/* ---- 残タスク ---- */
.tgroup { margin-top: 14px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.tgroup__head {
  display: flex; align-items: center; gap: 10px; padding: 12px 15px; cursor: pointer;
  list-style: none;
}
.tgroup__head::-webkit-details-marker { display: none; }
.tgroup__head h3 { font-size: 14px; }
.tgroup__meta { margin-left: auto; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tgroup__body { padding: 0 15px 14px; }
.tgroup[open] .tgroup__head { border-bottom: 1px solid var(--grid); margin-bottom: 12px; }
.empty { color: var(--muted); font-size: 13px; padding: 6px 0; }

.tip {
  position: fixed; z-index: 40; pointer-events: none;
  background: var(--surface-1); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.14);
  min-width: 150px;
}
.tip__t { font-weight: 600; margin-bottom: 4px; }
.tip__r { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tip__r span:last-child { font-variant-numeric: tabular-nums; }
.tip__k { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }

/* ---- 設定 ---- */
.setup {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--plane) 78%, transparent); backdrop-filter: blur(6px); padding: 20px;
}
.setup__card {
  width: min(440px, 100%); background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; display: grid; gap: 14px; box-shadow: 0 18px 50px rgba(0,0,0,.16);
}
.setup__lead { margin: 0; color: var(--ink-2); font-size: 13px; }
.setup__msg { margin: 0; font-size: 13px; min-height: 1.2em; color: var(--critical); }
.setup__msg.is-ok { color: var(--success-text); }
.setup__actions { display: flex; gap: 8px; }

.foot { margin-top: 40px; color: var(--muted); font-size: 12px; }
.banner {
  margin-top: 14px; padding: 10px 14px; border-radius: var(--r); font-size: 13px;
  border: 1px solid color-mix(in srgb, var(--critical) 40%, transparent);
  background: color-mix(in srgb, var(--critical) 8%, var(--surface-1));
}
