/* Control Tower: minimalist, Apple-inspired design system. */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.16);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, 0.1);
  --green: #1d8a3a;
  --green-soft: rgba(52, 199, 89, 0.15);
  --orange: #b25000;
  --orange-soft: rgba(255, 159, 10, 0.16);
  --red: #d70015;
  --red-soft: rgba(255, 59, 48, 0.12);
  --purple: #8944ab;
  --purple-soft: rgba(175, 82, 222, 0.13);
  --gray-soft: rgba(0, 0, 0, 0.055);
  --nav-bg: rgba(251, 251, 253, 0.78);
  --input-bg: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 24px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.18);
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI Variable Text", "Segoe UI",
    Inter, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #161617;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --faint: #86868b;
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.18);
    --accent: #2997ff;
    --accent-hover: #47a6ff;
    --accent-soft: rgba(41, 151, 255, 0.16);
    --green: #30d158;
    --green-soft: rgba(48, 209, 88, 0.16);
    --orange: #ffb340;
    --orange-soft: rgba(255, 159, 10, 0.18);
    --red: #ff6961;
    --red-soft: rgba(255, 69, 58, 0.18);
    --purple: #da8fff;
    --purple-soft: rgba(191, 90, 242, 0.2);
    --gray-soft: rgba(255, 255, 255, 0.08);
    --nav-bg: rgba(22, 22, 23, 0.78);
    --input-bg: #2c2c2e;
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.6);
    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.47 var(--font);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -0.022em; font-weight: 600; }
h1 { font-size: 32px; line-height: 1.12; }
h2 { font-size: 21px; line-height: 1.2; }
h3 { font-size: 17px; }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; }
.danger-text { color: var(--red); }
.ok-text { color: var(--green); }

