:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #1d1c1a;
  --muted: #6c6862;
  --line: #e2dfd8;
  --accent: #c2410c;
  --accent-soft: #fde7da;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --surface: #1f1e1c;
    --surface-2: #2a2826;
    --text: #efece6;
    --muted: #a29d95;
    --line: #36332f;
    --accent: #fb923c;
    --accent-soft: #3b2416;
    --ok: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

header.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.top-inner { max-width: 1100px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 16px; }
.brand { font-weight: 700; padding: 12px 0; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand svg { width: 20px; height: 20px; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a {
  padding: 14px 10px; color: var(--muted); white-space: nowrap; border-bottom: 2px solid transparent; font-weight: 500;
}
nav.tabs a:hover { color: var(--text); text-decoration: none; }
nav.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.logout { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 8px 0; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 64px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--surface-2); }
td.actions-cell { text-align: right; white-space: nowrap; }

.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgb(0 0 0 / 0.2); vertical-align: -2px; margin-right: 6px; flex: none; }
.fil { display: inline-flex; align-items: center; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.low > span { background: var(--bad); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.planned { background: var(--surface-2); color: var(--muted); }
.badge.printing { background: var(--accent-soft); color: var(--accent); }
.badge.done { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.failed, .badge.cancelled { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.badge.low { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

button, .btn {
  font: inherit; font-weight: 550; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); padding: 8px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.05); background: var(--accent); }
button.danger { color: var(--bad); }
button.icon { padding: 4px 8px; border-color: transparent; background: transparent; color: var(--muted); }
button.icon:hover { color: var(--bad); background: var(--surface-2); }
button:disabled { opacity: 0.5; cursor: default; }

form .row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 12px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input[type="color"] { padding: 2px; height: 38px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
.lines { display: grid; gap: 8px; margin: 8px 0 12px; }
.line {
  display: grid; gap: 8px; align-items: end; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2);
  grid-template-columns: 110px minmax(180px, 2fr) 100px 70px 90px 90px 80px 32px;
}
.line .wide { grid-column: span 1; }
@media (max-width: 860px) {
  .line { grid-template-columns: 1fr 1fr; }
  .line .full { grid-column: 1 / -1; }
}

dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text);
  width: min(920px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog .dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
dialog .dlg-head h2 { margin: 0; }
dialog .dlg-body { padding: 16px; overflow-y: auto; max-height: calc(100vh - 160px); }
dialog .dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }

.chart { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .area { fill: var(--accent); opacity: 0.12; }
.chart .series.alt { stroke: var(--muted); stroke-dasharray: 4 3; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; background: var(--accent); vertical-align: middle; margin-right: 6px; }
.legend i.alt { background: var(--muted); }

.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-weight: 550; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.error { background: var(--bad); color: #fff; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input, .filters select { width: auto; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.stat-line { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.stat-line b { color: var(--text); font-variant-numeric: tabular-nums; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); }
.login-card h1 { display: flex; align-items: center; gap: 10px; }
.login-card button { width: 100%; justify-content: center; margin-top: 4px; }
.error-text { color: var(--bad); font-size: 14px; min-height: 20px; margin: 8px 0 0; }
.stack { display: grid; gap: 12px; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }
[hidden] { display: none !important; }
@media (prefers-color-scheme: dark) {
  .swatch { border-color: rgb(255 255 255 / 0.35); }
}
@media (max-width: 640px) {
  .top-inner { flex-wrap: wrap; gap: 0 12px; }
  .brand { flex: 1; padding: 10px 0 2px; }
  .logout { padding: 10px 0 2px; }
  nav.tabs { order: 3; flex-basis: 100%; margin: 0 -16px; padding: 0 8px; }
  nav.tabs a { padding: 10px 10px 12px; }
  .hide-sm { display: none; }
  main { padding-top: 16px; }
  h1 { font-size: 20px; }
  .kpi .value { font-size: 20px; }
  th, td { padding: 8px 6px; }
}
details.plan-lines summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 12px; }
.sub-note { color: var(--muted); font-size: 12px; margin-top: 2px; }
