:root {
  --bg: #f5f5f7;
  --sidebar: #ececef;
  --surface: #ffffff;
  --surface-2: #f2f2f5;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #a1a1a6;
  --line: rgba(0, 0, 0, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.06);
  --sel: rgba(0, 0, 0, 0.06);
  --gray: #8e8e93;
  --blue: #007aff;
  --green: #28a745;
  --purple: #8e44d6;
  --orange: #f08c00;
  --red: #e5383b;
  --accent: #ff9f0a;
  --accent-ink: #ffffff;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1c1e;
    --sidebar: #232326;
    --surface: #2c2c2e;
    --surface-2: #3a3a3c;
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #6e6e73;
    --line: rgba(255, 255, 255, 0.09);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    --sel: rgba(255, 255, 255, 0.08);
    --blue: #0a84ff;
    --green: #32d74b;
    --purple: #bf5af2;
    --orange: #ff9f0a;
    --red: #ff453a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1c1c1e;
  --sidebar: #232326;
  --surface: #2c2c2e;
  --surface-2: #3a3a3c;
  --text: #f5f5f7;
  --text-2: #a1a1a6;
  --text-3: #6e6e73;
  --line: rgba(255, 255, 255, 0.09);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  --sel: rgba(255, 255, 255, 0.08);
  --blue: #0a84ff;
  --green: #32d74b;
  --purple: #bf5af2;
  --orange: #ff9f0a;
  --red: #ff453a;
  color-scheme: dark;
}

:root[data-accent="blue"] { --accent: #0a84ff; }
:root[data-accent="mint"] { --accent: #00b894; }
:root[data-accent="grape"] { --accent: #8e5cf7; }
:root[data-accent="rose"] { --accent: #f2557a; }
:root[data-accent="graphite"] { --accent: #636366; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.inline { width: 14px; height: 14px; vertical-align: -2px; opacity: 0.5; }

/* ---------- Layout ---------- */

.app { display: grid; grid-template-columns: minmax(300px, 360px) 1fr; height: 100dvh; }

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  -webkit-mask: none;
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 5px;
  background: var(--accent-ink);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linejoin='round'%3E%3Cpath d='M4 7.5l8-4 8 4v9l-8 4-8-4z'/%3E%3Cpath d='M4 7.5l8 4 8-4M12 11.5v9'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linejoin='round'%3E%3Cpath d='M4 7.5l8-4 8 4v9l-8 4-8-4z'/%3E%3Cpath d='M4 7.5l8 4 8-4M12 11.5v9'/%3E%3C/svg%3E") center / contain no-repeat;
}
.head-actions { display: flex; gap: 6px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: transparent; color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--sel); color: var(--text); }
.icon-btn.accent { background: var(--accent); color: var(--accent-ink); }
.icon-btn.accent:hover { filter: brightness(1.08); background: var(--accent); color: var(--accent-ink); }
.icon-btn.danger:hover { color: var(--red); }
.icon-btn.small { width: 28px; height: 28px; }
.icon-btn.small .ico { width: 16px; height: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sidebar-tools { padding: 0 16px 10px; display: grid; gap: 10px; }
.search {
  display: flex; align-items: center; gap: 6px;
  background: var(--sel); border-radius: 9px; padding: 0 10px; color: var(--text-2);
}
.search .ico { width: 16px; height: 16px; }
.search input { flex: 1; border: 0; background: transparent; padding: 7px 0; outline: none; min-width: 0; }

.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--sel); border-radius: 9px; padding: 2px;
}
.segmented button {
  border: 0; background: transparent; border-radius: 7px; padding: 5px 4px;
  font-size: 13px; font-weight: 500; color: var(--text-2);
}
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.segmented button[data-count]:not([data-count=""])::after { content: " " attr(data-count); color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---------- List ---------- */

.list { list-style: none; margin: 0; padding: 4px 8px 16px; overflow-y: auto; flex: 1; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; border-radius: 10px; cursor: pointer; outline: none;
}
.row:hover { background: var(--sel); }
.row[aria-selected="true"] { background: var(--surface); box-shadow: var(--shadow); }
.row.done .row-title { color: var(--text-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-sub .carrier-dot { flex: none; }
.list-empty { padding: 40px 16px; text-align: center; color: var(--text-3); }

.carrier-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); }
.row-sub .carrier-dot { margin-right: 0; }

.counter { display: grid; justify-items: center; min-width: 40px; line-height: 1; }
.counter-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--accent); }
.counter-unit { font-size: 10.5px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 3px; }
.counter.muted .counter-value { color: var(--text-2); }
.counter.late .counter-value { color: var(--red); }

/* ---------- Status icons ---------- */

.status-icon {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  color: #fff; background: var(--tone);
}
.status-icon .ico { width: 19px; height: 19px; stroke-width: 2; }
.status-icon.xl { width: 56px; height: 56px; }
.status-icon.xl .ico { width: 28px; height: 28px; }
.tone-gray { --tone: var(--gray); }
.tone-blue { --tone: var(--blue); }
.tone-green { --tone: var(--green); }
.tone-purple { --tone: var(--purple); }
.tone-orange { --tone: var(--orange); }
.tone-red { --tone: var(--red); }

/* ---------- Detail ---------- */

.detail { overflow-y: auto; padding: 0 clamp(16px, 4vw, 48px) 48px; }
.detail > * { max-width: 760px; margin-left: auto; margin-right: auto; }

.detail-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0 10px; background: var(--bg);
}
.detail-actions { display: flex; gap: 4px; margin-left: auto; }
.back { display: none; }

