/* Control Center: styles */
:root {
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --line: #E2E5EA;
  --line-soft: #EEF0F3;
  --text: #151A21;
  --text-2: #545E6B;
  --text-3: #66707C;
  --accent: #2563EB;
  --accent-ink: #1D4ED8;
  --accent-tint: #EEF3FF;
  --ok: #1F9D5B;   --ok-ink: #146C43;   --ok-tint: #E5F4EC;
  --warn: #E08A00; --warn-ink: #8F5300; --warn-tint: #FFF1DB;
  --bad: #D92D20;  --bad-ink: #B42318;  --bad-tint: #FDECEA;
  --idle: #98A2B3; --idle-ink: #545E6B; --idle-tint: #EEF0F3;
  --blue-tint: #E8EFFE;
  --radius: 16px;
  --radius-sm: 10px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Space Grotesk", Inter, system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-family: var(--font-display); font-size: 28px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
h2 { font-family: var(--font-display); font-size: 16px; font-weight: 600; }
h3 { font-size: 17px; font-weight: 600; line-height: 1.3; }
a { color: var(--accent-ink); }
code { font-family: var(--mono); font-size: 0.9em; background: var(--line-soft); padding: 1px 5px; border-radius: 5px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.offscreen { position: fixed; top: 0; left: -9999px; opacity: 0; }
.n { font-size: 13px; line-height: 18px; color: var(--text-2); }
.hint { font-size: 13px; line-height: 18px; color: var(--text-3); }
.err { color: var(--bad-ink); font-size: 14px; line-height: 20px; }

/* ---------- layout ---------- */
.shell { max-width: 1320px; margin: 0 auto; padding: 20px 24px 56px; display: flex; gap: 20px; align-items: flex-start; }
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.side {
  flex: 0 0 248px; position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 14px;
}
.brand { display: flex; flex-direction: column; gap: 2px; padding: 2px 6px; min-width: 0; }
.brand b { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.brand span { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  position: relative; /* keeps hidden screen-reader text inside the link */
  min-height: 44px; border-radius: var(--radius-sm); display: flex; align-items: center; gap: 10px;
  padding: 0 12px; color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--accent-tint); color: var(--accent-ink); font-weight: 600; }
.nav a svg { flex: none; }
.nav .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .count {
  min-width: 22px; height: 22px; border-radius: 11px; background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px;
}
.nav .muted { font-size: 12px; color: var(--text-3); }
.nav-label { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); padding: 10px 12px 4px; }
.side-foot { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line-soft); padding-top: 12px; }

