:root {
  --ground: #f3f4f1;
  --surface: #ffffff;
  --ink: #16181a;
  --muted: #55595c;
  --line: #d5d8d1;
  --line-strong: #9a9e97;
  --accent: #d9530f;
  --accent-ink: #b4450a;
  --bar: #16181a;
  --bar-ink: #f3f4f1;
  --orig: #9a9e97;
  --chip: #f3f4f1;
  --error-bg: #fde8e0;
  --error-ink: #8a2a00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #121314;
    --surface: #1c1e20;
    --ink: #eceee9;
    --muted: #a9ada6;
    --line: #34373a;
    --line-strong: #5c6063;
    --accent: #e8611c;
    --accent-ink: #ff8a4c;
    --bar: #0b0c0d;
    --orig: #6d7174;
    --chip: #26292b;
    --error-bg: #3a1a0e;
    --error-ink: #ffb899;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 16px;
}
h2 { margin: 0; font-size: 20px; }
p { margin: 0; }
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }
.strong { font-weight: 600; }
.muted { color: var(--muted); font-size: 14px; }
.accent { color: var(--accent-ink); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar {
  background: var(--bar); color: var(--bar-ink);
  padding: 14px 24px; display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-name { font-size: 20px; font-weight: 700; }
.pill { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #a9ada6; border: 1px solid #3a3d40; padding: 3px 8px; border-radius: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.btn-primary, .btn-ghost, .btn-outline, .btn-dark {
  min-height: 44px; padding: 0 18px; border-radius: 6px; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary { background: var(--accent); color: #fff; border: 0; font-weight: 600; }
.btn-ghost { background: transparent; color: var(--bar-ink); border: 1px solid #55595c; }
.btn-ghost.dark { color: var(--ink); border-color: var(--line-strong); }
.btn-outline { background: transparent; border: 1px solid var(--ink); cursor: pointer; }
.btn-dark { background: var(--ink); color: var(--ground); border: 0; font-weight: 600; flex: 1 1 auto; min-height: 48px; }

main { max-width: 1200px; margin: 0 auto; padding: 24px 16px; display: flex; flex-direction: column; gap: 24px; }
#editor { display: flex; flex-direction: column; gap: 24px; }
#editor[hidden] { display: none; }

.drop {
  border: 2px dashed var(--line-strong); border-radius: 10px; background: var(--surface);
  padding: 20px 24px; display: flex; flex-wrap: wrap; gap: 16px;
  align-items: center; justify-content: space-between;
}
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.drop-file { display: flex; align-items: center; gap: 16px; min-width: 0; }
.drop-file > div { min-width: 0; overflow-wrap: anywhere; }
.drop-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.error { background: var(--error-bg); color: var(--error-ink); border-radius: 8px; padding: 12px 16px; }

.stats {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line); }
.stat-sub { font-family: 'IBM Plex Mono', monospace; font-size: 14px; color: var(--muted); }
.stat-label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-family: 'IBM Plex Mono', monospace; font-size: 24px; font-weight: 600; }
.stat-unit { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.stat-was { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--accent-ink); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 24px; display: flex; flex-direction: column; gap: 18px; min-width: 0;
}
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 24px; align-items: start; }

.chart-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  min-height: 36px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--chip); font-size: 14px;
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
.chart { width: 100%; height: 220px; display: block; }
.chart .orig { stroke: var(--orig); }
.chart .edit { stroke: var(--accent); }
.chart .axis { fill: var(--muted); font-family: 'IBM Plex Mono', monospace; font-size: 11px; }
.chart .grid { stroke: var(--line); }
.legend { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.key { width: 18px; height: 3px; border-radius: 2px; display: inline-block; }
.key.orig { background: var(--orig); }
.key.edit { background: var(--accent); margin-left: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
.field input[type=datetime-local], .field input[type=number], .field select {
  min-height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--surface); font-family: 'IBM Plex Mono', monospace; font-size: 15px; font-weight: 400;
}
.row2 { display: flex; flex-wrap: wrap; gap: 16px; }
.row2 > .field:first-child { flex: 3 1 250px; }
.row2 > .field:last-child { flex: 2 1 160px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  min-height: 44px; min-width: 64px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--chip); font-family: 'IBM Plex Mono', monospace; font-size: 14px;
}
.totals { display: flex; flex-direction: column; gap: 18px; }
.total-row { display: flex; gap: 8px; }
.total-row input { flex: 1 1 auto; min-width: 0; }
.total-row button {
  min-height: 44px; min-width: 56px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--chip); font-family: 'IBM Plex Mono', monospace; font-size: 14px;
}
.total-hint { font-family: 'IBM Plex Mono', monospace; font-size: 13px; font-weight: 400; color: var(--muted); }
.total-hint .accent { color: var(--accent-ink); }
.field input[type=text] {
  min-height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--surface); font-family: 'IBM Plex Mono', monospace; font-size: 15px; font-weight: 400;
}
.kv { margin: 0; background: var(--chip); border-radius: 8px; padding: 14px 16px; display: grid; grid-template-columns: auto 1fr; gap: 10px 20px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.note { font-size: 13px; color: var(--accent-ink); }
.spread { display: flex; justify-content: space-between; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 16px; }
.check { min-height: 44px; display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; }
input[type=range] { accent-color: var(--accent); width: 100%; }
.row-btns { display: flex; flex-wrap: wrap; gap: 10px; }
.foot { text-align: center; padding: 8px 16px 40px; }

@media (max-width: 480px) {
  .topbar { padding: 14px 16px; }
  .drop, .card { padding: 18px 16px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 21px; }
}