.hero { display: flex; align-items: center; gap: 16px; padding: 8px 0 20px; }
.hero-text { flex: 1; min-width: 0; }
.hero h2 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.hero-status { font-size: 15px; font-weight: 600; color: var(--tone); margin-top: 2px; }
.hero-counter { display: grid; justify-items: center; font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-2); letter-spacing: 0.03em; }
.hero-counter span { font-size: 36px; line-height: 1; font-weight: 700; color: var(--accent); letter-spacing: -0.03em; text-transform: none; }
.hero-counter.late span { color: var(--red); }

.steps { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); margin: 0 0 20px; padding: 0; counter-reset: s; }
.steps li { position: relative; display: grid; justify-items: center; gap: 6px; font-size: 11.5px; color: var(--text-3); text-align: center; font-weight: 500; }
.steps li span { width: 12px; height: 12px; border-radius: 50%; background: var(--surface-2); border: 2px solid var(--line); z-index: 1; }
.steps li::before { content: ""; position: absolute; top: 5px; left: -50%; width: 100%; height: 2px; background: var(--line); }
.steps li:first-child::before { display: none; }
.steps li.on { color: var(--text-2); }
.steps li.on span { background: var(--accent); border-color: var(--accent); }
.steps li.on::before { background: var(--accent); }
.steps li.current { color: var(--text); font-weight: 650; }
.steps li.current span { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }
.steps.has-problem li.current span { background: var(--red); border-color: var(--red); box-shadow: 0 0 0 4px color-mix(in srgb, var(--red) 25%, transparent); }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card {
  display: grid; gap: 4px; text-align: left;
  background: var(--surface); border: 0; border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
  min-width: 0;
}
.card-label { font-size: 11.5px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.03em; }
.card-value { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.card-value small { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.copyable:hover { background: var(--surface-2); }
.mono { font-family: var(--mono); font-size: 14px; }

.primary-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px auto 26px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 8px 14px;
  background: var(--surface); box-shadow: var(--shadow); color: var(--text);
  font-weight: 600; text-decoration: none; font-size: 13.5px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn.danger { color: var(--red); }
.btn .ico { width: 16px; height: 16px; }

.history h3, .notes h3 { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.timeline { list-style: none; margin: 0; padding: 4px 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.timeline li { position: relative; display: flex; align-items: flex-start; gap: 14px; padding: 12px 12px 12px 18px; }
.timeline li + li { border-top: 1px solid var(--line); }
.timeline li::before { content: ""; position: absolute; left: 23px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.timeline li:first-child::before { top: 18px; }
.timeline li:last-child::before { bottom: calc(100% - 18px); }
.timeline li:only-child::before { display: none; }
.tl-dot { position: relative; z-index: 1; flex: none; width: 12px; height: 12px; margin-top: 4px; border-radius: 50%; background: var(--tone); box-shadow: 0 0 0 3px var(--surface); }
.timeline li:not(.latest) .tl-dot { opacity: 0.55; }
.tl-body { flex: 1; min-width: 0; }
.tl-title { font-weight: 600; }
.timeline li:not(.latest) .tl-title { font-weight: 500; }
.tl-meta { font-size: 12.5px; color: var(--text-2); }
.timeline .icon-btn { opacity: 0; }
.timeline li:hover .icon-btn, .timeline .icon-btn:focus-visible { opacity: 1; }
.notes { margin-top: 24px; }
.notes p { background: var(--surface); padding: 12px 14px; border-radius: var(--radius); box-shadow: var(--shadow); white-space: pre-wrap; }
.added { margin-top: 24px; font-size: 12px; text-align: center; }
.muted { color: var(--text-2); }

.link-btn { border: 0; background: none; color: var(--accent); font-weight: 500; padding: 8px 0; }
.link-btn.strong { font-weight: 700; }
.history .link-btn { display: block; margin: 6px auto 0; }

.empty { height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; gap: 10px; padding: 40px 0; max-width: 420px; }
.empty-ico { width: 64px; height: 64px; color: var(--text-3); stroke-width: 1.2; }
.empty h2 { font-size: 22px; }
.empty p { color: var(--text-2); }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }

/* ---------- Sheets ---------- */

dialog.sheet {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  border: 0; border-radius: 16px; padding: 0;
  background: var(--bg); color: var(--text);
  box-shadow: 0 24px 64px rgba(0,0,0,0.3);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.32); backdrop-filter: blur(2px); }
dialog[open] { animation: pop 0.18s ease-out; }
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } }

.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 15px; font-weight: 700; }
.sheet-head > :last-child { justify-self: end; }
.sheet-head > :first-child { justify-self: start; }

