:root {
  --bg: #eeede8;
  --panel: #fbfaf7;
  --ink: #111110;
  --muted: #6d6c66;
  --faint: #b9b7ae;
  --line: #d8d6cd;
  --track: #e6e4dc;
  --red: #d63a2a;
  --orange: #e9772a;
  --green: #2e8b57;
  --blue: #2c5fd6;
  --gray: #9a988f;
  --lane-staff: var(--green);
  --lane-accountant: var(--blue);
  --lane-director: #111110;
  --lane-review: var(--orange);
  --lane-spam: #c9c7bd;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Noto Sans JP', system-ui, -apple-system, 'Hiragino Sans', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  padding: 24px 24px 64px;
  max-width: 1680px;
  margin: 0 auto;
  overflow-x: hidden;
}
.mono { font-family: var(--mono); }
button { font: inherit; color: inherit; cursor: pointer; }
.empty { color: var(--muted); font-size: 13px; margin: 8px 0; }

/* ---------- header ---------- */
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
h1 { font-size: clamp(26px, 4vw, 44px); font-weight: 900; letter-spacing: -0.02em; margin: 0; line-height: 1.1; }
.sub { color: var(--muted); font-size: 11px; margin: 8px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1.5px solid var(--ink); background: var(--panel); padding: 10px 16px; border-radius: 2px;
  font-weight: 700; font-size: 13px; transition: transform .1s, background .2s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn.primary { background: var(--ink); color: var(--panel); }
.btn.ghost { border-color: var(--line); color: var(--muted); }

/* ---------- progress ---------- */
.progress { margin: 18px 0 12px; background: var(--panel); border: 1px solid var(--line); padding: 12px 14px; }
.progress-top { display: flex; align-items: baseline; gap: 12px; }
.phase { font-size: 11px; letter-spacing: .08em; color: var(--muted); }
.progress[data-phase="running"] .phase,
.progress[data-phase="importing"] .phase { color: var(--ink); }
.progress[data-phase="running"] .phase::before,
.progress[data-phase="importing"] .phase::before {
  content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red);
  margin-right: 8px; animation: blink 1s infinite; vertical-align: 1px;
}
.progress-count { font-size: 12px; color: var(--muted); flex: 1; }
.progress-pct { font-family: var(--mono); font-weight: 600; font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; }
.progress-pct small { font-size: 14px; margin-left: 2px; color: var(--muted); }
.track { position: relative; height: 12px; background: var(--track); margin-top: 10px; overflow: hidden; }
.fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--ink); transition: width .35s cubic-bezier(.2,.8,.2,1); }
.progress[data-phase="running"] .fill,
.progress[data-phase="importing"] .fill {
  background-image: repeating-linear-gradient(-45deg, rgba(255,255,255,.14) 0 10px, transparent 10px 20px);
  background-size: 28px 28px; animation: stripes .6s linear infinite;
}
.progress[data-phase="running"] .fill::after,
.progress[data-phase="importing"] .fill::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; width: 60px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55)); animation: glow 1.2s ease-in-out infinite;
}
.progress[data-phase="done"] .fill { background: var(--green); }
@keyframes stripes { to { background-position: 28px 0; } }
@keyframes glow { 50% { opacity: .2; } }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); padding: 8px 12px 10px; min-width: 0; }
.kpi label { display: block; font-family: var(--mono); font-size: 10px; letter-spacing: .06em; color: var(--muted); }
.kpi b { display: block; font-family: var(--mono); font-weight: 600; font-size: clamp(22px, 2.6vw, 36px); line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }
.kpi b small { font-size: 13px; color: var(--muted); margin-left: 2px; }
.kpi.dark { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.kpi.dark label { color: #a8a79f; }
.kpi.alert b { color: var(--red); }
.kpi b.bump { animation: bump .35s; }
@keyframes bump { 40% { transform: translateY(-3px); } }

/* ---------- board ---------- */
.board {
  display: grid; gap: 12px;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  grid-template-areas: "inbox teardown" "inbox aggregate" "alerts alerts" "review review";
}
.inbox { grid-area: inbox; }
.teardown { grid-area: teardown; }
.aggregate { grid-area: aggregate; }
.alerts-strip { grid-area: alerts; }
.review-strip { grid-area: review; }
.panel { background: var(--panel); border: 1px solid var(--line); padding: 10px 12px 12px; min-width: 0; }
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 11px; letter-spacing: .06em; color: var(--muted);
  padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 10px;
}
.panel-head > span:first-child { color: var(--ink); font-weight: 600; }

/* ---------- inbox tiles ---------- */
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 10px; color: var(--muted); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.sw { display: inline-block; width: 10px; height: 10px; }
.sw.lane-staff { background: var(--lane-staff); }
.sw.lane-accountant { background: var(--lane-accountant); }
.sw.lane-director { background: var(--lane-director); }
.sw.lane-review { background: var(--lane-review); }
.sw.lane-spam { background: var(--lane-spam); }
.sw-deadline { border: 2px solid var(--red); }
.tiles { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; }
.tiles .empty { grid-column: 1 / -1; }
.tile {
  position: relative; aspect-ratio: 1 / 1; border: 1px solid var(--line); background: #f3f2ec;
  padding: 4px; font-size: 9px; line-height: 1.25; text-align: left; overflow: hidden; color: var(--muted);
  transition: background .4s, color .4s, border-color .4s, transform .15s;
  animation: drop .35s both;
}
.tile:hover { transform: scale(1.06); z-index: 2; }
.tile .t-subj { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tile .t-flag { position: absolute; right: 3px; bottom: 2px; font-family: var(--mono); font-size: 9px; font-weight: 600; }
.tile.analyzing { border-color: var(--ink); color: var(--ink); background: #fff; }
.tile.analyzing::after {
  content: ''; position: absolute; left: 0; right: 0; height: 30%;
  background: linear-gradient(180deg, transparent, rgba(214,58,42,.25), transparent);
  animation: scan .8s linear infinite;
}
.tile.done { color: #fff; border-color: transparent; }
.tile.done.lane-staff { background: var(--lane-staff); }
.tile.done.lane-accountant { background: var(--lane-accountant); }
.tile.done.lane-director { background: var(--lane-director); }
.tile.done.lane-review { background: var(--lane-review); }
.tile.done.lane-spam { background: var(--lane-spam); color: var(--ink); }
.tile.deadline { box-shadow: inset 0 0 0 3px var(--red); }
.tile.error { background: #fff; border: 1px dashed var(--red); color: var(--red); }
.tile.selected { outline: 3px solid var(--ink); outline-offset: 1px; z-index: 3; }
.tile.just { animation: pop .5s; }
@keyframes drop { from { opacity: 0; transform: translateY(-8px) scale(.9); } }
@keyframes pop { 40% { transform: scale(1.18); } }
@keyframes scan { from { top: -30%; } to { top: 100%; } }

/* ---------- teardown ---------- */
.td-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; margin-bottom: 10px; }
.td-subj { font-weight: 700; font-size: 16px; margin: 0 0 4px; }
.td-from { font-size: 12px; color: var(--muted); }
.td-body { font-size: 12px; color: #3a3935; white-space: pre-wrap; max-height: 96px; overflow: auto; background: #f3f2ec; padding: 8px; margin: 8px 0 0; }
.td-deadline { text-align: right; min-width: 120px; }
.td-deadline .days { font-family: var(--mono); font-weight: 600; font-size: 30px; line-height: 1; }
.td-deadline .date { font-size: 12px; }
.td-deadline .src { font-size: 10px; color: var(--muted); }
.lvl-overdue, .lvl-critical { color: var(--red); }
.lvl-warning { color: var(--orange); }
.lvl-unknown { color: var(--red); }
.lane-badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; color: #fff; margin-top: 6px; white-space: nowrap; }
td .lane-badge { margin-top: 0; }
.lane-badge.lane-staff { background: var(--lane-staff); }
.lane-badge.lane-accountant { background: var(--lane-accountant); }
.lane-badge.lane-director { background: var(--lane-director); }
.lane-badge.lane-review { background: var(--lane-review); }
.lane-badge.lane-spam { background: var(--lane-spam); color: var(--ink); }
.reasons { font-size: 11px; color: var(--orange); margin-left: 6px; }

.q-rows { display: grid; gap: 7px; }
.q-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) 44px; gap: 10px; align-items: center; animation: rise .4s both; }
.q-label { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: .04em; }
.q-val { font-size: 13px; font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.q-val .alt { font-weight: 400; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-pct { font-family: var(--mono); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.q-row.low .q-pct, .q-row.low .q-val > span:first-child { color: var(--red); }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }

.bar { position: relative; height: 5px; background: var(--track); margin-top: 3px; overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--ink); transition: width .7s cubic-bezier(.2,.8,.2,1); }
.low .bar > i, .bar.low > i {
  background: repeating-linear-gradient(90deg, var(--red) 0 6px, transparent 6px 9px);
}
.bar.hot > i { background: var(--red); }

/* ---------- aggregate ---------- */
.agg-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.agg-col h3 { font-family: var(--mono); font-weight: 600; font-size: 10px; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.agg-item { margin-bottom: 6px; }
.agg-item .row { display: flex; justify-content: space-between; font-size: 11px; gap: 6px; }
.agg-item .row b { font-family: var(--mono); font-weight: 600; }
.agg-col:nth-child(1) .bar > i { background: var(--ink); }
.agg-col:nth-child(2) .bar > i { background: var(--blue); }
.agg-col:nth-child(3) .bar > i { background: var(--orange); }

/* ---------- strips ---------- */
.cards { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x proximity; }
.card {
  flex: 0 0 168px; scroll-snap-align: start; text-align: left; background: #fff; border: 1px solid var(--line);
  padding: 8px 10px; animation: rise .35s both; transition: transform .15s;
}
.card:hover { transform: translateY(-2px); }
.card .c-org { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .c-big { font-family: var(--mono); font-weight: 600; font-size: 22px; line-height: 1.2; }
.card .c-subj { font-size: 11px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.card .c-note { font-family: var(--mono); font-size: 9px; color: var(--muted); margin-top: 4px; }
.alerts-strip .card { border-color: #f0c5bf; background: #fff7f5; }
.alerts-strip .card.lvl-warning { border-color: #f3d3b8; background: #fffaf4; }
.review-strip .card { border-style: dashed; border-color: var(--orange); }
.review-strip .card .c-big { color: var(--orange); }

/* ---------- table ---------- */
.table-panel { margin-top: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; padding: 4px 10px; font-size: 12px; border-radius: 999px; font-family: var(--sans); color: var(--ink); }
.chip b { font-family: var(--mono); margin-left: 4px; }
.chip.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.hint { font-size: 10px; color: var(--muted); margin: 0 0 6px; }
.table-wrap { overflow-x: auto; max-height: 640px; overflow-y: auto; border: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; min-width: 1500px; font-size: 12px; }
thead th {
  position: sticky; top: 0; z-index: 1; background: var(--ink); color: var(--panel);
  font-family: var(--mono); font-weight: 600; font-size: 10px; letter-spacing: .04em;
  text-align: left; padding: 8px; white-space: nowrap; cursor: pointer; user-select: none;
}
thead th:hover { background: #33322f; }
thead th .arrow { opacity: .35; margin-left: 4px; }
thead th[aria-sort="ascending"] .arrow, thead th[aria-sort="descending"] .arrow { opacity: 1; color: #ffb199; }
tbody td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .3s; }
tbody tr:hover { background: #f4f3ee; }
tbody tr.selected { background: #fff1c9; }
tbody tr.flash { animation: flash 1.2s; }
@keyframes flash { from { background: #fff1c9; } }
.c-subject { min-width: 240px; max-width: 320px; }
.c-subject b { display: block; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-subject span { font-size: 10px; color: var(--muted); }
.cell { min-width: 96px; }
.cell .top { display: flex; justify-content: space-between; gap: 6px; }
.cell .top span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .top b { font-family: var(--mono); font-weight: 600; font-variant-numeric: tabular-nums; }
.cell.dim { color: var(--faint); }
.cell.dim .bar > i { background: var(--faint); }
.cell.low .top b { color: var(--red); }
.pending-cell { color: var(--faint); font-family: var(--mono); font-size: 10px; }
.analyzing-cell { height: 10px; background: linear-gradient(90deg, var(--track), #fff, var(--track)); background-size: 200% 100%; animation: shimmer 1s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.dl { font-family: var(--mono); font-weight: 600; white-space: nowrap; }
.dl small { display: block; font-family: var(--sans); font-weight: 400; font-size: 10px; color: var(--muted); }
.retry { border: 1px solid var(--red); color: var(--red); background: #fff; font-size: 11px; padding: 2px 8px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; top: 16px; display: grid; gap: 8px; z-index: 50; width: min(360px, calc(100vw - 32px)); }
.toast {
  background: var(--ink); color: var(--panel); padding: 10px 12px; border-left: 4px solid var(--red);
  font-size: 12px; animation: slidein .3s both; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.toast b { font-family: var(--mono); color: #ffb199; margin-right: 6px; }
.toast.ok { border-left-color: var(--green); }
.toast.out { animation: slideout .3s forwards; }
@keyframes slidein { from { opacity: 0; transform: translateX(24px); } }
@keyframes slideout { to { opacity: 0; transform: translateX(24px); } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .board { grid-template-columns: minmax(0, 1fr); grid-template-areas: "inbox" "teardown" "alerts" "review" "aggregate"; }
}
@media (max-width: 640px) {
  body { padding: 16px 16px 48px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .agg-cols { grid-template-columns: minmax(0, 1fr); }
  .q-row { grid-template-columns: 84px minmax(0, 1fr) 40px; }
  .td-head { grid-template-columns: minmax(0, 1fr); }
  .td-deadline { text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