/* ───── navigation ───── */
.nav {
  position: sticky; top: 0; z-index: 20;
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.nav-inner {
  max-width: 1180px; margin: 0 auto; height: 52px; padding: 0 20px;
  display: flex; align-items: center; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); font-weight: 600; font-size: 16px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px; flex: none;
  background: linear-gradient(145deg, #2997ff, #0071e3 55%, #5e5ce6);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}
.brand-mark.lg { width: 52px; height: 52px; border-radius: 15px; margin: 0 auto 18px; }
.nav-links { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a, .nav-right a {
  color: var(--muted); font-size: 14px; padding: 6px 12px; border-radius: 980px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.nav-links a:hover, .nav-right a:hover { color: var(--text); text-decoration: none; }
.nav-links a.active, .nav-right a.active { color: var(--text); background: var(--gray-soft); }
.nav-right { display: flex; align-items: center; gap: 6px; }
.nav-right svg { width: 18px; height: 18px; }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 600; line-height: 18px; text-align: center;
}

/* ───── layout ───── */
.view { max-width: 1180px; margin: 0 auto; padding: 36px 20px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 6px; }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; margin-bottom: 14px; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.row-flex { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 20px; }
.grid.tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.grid.halves { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.grid.form-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid.form-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .grid.tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.halves { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  h1 { font-size: 26px; }
  .view { padding: 24px 16px 64px; }
  .nav-inner { padding: 0 16px; gap: 14px; }
  .grid.form-2, .grid.form-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .brand span.brand-text { display: none; }
}

/* ───── surfaces ───── */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 24px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card.flush .card-head { padding: 20px 24px 0; }
.card-head .hint { color: var(--muted); font-size: 13px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 8px 0 10px; }

.tile {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; display: block; color: inherit; transition: transform 0.15s ease;
}
.tile:hover { text-decoration: none; transform: translateY(-1px); }
.tile .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.tile .value { font-size: 40px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; margin-top: 6px; }
.tile .foot { font-size: 13px; color: var(--muted); margin-top: 4px; min-height: 18px; }

.banner {
  border-radius: var(--radius-sm); padding: 12px 16px; font-size: 14px;
  background: var(--accent-soft); color: var(--text); display: flex; gap: 10px; align-items: flex-start;
}
.banner.warn { background: var(--orange-soft); }
.banner.error { background: var(--red-soft); }
.banner.ok { background: var(--green-soft); }

/* ───── lists ───── */
.list { list-style: none; margin: 0; padding: 0; }
.list-row {
  display: grid; align-items: center; gap: 14px; padding: 14px 24px;
  border-top: 1px solid var(--line); color: inherit;
}
.list-row:first-child { border-top: 0; }
a.list-row:hover, .list-row.clickable:hover { background: var(--surface-2); text-decoration: none; cursor: pointer; }
.list-row .title { font-weight: 500; }
.list-row .meta { color: var(--muted); font-size: 13px; }
.orders-row { grid-template-columns: 28px minmax(120px, 1fr) minmax(140px, 1.2fr) minmax(0, 2fr) 110px 90px 130px; }
.orders-row.no-check { grid-template-columns: minmax(120px, 1fr) minmax(140px, 1.2fr) minmax(0, 2fr) 110px 90px 130px; }
.ship-row { grid-template-columns: minmax(110px, 0.9fr) minmax(140px, 1.2fr) minmax(0, 1.6fr) 130px 120px; }
.alert-row { grid-template-columns: 12px minmax(0, 1fr) auto; align-items: start; }
.card-row { grid-template-columns: 28px minmax(110px, 0.8fr) minmax(120px, 1fr) minmax(0, 2.4fr) 110px; }
.job-row { grid-template-columns: minmax(0, 2fr) 80px 110px 140px auto; }
.simple-row { grid-template-columns: minmax(0, 1fr) auto; }
.list-head { color: var(--faint); font-size: 12px; font-weight: 500; padding-top: 10px; padding-bottom: 10px; }
@media (max-width: 900px) {
  .orders-row, .orders-row.no-check, .ship-row, .card-row, .job-row { grid-template-columns: minmax(0, 1fr) auto; }
  .orders-row > .hide-sm, .ship-row > .hide-sm, .card-row > .hide-sm, .job-row > .hide-sm { display: none; }
  .list-head { display: none; }
  .list-row { padding: 14px 18px; }
}
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--faint); }
.dot.critical { background: var(--red); }
.dot.warning { background: #ff9f0a; }
.dot.info { background: var(--accent); }

.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.address { line-height: 1.55; }

/* ───── status pills ───── */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 980px;
  font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--gray-soft); color: var(--muted);
}
.pill.blue { background: var(--accent-soft); color: var(--accent); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.orange { background: var(--orange-soft); color: var(--orange); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.purple { background: var(--purple-soft); color: var(--purple); }
.gift { font-size: 14px; }

/* ───── controls ───── */
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-size: 14px; font-weight: 500;
  padding: 8px 18px; border-radius: 980px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--gray-soft); color: var(--text); transition: background 0.15s ease, opacity 0.15s ease; white-space: nowrap;
}
.btn:hover { background: var(--line-strong); text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.ghost { background: transparent; color: var(--accent); padding-left: 8px; padding-right: 8px; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.sm { padding: 5px 12px; font-size: 13px; }
.btn.lg { padding: 12px 24px; font-size: 16px; }
.btn.block { width: 100%; }
.btn[disabled], .btn.busy { opacity: 0.5; pointer-events: none; }
.btn.busy::after {
  content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
button.link { background: none; border: 0; padding: 6px 8px; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; }
button.link:hover { color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field .help { font-weight: 400; color: var(--faint); font-size: 12px; }
.input, select.input, textarea.input {
  width: 100%; font: inherit; font-size: 15px; color: var(--text); background: var(--input-bg);
  border: 1px solid var(--line-strong); border-radius: 10px; padding: 9px 12px; outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea.input { resize: vertical; min-height: 96px; line-height: 1.45; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.input.search { border-radius: 980px; padding-left: 36px; min-width: 240px;
  background: var(--input-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 3.5 3.5'/%3E%3C/svg%3E") no-repeat 13px center; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text); font-weight: 400; cursor: pointer; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; margin: 0; }
input[type="radio"] { accent-color: var(--accent); }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.actions.left { justify-content: flex-start; }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--text); font-weight: 400; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 42px; height: 26px; border-radius: 13px; background: var(--line-strong); position: relative; transition: background 0.2s ease; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); transition: transform 0.2s ease; }
.switch input:checked + .track { background: #34c759; }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 4px var(--accent-soft); }

/* segmented control */
.seg { display: inline-flex; background: var(--gray-soft); border-radius: 10px; padding: 3px; gap: 2px; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg a, .seg button {
  border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 500; color: var(--text);
  padding: 6px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.seg a:hover, .seg button:hover { text-decoration: none; }
.seg .on { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg .count { color: var(--muted); font-weight: 400; margin-left: 4px; }

/* rates */
.rates { display: flex; flex-direction: column; gap: 8px; }
.rate {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer;
}
.rate:hover { background: var(--surface-2); }
.rate.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rate .price { font-weight: 600; font-size: 16px; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--line); margin-left: 4px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--line-strong);
}
.timeline li:first-child::before { border-color: var(--accent); background: var(--accent); }
.timeline .when { color: var(--faint); font-size: 12px; }

.message-preview {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-style: italic; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; padding-top: 0; }
.variations { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* empty & loading */
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 8px; }
.loading { display: flex; justify-content: center; padding: 80px 0; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.bulkbar {
  position: sticky; bottom: 20px; margin-top: 20px; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--nav-bg); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 12px 22px; box-shadow: var(--shadow-lg);
}

/* auth */
.auth-wrap { min-height: calc(100vh - 120px); display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 380px; text-align: center; display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { font-size: 28px; }
.auth-card .field { text-align: left; }
.error { color: var(--red); font-size: 14px; }

/* dialog */
dialog.modal {
  border: 0; padding: 0; border-radius: 20px; background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.32); backdrop-filter: blur(4px); }
dialog .modal-body { padding: 24px; }
dialog .modal-body h2 { margin-bottom: 10px; }

/* toasts */
.toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; width: calc(100vw - 32px); pointer-events: none; }
.toast {
  background: rgba(29, 29, 31, 0.92); color: #fff; padding: 10px 18px; border-radius: 980px; font-size: 14px;
  box-shadow: var(--shadow-lg); animation: toast-in 0.25s ease; max-width: 560px; text-align: center; pointer-events: auto;
}
.toast.error { background: #d70015; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.copy-field { display: flex; gap: 8px; }
.copy-field .input { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.steps li { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.steps .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-strong); flex: none; display: grid; place-items: center; font-size: 12px; }
.steps .done .tick { background: #34c759; border-color: #34c759; color: #fff; }
.steps .done span.txt { color: var(--muted); text-decoration: line-through; }
.template-list .list-row { grid-template-columns: minmax(0, 1fr) auto; }
.template-list .list-row.on { background: var(--accent-soft); }