.fields { display: grid; gap: 12px; padding: 16px; }
.field { display: grid; gap: 4px; }
.field > span, legend { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.03em; }
.field-row { display: flex; gap: 6px; align-items: center; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field input, .field select, .field textarea, fieldset select {
  width: 100%; border: 1px solid var(--line); background: var(--surface);
  border-radius: 9px; padding: 9px 11px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.field input[name="number"] { font-family: var(--mono); letter-spacing: 0.02em; }
.field textarea { resize: vertical; }
.hint { font-size: 12.5px; color: var(--text-2); min-height: 0; }
.hint:empty { display: none; }
.error { color: var(--red); font-size: 13px; font-weight: 500; }
.error:empty { display: none; }

fieldset { border: 0; padding: 0; margin: 0 0 6px; display: grid; gap: 8px; }
legend { padding: 0; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip input, .swatch input, .status-option input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 6px 12px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); font-size: 13px; font-weight: 500; cursor: pointer;
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip input:focus-visible + span, .swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.swatches { display: flex; gap: 10px; }
.swatch span { display: block; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; background: var(--sw); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1); }
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--sw); }
.swatch[data-a="amber"] { --sw: #ff9f0a; }
.swatch[data-a="blue"] { --sw: #0a84ff; }
.swatch[data-a="mint"] { --sw: #00b894; }
.swatch[data-a="grape"] { --sw: #8e5cf7; }
.swatch[data-a="rose"] { --sw: #f2557a; }
.swatch[data-a="graphite"] { --sw: #636366; }

.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.status-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.status-option {
  position: relative; display: grid; justify-items: center; gap: 6px; text-align: center;
  padding: 10px 4px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
  font-size: 11.5px; font-weight: 600; color: var(--text-2); cursor: pointer;
}
.status-option .status-icon { width: 30px; height: 30px; opacity: 0.6; }
.status-option .status-icon .ico { width: 16px; height: 16px; }
.status-option:has(input:checked) { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.status-option:has(input:checked) .status-icon { opacity: 1; }
.status-option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Toasts ---------- */

.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; pointer-events: none; }
.toast {
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg);
  padding: 9px 16px; border-radius: 99px; font-weight: 600; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2); animation: pop 0.2s ease-out; transition: opacity 0.3s, transform 0.3s;
}
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- Narrow screens: list and detail become separate views ---------- */

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .detail { display: none; padding: 0 16px 40px; }
  body.show-detail .sidebar { display: none; }
  body.show-detail .detail { display: block; }
  .back { display: inline-grid; }
  .hero h2 { font-size: 22px; }
  .status-picker { grid-template-columns: repeat(2, 1fr); }
  .field-pair { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Live tracking ---------- */

.live-line {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: -12px auto 22px; padding: 8px 12px; border-radius: 10px;
  background: var(--sel); color: var(--text-2); font-size: 12.5px;
}
.live-line .link-btn { padding: 0; font-size: 12.5px; flex: none; }
.live-line .link-btn[disabled] { opacity: 0.4; cursor: default; }
.live-line.has-error { color: var(--red); background: color-mix(in srgb, var(--red) 10%, transparent); }
p.live-line.muted { justify-content: flex-start; flex-wrap: wrap; gap: 4px; }
