/* C-Spaceship admin. Desktop ≥ 1024: sidebar. Tablet and phone: top bar + bottom tab bar. */
:root {
  --bg: #0A0B10; --surface: #12141B; --surface-2: #181B25; --line: #1E2130; --line-strong: #2F3345;
  --text: #ECEDF2; --muted: #A3A9BD; --dim: #8F95A8; --accent: #FF3B3F; --accent-soft: rgba(255, 59, 63, .14);
  --ok: #56D69A; --warn: #F2B35B; --info: #7FA8FF;
  --radius: 14px; --sidebar: 248px; --tabbar: 64px;
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Unbounded', 'Arial Black', sans-serif; --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  color-scheme: dark; box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #0A0B10; } }
:root[data-theme="dark"] { --bg: #0A0B10; }
*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; border-radius: 8px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--dim); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 20px 14px; border-right: 1px solid var(--line); background: #0C0D13; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 20px; font-family: var(--mono); font-size: 13px; letter-spacing: .12em; }
.brand img { height: 30px; width: auto; }
.nav-item { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 10px; text-decoration: none; color: var(--muted); }
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.nav-item[aria-current="page"] svg { color: var(--accent); }
.nav-item .count { margin-left: auto; min-width: 22px; padding: 0 7px; border-radius: 999px; background: var(--accent); color: #0A0B10; font-size: 12px; font-weight: 600; text-align: center; }
.sidebar .me { margin-top: auto; padding: 14px 12px 4px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.main { min-width: 0; padding: 28px clamp(16px, 3vw, 40px) 60px; }
.topbar { display: none; }
.tabbar { display: none; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; font: 700 clamp(22px, 2.4vw, 28px) var(--display); letter-spacing: -.01em; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--line-strong); background: transparent; cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0A0B10; font-weight: 600; }
.btn.primary:hover { background: #FF5A5D; }
.btn.danger { color: #FF8A8C; border-color: rgba(255, 90, 93, .45); }
.btn.icon { width: 44px; padding: 0; }
.btn[disabled] { opacity: .55; cursor: default; }
.input, .select, .textarea { width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); }
.search { max-width: 320px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-size: 13px; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--dim); }
.field .error { font-size: 13px; color: #FF8A8C; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-bottom: 18px; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: transparent; cursor: pointer; font-size: 14px; color: var(--muted); }
.tab[aria-pressed="true"] { background: var(--text); color: #0A0B10; border-color: var(--text); font-weight: 600; }
.tab .n { margin-left: 6px; opacity: .7; }

/* ---------- Cards and lists ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card h2 { margin: 0 0 14px; font: 500 16px var(--display); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { padding: 18px 20px; }
.stat .v { font: 700 30px var(--display); }
.stat .l { color: var(--muted); font-size: 14px; }
.stat.accent .v { color: var(--accent); }
.two-col { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px 16px; padding: 14px 18px; border-bottom: 1px solid var(--line); text-decoration: none; min-height: 64px; }
.row:last-child { border-bottom: 0; }
a.row:hover, button.row:hover { background: var(--surface-2); }
button.row { width: 100%; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.row .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 13px; color: var(--dim); display: flex; gap: 6px 12px; flex-wrap: wrap; }
.row .right { display: flex; align-items: center; gap: 8px; }
.row svg { width: 20px; height: 20px; flex: none; }
.row .thumb { width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); object-fit: contain; flex: none; }
.row.with-thumb { grid-template-columns: 44px minmax(0, 1fr) auto; }
.pill { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.new, .pill.draft { background: rgba(127, 168, 255, .14); color: var(--info); }
.pill.contacted, .pill.scheduled { background: rgba(242, 179, 91, .14); color: var(--warn); }
.pill.proposal { background: var(--accent-soft); color: #FF8A8C; }
.pill.won, .pill.published { background: rgba(86, 214, 154, .14); color: var(--ok); }
.pill.lost, .pill.hidden { background: #1A1C24; color: var(--dim); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 14px; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.editor .side { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 16px; }
.title-input { font: 700 clamp(22px, 2.4vw, 30px) var(--display); background: transparent; border: 0; border-bottom: 1px solid var(--line-strong); border-radius: 0; padding: 8px 0; }
.md-toolbar { display: flex; gap: 4px; flex-wrap: wrap; padding: 6px; border: 1px solid var(--line-strong); border-bottom: 0; border-radius: 12px 12px 0 0; background: var(--surface-2); }
.md-toolbar .btn { min-height: 38px; height: 38px; padding: 0 10px; border: 0; border-radius: 8px; font-size: 14px; }
.md-toolbar .btn:hover { background: var(--surface); }
.md-body { border-radius: 0 0 12px 12px; min-height: 420px; font-family: var(--mono); font-size: 14px; }
.preview { min-height: 420px; padding: 20px 24px; border: 1px solid var(--line-strong); border-radius: 0 0 12px 12px; background: var(--surface); line-height: 1.75; }
.preview h2, .preview h3 { font-family: var(--display); font-weight: 500; }
.preview img { max-width: 100%; border-radius: 10px; }
.preview a { color: var(--accent); }
.cover-box { aspect-ratio: 16 / 10; border-radius: 12px; border: 1px dashed var(--line-strong); background: var(--surface-2); display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--dim); font-size: 14px; }
.cover-box img { width: 100%; height: 100%; object-fit: cover; }
.upload { position: relative; overflow: hidden; }
.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------- Sheet (modal on desktop, full screen on phone) ---------- */
.scrim { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .55); display: flex; justify-content: flex-end; }
.sheet { width: min(560px, 100%); height: 100%; background: var(--bg); border-left: 1px solid var(--line); display: flex; flex-direction: column; animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); padding-top: calc(16px + env(safe-area-inset-top, 0px)); }
.sheet header h2 { margin: 0; font: 500 18px var(--display); }
.sheet .body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; -webkit-overflow-scrolling: touch; }
.sheet footer { display: flex; gap: 10px; justify-content: space-between; padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth .card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 28px; }
.auth h1 { margin: 0; font: 700 22px var(--display); }
.form-msg { min-height: 20px; font-size: 14px; }
.form-msg.error { color: #FF8A8C; }
.form-msg.ok { color: var(--ok); }

/* ---------- Toast ---------- */
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; pointer-events: none; width: min(92vw, 420px); }
.toast { padding: 12px 16px; border-radius: 12px; background: #1C1F2B; border: 1px solid var(--line-strong); box-shadow: 0 10px 30px rgba(0, 0, 0, .4); font-size: 14px; }
.toast.error { border-color: rgba(255, 90, 93, .6); }

/* =========== Laptop 1024–1279 =========== */
@media (max-width: 1279px) {
  :root { --sidebar: 220px; }
  .editor { grid-template-columns: minmax(0, 1fr) 280px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* =========== Tablet 640–1023 =========== */
@media (max-width: 1023px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 40; display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 60px; padding: 0 16px; background: rgba(10, 11, 16, .92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
  .topbar .brand { padding: 0; }
  .topbar .brand img { height: 26px; }
  .main { padding: 20px 18px calc(var(--tabbar) + 32px + env(safe-area-inset-bottom, 0px)); }
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: calc(var(--tabbar) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px); background: rgba(12, 13, 19, .96); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
  .tabbar a, .tabbar button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--dim); text-decoration: none; background: none; border: 0; cursor: pointer; }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar [aria-current="page"] { color: var(--text); }
  .tabbar [aria-current="page"] svg { color: var(--accent); }
  .tabbar .count { position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: #0A0B10; font-size: 11px; font-weight: 600; line-height: 18px; }
  .editor { grid-template-columns: minmax(0, 1fr); }
  .editor .side { position: static; }
  .two-col { grid-template-columns: minmax(0, 1fr); }
  .sheet { width: min(620px, 100%); }
}

/* =========== Phone < 640 =========== */
@media (max-width: 639px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px 16px; }
  .stat .v { font-size: 24px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .search { max-width: none; flex: 1 1 100%; }
  .page-head .toolbar { width: 100%; }
  .page-head .toolbar .btn.primary { flex: 1; }
  .row { padding: 12px 14px; }
  .row .hide-sm { display: none; }
  .sheet { width: 100%; border-left: 0; }
  .scrim { background: var(--bg); }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 10px; }
  .md-body, .preview { min-height: 320px; }
}