/* ---------- buttons ---------- */
.btn {
  height: 44px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid #D5DAE1;
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
  text-decoration: none; flex: none;
}
.btn:hover { background: #F7F8FA; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent-ink); font-weight: 600; padding: 0 8px; }
.btn.ghost:hover { background: var(--accent-tint); }
.btn.icon { width: 44px; padding: 0; }
.btn.grow { flex: 1; }
.btn.add { border: 1.5px dashed #C9CFD8; background: transparent; color: var(--text-2); }
.btn.danger { color: var(--bad-ink); border-color: #F3C7C3; }
.btn.ghost.danger { border-color: transparent; }
.btn.keep { color: var(--ok-ink); }
.btn.drop { color: var(--bad-ink); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- chips and dots ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.chip.ok { color: var(--ok-ink); background: var(--ok-tint); }
.chip.warn { color: var(--warn-ink); background: var(--warn-tint); }
.chip.bad { color: var(--bad-ink); background: var(--bad-tint); }
.chip.idle { color: var(--idle-ink); background: var(--idle-tint); }
.chip.blue { color: var(--accent-ink); background: var(--blue-tint); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--idle); display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.blue { background: var(--accent); }
.dot.none { background: transparent; box-shadow: inset 0 0 0 1.5px #C2C8D0; }

/* ---------- banner ---------- */
.banner { background: #FFF8E6; border: 1px solid #F2D79B; color: #6B4A00; border-radius: 12px; padding: 10px 14px; font-size: 14px; line-height: 20px; }
.banner code { background: #FBEBC4; }

/* ---------- cards ---------- */
.card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card.bad { border-color: #F3C7C3; }
.card.empty { align-items: flex-start; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.card-head .who { font-weight: 600; }
.card-head .when { color: var(--text-3); }
.txt { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.card .txt > p { font-size: 14px; line-height: 20px; color: var(--text-2); }

/* home */
.home { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.feed { flex: 999 1 480px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.rail { flex: 1 1 290px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.hello { display: flex; flex-direction: column; gap: 4px; padding: 4px 2px 2px; }
.hello p { font-size: 15px; color: var(--text-2); }

/* rows: leads, people */
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }
.row .txt { flex: 1 1 200px; gap: 2px; }
.row .t { font-size: 14px; font-weight: 600; }
.row .t a { color: inherit; }
.row.decided .t { color: var(--text-3); }
.avatar { width: 36px; height: 36px; flex: none; border-radius: 50%; background: var(--blue-tint); color: var(--accent-ink); font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; }

/* thumbnails */
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { width: 92px; height: 54px; border-radius: 8px; background: #E9ECF1; display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--text-2); overflow: hidden; text-align: center; padding: 2px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.more { background: transparent; border: 1px dashed #C9CFD8; font-weight: 600; font-size: 12px; }

/* forms */
input, select, textarea {
  width: 100%; min-height: 44px; border: 1px solid #C9CFD8; border-radius: var(--radius-sm);
  background: #fff; padding: 10px 12px; font-size: 15px;
}
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent-tint); outline-offset: 0; }
.changes { display: flex; flex-direction: column; gap: 8px; }
.changes label { font-size: 13px; font-weight: 600; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form label, .modal label, .login label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.form label small, .modal label small { font-weight: 400; color: var(--text-3); }
.form .actions, .form .wide { grid-column: 1 / -1; }

/* rail */
.rail-card { gap: 8px; }
.qrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.qrow .qi { flex: none; display: flex; }
.qrow .txt { flex: 1; gap: 2px; }
.qrow .t { font-size: 14px; font-weight: 600; color: var(--text); text-decoration: none; }
.qrow .t:hover { text-decoration: underline; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding-top: 4px; }
.stats b { display: block; font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.stats span { font-size: 12px; line-height: 16px; color: var(--text-3); }
.weeks { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
.wk-title { font-size: 13px; font-weight: 600; }
.bars { display: flex; align-items: flex-end; gap: 10px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.bar .v { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.bar .b { width: 100%; border-radius: 6px 6px 2px 2px; background: var(--accent); display: block; }
.bar .l { font-size: 11px; color: var(--text-3); white-space: nowrap; }

/* page heads */
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: space-between; }
.page-head > div:first-child { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.page-head p { color: var(--text-2); font-size: 14px; }
.status-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; text-decoration: none; min-height: 44px; align-self: flex-start; }
.sec { font-size: 18px; margin-top: 8px; }

/* automation cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.auto { gap: 10px; }
.auto-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.auto-top h3 { font-size: 15px; }
.auto-top h3 a { color: var(--text); text-decoration: none; }
.auto-top h3 a:hover { text-decoration: underline; }
.auto .msg { font-size: 14px; line-height: 20px; color: var(--text-2); min-height: 20px; }
.auto .meta { font-size: 12px; color: var(--text-3); }
.msg { font-size: 14px; color: var(--text-2); }

/* factory lines */
.line-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.line { display: flex; flex-wrap: nowrap; align-items: stretch; gap: 4px; overflow-x: auto; padding-bottom: 2px; }
.stage { position: relative; flex: 1 1 0; min-width: 104px; border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--line); background: var(--surface); }
.stage .nm { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; }
.stage .nm svg { flex: none; }
.stage .nt { font-size: 12px; line-height: 16px; color: var(--text-3); }
.stage.done { background: #F1F8F4; border-color: #CDE8D7; }
.stage.done .nt { color: var(--ok-ink); }
.stage.you { background: #FFF6E6; border: 2px solid #E9B44C; padding: 9px; }
.stage.you .nt { color: var(--warn-ink); }
.stage.now { background: var(--accent-tint); border: 2px solid #9DB8F5; padding: 9px; }
.stage.now .nt { color: var(--accent-ink); }
.stage.wait .nm { color: var(--text-2); }
.chev { color: #9AA3AE; display: flex; align-items: center; flex: none; }
.chev svg { width: 12px; height: 12px; }
.crew { display: flex; flex-direction: column; gap: 8px; }
.crew-label { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }
.crew-list { display: flex; flex-wrap: wrap; gap: 8px; }
.crew-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 13px; }
.crew-chip span:last-child { color: var(--text-2); }

/* activity log */
.log { gap: 0; }
.card.log { padding-top: 6px; padding-bottom: 6px; }
.logrow { display: flex; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.logrow:first-child { border-top: 0; }
.logrow .time { width: 128px; flex: none; font-size: 12px; line-height: 20px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.logrow .txt { gap: 2px; }
.logrow .t { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.logrow .t a { color: var(--text); text-decoration: none; }
.logrow .t a:hover { text-decoration: underline; }
.metrics { font-size: 12px; color: var(--text-3); }
.filter select { width: auto; min-width: 220px; }

/* code and tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: 14px; font-weight: 500; }
.tab.on { background: var(--text); color: #fff; border-color: var(--text); }
.code {
  margin: 0; background: #0F1419; color: #E8EDF2; border-radius: 12px; padding: 14px 16px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; overflow: auto; max-height: 420px; white-space: pre;
}
.code code { background: none; padding: 0; color: inherit; font-size: inherit; }
.quiet-zone { border-style: dashed; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 25, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; z-index: 20; overflow-y: auto; }
.modal { width: 100%; max-width: 480px; background: #fff; border-radius: 18px; padding: 22px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(15, 20, 25, 0.25); }
.modal h2 { font-size: 20px; }

/* login and setup screens */
.center { min-height: 100vh; display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; padding: 24px 16px; }
.login { width: 100%; max-width: 440px; gap: 14px; }
.login .code { white-space: pre-wrap; word-break: break-all; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px);
  background: #151A21; color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; line-height: 20px;
  max-width: min(92vw, 520px); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  z-index: 30; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: #8A1C14; }

/* ---------- phone and small tablet ---------- */
@media (max-width: 860px) {
  .shell { flex-direction: column; align-items: stretch; padding: 12px 12px 48px; gap: 12px; }
  .side { position: static; max-height: none; width: 100%; flex: none; padding: 12px; gap: 10px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 6px; scrollbar-width: none; margin: 0 -4px; padding: 0 4px 2px; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: none; border: 1px solid var(--line); padding: 0 14px; }
  .nav .lbl { overflow: visible; }
  .nav-label { display: none; }
  .side-foot { flex-direction: row; border-top: 0; padding-top: 0; }
  .side-foot .btn { flex: 1; }
  h1 { font-size: 24px; }
  .card { padding: 16px; }
  .form { grid-template-columns: 1fr; }
  .logrow { flex-direction: column; gap: 2px; }
  .logrow .time { width: auto; }
  .filter, .filter select { width: 100%; }
}
@media (max-width: 640px) {
  .line { flex-direction: column; align-items: stretch; overflow: visible; }
  .stage { flex: none; min-width: 0; }
  .chev { transform: rotate(90deg); align-self: center; }
  .stats b { font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
