:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #131722;
  --border: #232a3a;
  --text: #e7ecf3;
  --muted: #8693aa;
  --accent: #4cc9f0;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --tap: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "PingFang SC",
               "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ─── boot splash ─────────────────────────────────────── */
.boot {
  display: flex; align-items: center; justify-content: center;
  flex: 1; font-size: 24px; color: var(--muted);
}

/* ─── topbar ──────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.brand {
  font-weight: 600; font-size: 18px;
  color: var(--text); text-decoration: none; letter-spacing: 0.02em;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.pending {
  display: inline-block; min-width: 28px; padding: 4px 10px;
  background: #1d2434; border: 1px solid var(--border); border-radius: 999px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px;
  text-align: center;
  transition: all 0.2s;
}
.pending[data-state="idle"]    { color: var(--muted); }
.pending[data-state="pending"] { color: var(--warn); border-color: #4a3a1a; background: #1f1c10; }

/* ─── main ────────────────────────────────────────────── */
.main {
  flex: 1; padding: 14px; overflow-y: auto;
}

/* ─── footer ──────────────────────────────────────────── */
.footer {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border-top: 1px solid var(--border);
  background: var(--panel);
  font-size: 12px; color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.footer .dot { color: var(--border); }
.footer .worker-name { color: var(--text); }

/* ─── home ────────────────────────────────────────────── */
.home-title { margin: 8px 4px 0; font-size: 20px; }
.home-sub { margin: 0 4px 16px; color: var(--muted); font-size: 14px; }
.cards { display: flex; flex-direction: column; gap: 12px; }
.card {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  text-decoration: none; color: var(--text);
  min-height: var(--tap);
  transition: transform 0.05s, background 0.15s, border-color 0.15s;
}
.card:active { transform: scale(0.985); background: #181d2a; }
.card-icon { font-size: 36px; line-height: 1; min-width: 44px; text-align: center; }
.card-body { flex: 1; min-width: 0; }
.card-en { font-size: 18px; font-weight: 600; }
.card-zh { font-size: 14px; color: var(--accent); margin-top: 2px; }
.card-desc { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card-chevron { color: var(--muted); font-size: 24px; line-height: 1; }

/* ─── placeholder views ───────────────────────────────── */
.placeholder {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 36px 16px; gap: 8px;
}
.placeholder-icon { font-size: 64px; line-height: 1; margin-bottom: 8px; }
.placeholder h2 { margin: 0; font-size: 22px; }
.placeholder .zh { margin: 0; color: var(--accent); font-size: 16px; }
.placeholder .note { color: var(--muted); font-size: 13px; margin-top: 16px; }
.btn-back {
  display: inline-block; margin-top: 24px;
  padding: 12px 20px; background: #1d2434; border: 1px solid var(--border);
  border-radius: 999px; color: var(--text); text-decoration: none;
  min-height: var(--tap); display: inline-flex; align-items: center;
}
.btn-back:active { background: #283045; }

/* ─── setup needed ────────────────────────────────────── */
.setup-needed {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 24px; min-height: 100dvh; text-align: center; gap: 14px;
}
.setup-needed h1 { margin: 0; font-size: 28px; }
.setup-needed p { margin: 0; max-width: 30ch; color: var(--text); }
.setup-needed .muted { color: var(--muted); font-size: 13px; }

/* ─── CNC station ─────────────────────────────────────── */
.cnc { display: flex; flex-direction: column; gap: 14px; }
.cnc-head { text-align: center; padding: 4px 0 0; }
.cnc-head h2 { margin: 0; font-size: 22px; }
.cnc-head .zh { margin: 2px 0 0; color: var(--accent); font-size: 14px; }

.cnc-indicator {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 36px 16px;
  border: 2px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  text-align: center;
  transition: background 0.2s, border-color 0.2s, transform 0.05s;
}
.cnc-indicator-glyph {
  font-size: 80px; line-height: 1; margin-bottom: 16px;
  filter: grayscale(0.4); transition: filter 0.2s, transform 0.15s;
}
.cnc-indicator-text { font-size: 14px; color: var(--muted); line-height: 1.5; }
.cnc-indicator-text .zh { color: var(--accent); }

.cnc-indicator[data-state="success"] {
  background: #14302a; border-color: var(--good);
}
.cnc-indicator[data-state="success"] .cnc-indicator-glyph {
  filter: none; transform: scale(1.08);
}
.cnc-indicator[data-state="success"] .cnc-indicator-text {
  color: var(--good);
}

.cnc-indicator[data-state="error"] {
  background: #2e1716; border-color: var(--bad);
}
.cnc-indicator[data-state="error"] .cnc-indicator-glyph {
  filter: none;
}
.cnc-indicator[data-state="error"] .cnc-indicator-text {
  color: var(--bad);
}

.cnc-recent { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.cnc-recent-head { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.cnc-recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cnc-recent-empty { color: var(--muted); font-size: 13px; padding: 4px 0; font-style: italic; }
.cnc-recent-item {
  display: grid;
  grid-template-columns: 24px 80px 1fr;
  align-items: center; gap: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.cnc-recent-item:last-child { border-bottom: 0; }
.cnc-recent-icon { font-size: 16px; text-align: center; }
.cnc-recent-item[data-status="pending"]   .cnc-recent-icon { color: var(--warn); }
.cnc-recent-item[data-status="confirmed"] .cnc-recent-icon { color: var(--good); }
.cnc-recent-time { color: var(--muted); font-size: 12px; }
.cnc-recent-code { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── pallet packing ──────────────────────────────────── */
.pallet { display: flex; flex-direction: column; gap: 14px; }
.pallet-head { text-align: center; padding: 4px 0 0; }
.pallet-head h2 { margin: 0; font-size: 22px; }
.pallet-head .zh { margin: 2px 0 0; color: var(--accent); font-size: 14px; }

.pallet-meta {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
}
.pallet-meta-id {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 18px; font-weight: 600; color: var(--accent);
  word-break: break-all; max-width: 65%;
}
.pallet-meta-stats { display: flex; align-items: baseline; gap: 6px; }
.pallet-meta-count { font-size: 32px; font-weight: 600; color: var(--text); font-family: ui-monospace, monospace; }
.pallet-meta-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.pallet-actions {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
}
.pallet-actions button {
  min-height: var(--tap);
  font-size: 14px; font-weight: 500;
  border-radius: 12px;
  padding: 10px 8px;
  cursor: pointer;
}
.btn-primary {
  background: #14302a; color: var(--good); border: 1px solid var(--good);
}
.btn-primary:active { background: #1a4538; }
.btn-secondary {
  background: #1d2434; color: var(--text); border: 1px solid var(--border);
}
.btn-secondary:active { background: #283045; }
.btn-secondary[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn-danger {
  background: #2e1716; color: var(--bad); border: 1px solid var(--bad);
}
.btn-danger:active { background: #3d1d1c; }

.pallet-resume {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 16px;
  display: flex; flex-direction: column; gap: 16px;
}
.pallet-resume-msg { font-size: 15px; line-height: 1.5; text-align: center; }
.pallet-resume-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pallet-resume-actions button { min-height: var(--tap); font-size: 14px; border-radius: 12px; }

.cnc-recent-item[data-status="removed"] {
  opacity: 0.5;
  text-decoration: line-through;
}
.cnc-recent-item[data-status="removed"] .cnc-recent-icon { color: var(--muted); }

/* ─── shared utility ──────────────────────────────────── */
.muted { color: var(--muted); }
button, .btn-back, .card { -webkit-tap-highlight-color: transparent; }
