/* Flying Posts: shared design system and app shell */

:root {
  color-scheme: dark;
  --bg: #0d0f12;
  --bg-elev: #111419;
  --surface: #161a20;
  --surface-2: #1d222a;
  --surface-3: #252b35;
  --border: #272d37;
  --border-strong: #353c48;
  --text: #eceef1;
  --text-muted: #8b93a1;
  --text-faint: #5f6774;
  --primary: #c6f432;
  --primary-hover: #d4ff4a;
  --primary-contrast: #0d0f12;
  --primary-soft: rgba(198, 244, 50, 0.12);
  --primary-ring: rgba(198, 244, 50, 0.35);
  --danger: #ff5c5c;
  --danger-soft: rgba(255, 92, 92, 0.13);
  --success: #3ddc97;
  --success-soft: rgba(61, 220, 151, 0.13);
  --warning: #ffb547;
  --warning-soft: rgba(255, 181, 71, 0.14);
  --info: #7c9cff;
  --info-soft: rgba(124, 156, 255, 0.14);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 12px 32px -12px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 24px 64px -16px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --font: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Inter Tight", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --sidebar-w: 248px;
  --topbar-h: 64px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --grain: radial-gradient(1200px 600px at 10% -10%, rgba(198, 244, 50, 0.05), transparent 60%);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f4f0;
    --bg-elev: #fafaf7;
    --surface: #ffffff;
    --surface-2: #f1f1ec;
    --surface-3: #e7e7e0;
    --border: #e2e2db;
    --border-strong: #cfcfc6;
    --text: #15171b;
    --text-muted: #636a75;
    --text-faint: #9399a3;
    --primary: #4f6b00;
    --primary-hover: #435c00;
    --primary-contrast: #ffffff;
    --primary-soft: rgba(110, 150, 0, 0.12);
    --primary-ring: rgba(110, 150, 0, 0.35);
    --danger: #d92d2d;
    --danger-soft: rgba(217, 45, 45, 0.1);
    --success: #12935b;
    --success-soft: rgba(18, 147, 91, 0.1);
    --warning: #b86e00;
    --warning-soft: rgba(184, 110, 0, 0.12);
    --info: #3b5bdb;
    --info-soft: rgba(59, 91, 219, 0.1);
    --shadow: 0 1px 2px rgba(20, 22, 26, 0.04), 0 8px 24px -12px rgba(20, 22, 26, 0.14);
    --shadow-lg: 0 24px 64px -16px rgba(20, 22, 26, 0.25), 0 0 0 1px rgba(20, 22, 26, 0.05);
    --grain: radial-gradient(1200px 600px at 10% -10%, rgba(140, 190, 0, 0.08), transparent 60%);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4f0;
  --bg-elev: #fafaf7;
  --surface: #ffffff;
  --surface-2: #f1f1ec;
  --surface-3: #e7e7e0;
  --border: #e2e2db;
  --border-strong: #cfcfc6;
  --text: #15171b;
  --text-muted: #636a75;
  --text-faint: #9399a3;
  --primary: #4f6b00;
  --primary-hover: #435c00;
  --primary-contrast: #ffffff;
  --primary-soft: rgba(110, 150, 0, 0.12);
  --primary-ring: rgba(110, 150, 0, 0.35);
  --danger: #d92d2d;
  --danger-soft: rgba(217, 45, 45, 0.1);
  --success: #12935b;
  --success-soft: rgba(18, 147, 91, 0.1);
  --warning: #b86e00;
  --warning-soft: rgba(184, 110, 0, 0.12);
  --info: #3b5bdb;
  --info-soft: rgba(59, 91, 219, 0.1);
  --shadow: 0 1px 2px rgba(20, 22, 26, 0.04), 0 8px 24px -12px rgba(20, 22, 26, 0.14);
  --shadow-lg: 0 24px 64px -16px rgba(20, 22, 26, 0.25), 0 0 0 1px rgba(20, 22, 26, 0.05);
  --grain: radial-gradient(1200px 600px at 10% -10%, rgba(140, 190, 0, 0.08), transparent 60%);
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  background-image: var(--grain);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01", "tnum" 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
html.has-overlay body { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img, video { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); letter-spacing: -0.015em; line-height: 1.2; font-weight: 650; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
::selection { background: var(--primary); color: var(--primary-contrast); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
button { font: inherit; color: inherit; }
.icon { flex: 0 0 auto; display: inline-block; vertical-align: middle; }

* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- utilities ---------- */

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.spacer { flex: 1 1 auto; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); } }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.title { font-family: var(--font-display); font-size: 18px; font-weight: 650; letter-spacing: -0.02em; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.hidden { display: none !important; }
.scroll-y { overflow-y: auto; overscroll-behavior: contain; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  font: 600 11px/1 var(--font-mono);
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
}

/* ---------- buttons ---------- */

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-bd: var(--border);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  font: 550 13.5px/1 var(--font);
  letter-spacing: -0.005em;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-bd);
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.08s var(--ease), box-shadow 0.15s var(--ease);
  text-decoration: none !important;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { --btn-bg: var(--primary); --btn-fg: var(--primary-contrast); --btn-bd: transparent; font-weight: 650; box-shadow: 0 0 0 0 var(--primary-ring); }
.btn-primary:hover { background: var(--primary-hover); border-color: transparent; box-shadow: 0 6px 20px -8px var(--primary-ring); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-danger { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); --btn-bd: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; gap: 5px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 14.5px; border-radius: 12px; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-block { width: 100%; }
.btn.is-busy { color: transparent !important; pointer-events: none; }
.btn.is-busy > * { visibility: hidden; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; left: 50%; top: 50%; margin: -8px 0 0 -8px;
  border: 2px solid var(--btn-fg); border-right-color: transparent; border-radius: 50%;
  animation: fp-spin 0.7s linear infinite;
}
.btn-primary.is-busy::after { border-color: var(--primary-contrast); border-right-color: transparent; }

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-title {
  display: flex; align-items: center; gap: 8px;
  font: 600 13px/1.3 var(--font);
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.card-title .spacer + * { text-transform: none; letter-spacing: 0; }

.page-header {
  display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px;
  margin-bottom: 20px;
}
.page-header h1, .page-header h2 { font-size: 26px; letter-spacing: -0.03em; }
.page-header .muted { margin-top: 4px; }

/* ---------- forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); letter-spacing: 0.01em; }
.field-hint { font-size: 12px; color: var(--text-faint); }
.input, .select, .textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  font: 400 14px/1.4 var(--font);
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: var(--surface); }
.input:disabled, .select:disabled, .textarea:disabled { opacity: 0.6; cursor: not-allowed; }
.input-lg { min-height: 46px; font-size: 16px; padding: 10px 14px; border-radius: 12px; }
.textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b93a1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}
.select-sm, .input-sm { min-height: 30px; padding-top: 4px; padding-bottom: 4px; font-size: 13px; border-radius: 8px; }
.select option { background: var(--surface); color: var(--text); }
input[type="color"].input { padding: 4px; height: 38px; cursor: pointer; }
input[type="datetime-local"].input, input[type="date"].input, input[type="time"].input { font-variant-numeric: tabular-nums; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13.5px; }
.checkbox input, input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; cursor: pointer; }

/* ---------- pills, badges, statuses ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px;
  font: 600 12px/1 var(--font);
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  font: 700 11px/1 var(--font);
  color: var(--primary-contrast);
  background: var(--primary);
  border-radius: 999px;
}
.status { --st: var(--text-muted); --st-bg: var(--surface-2); color: var(--st); background: var(--st-bg); border-color: transparent; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.status-idea { --st: #c39bff; --st-bg: rgba(195, 155, 255, 0.13); }
.status-draft, .status-pending, .status-manual { --st: var(--text-muted); --st-bg: var(--surface-2); }
.status-ready { --st: var(--info); --st-bg: var(--info-soft); }
.status-scheduled { --st: var(--primary); --st-bg: var(--primary-soft); }
.status-publishing { --st: var(--info); --st-bg: var(--info-soft); }
.status-publishing .status-dot { animation: fp-pulse 1.1s ease-in-out infinite; }
.status-published, .status-manual_done, .status-active { --st: var(--success); --st-bg: var(--success-soft); }
.status-failed, .status-needs_reauth, .status-expired { --st: var(--danger); --st-bg: var(--danger-soft); }
.status-needs_manual { --st: var(--warning); --st-bg: var(--warning-soft); }
.status-disconnected { --st: var(--text-faint); --st-bg: var(--surface-2); }

.pbadge {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 22px; min-width: 22px; padding: 0 6px;
  font: 800 10px/1 var(--font);
  letter-spacing: 0.04em;
  color: var(--pc-text, #fff);
  background: var(--pc, #6b7280);
  border-radius: 6px;
  flex: 0 0 auto;
}
.pbadge-threads { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22); }
.pbadge-sm { height: 18px; min-width: 18px; padding: 0 4px; font-size: 9px; border-radius: 5px; }
.pbadge-lg { height: 28px; min-width: 28px; padding: 0 8px; font-size: 11.5px; border-radius: 8px; }
.pbadge-label { font-weight: 600; letter-spacing: 0; font-size: 11.5px; }

/* ---------- table ---------- */

.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th {
  text-align: left; font: 600 11.5px/1.2 var(--font); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num, .table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

/* ---------- tabs ---------- */

.tabs {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  font: 550 13px/1 var(--font);
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--border); }
.tab-count { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* ---------- empty, spinner ---------- */

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 8px; padding: 40px 20px;
  color: var(--text-muted);
}
.empty-icon {
  display: grid; place-items: center;
  width: 54px; height: 54px; margin-bottom: 6px;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 16px;
  transform: rotate(-4deg);
}
.empty-title { font: 650 16px/1.3 var(--font-display); color: var(--text); letter-spacing: -0.01em; }
.empty-text { max-width: 420px; font-size: 13.5px; }
.empty-action { margin-top: 10px; }

.spinner-wrap { display: flex; align-items: center; justify-content: center; padding: 40px; }
.spinner {
  display: inline-block; width: 22px; height: 22px;
  border: 2.5px solid var(--surface-3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: fp-spin 0.75s linear infinite;
}
@keyframes fp-spin { to { transform: rotate(360deg); } }
@keyframes fp-pulse { 50% { opacity: 0.3; } }
@keyframes fp-fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.boot-splash { min-height: 100vh; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; }
.boot-error { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.boot-error .card { max-width: 480px; width: 100%; }

/* ---------- overlays: modal and drawer ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(5, 6, 8, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.18s var(--ease);
}
.overlay.is-open { opacity: 1; }
.overlay.is-leaving { opacity: 0; }

.modal-backdrop { display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal {
  width: 520px; max-width: 100%; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateY(10px) scale(0.98);
  transition: transform 0.2s var(--ease);
  outline: none;
}
.overlay.is-open .modal { transform: none; }
.modal-header { display: flex; align-items: center; gap: 12px; padding: 18px 20px 6px; }
.modal-title { flex: 1; font-size: 17px; }
.modal-body { padding: 12px 20px 20px; overflow-y: auto; }
.modal-text { color: var(--text-muted); line-height: 1.55; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--bg-elev); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

.drawer-backdrop { display: flex; justify-content: flex-end; }
.drawer {
  width: 560px; max-width: 100vw; height: 100%;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.26s var(--ease);
  outline: none;
}
.overlay.is-open .drawer { transform: none; }
.overlay.is-leaving .drawer { transform: translateX(100%); }
.drawer-header { display: flex; align-items: center; gap: 12px; height: var(--topbar-h); padding: 0 16px 0 22px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.drawer-title { flex: 1; font-size: 17px; display: flex; align-items: center; gap: 10px; min-width: 0; }
.drawer-body { flex: 1 1 auto; padding: 20px 22px; min-height: 0; }

/* ---------- toasts ---------- */

.toast-host {
  position: fixed; z-index: 2000; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 260px; max-width: 420px;
  padding: 11px 10px 11px 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  animation: fp-fade-up 0.22s var(--ease);
  transition: opacity 0.2s, transform 0.2s;
}
.toast-out { opacity: 0; transform: translateX(12px); }
.toast-icon { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 7px; flex: 0 0 auto; color: var(--info); background: var(--info-soft); }
.toast-success .toast-icon { color: var(--success); background: var(--success-soft); }
.toast-error .toast-icon { color: var(--danger); background: var(--danger-soft); }
.toast-error { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.toast-msg { flex: 1; font-size: 13.5px; line-height: 1.45; padding-top: 1px; word-break: break-word; }
.toast-close { background: none; border: 0; color: var(--text-faint); cursor: pointer; padding: 3px; border-radius: 6px; display: grid; place-items: center; }
.toast-close:hover { color: var(--text); background: var(--surface-3); }

/* ---------- app shell ---------- */

.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
  position: sticky; top: 0;
  width: var(--sidebar-w); height: 100vh; flex: 0 0 var(--sidebar-w);
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px 14px 14px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  z-index: 50;
}
.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.app-logo { display: inline-flex; align-items: center; gap: 10px; padding: 4px 8px 14px; color: var(--text); text-decoration: none !important; }
.app-logo-mark {
  display: grid; place-items: center; width: 32px; height: 32px;
  color: var(--primary-contrast); background: var(--primary);
  border-radius: 10px;
  transform: rotate(-8deg);
  box-shadow: 0 8px 22px -10px var(--primary-ring);
  transition: transform 0.3s var(--ease);
}
.app-logo:hover .app-logo-mark { transform: rotate(0deg) translateX(2px) translateY(-2px); }
.app-logo-word { font: 750 17px/1 var(--font-display); letter-spacing: -0.035em; }
.app-logo-word em { font-style: italic; font-weight: 800; color: var(--primary); margin-left: 3px; }

.brand-switcher { position: relative; margin-bottom: 10px; }
.brand-trigger {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 8px 8px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.brand-trigger:hover { border-color: var(--border-strong); background: var(--surface-2); }
.brand-trigger > .icon { color: var(--text-faint); }
.brand-trigger-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.brand-trigger-label { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); }
.brand-trigger-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-avatar {
  display: grid; place-items: center; flex: 0 0 auto;
  width: 30px; height: 30px; border-radius: 9px;
  font: 800 11.5px/1 var(--font-display); letter-spacing: 0.02em;
}
.brand-avatar-all { color: var(--text-muted); background: var(--surface-3); }
.brand-avatar-lg { width: 48px; height: 48px; border-radius: 14px; font-size: 16px; }
.brand-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.brand-dot-all { background: conic-gradient(#c6f432, #7c9cff, #ff7a59, #38d9a9, #c6f432); }
.brand-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 60;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-height: 60vh; overflow-y: auto;
  animation: fp-fade-up 0.16s var(--ease);
}
.brand-option {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: none; border: 0; border-radius: 8px;
  text-align: left; cursor: pointer; font-size: 13.5px;
}
.brand-option:hover { background: var(--surface-2); }
.brand-option.active { color: var(--primary); }
.brand-option-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.brand-manage { display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-top: 4px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-muted); }
.brand-manage:hover { color: var(--text); text-decoration: none; }

.nav-caption { padding: 8px 10px 4px; font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-faint); }
.app-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  height: 38px; padding: 0 10px;
  color: var(--text-muted);
  font-weight: 550;
  border-radius: 10px;
  text-decoration: none !important;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { color: var(--text); background: var(--surface-2); }
.nav-item.active::before {
  content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px;
  background: var(--primary); border-radius: 0 3px 3px 0;
}
.nav-item.active .nav-icon { color: var(--primary); }
.nav-icon { display: grid; place-items: center; }

.sidebar-help {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  font-size: 12.5px; color: var(--text-faint);
  background: none; border: 1px dashed var(--border); border-radius: 10px;
  cursor: pointer;
}
.sidebar-help span:nth-child(2) { flex: 1; text-align: left; }
.sidebar-help:hover { color: var(--text-muted); border-color: var(--border-strong); }

.app-topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  height: var(--topbar-h); padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 19px; letter-spacing: -0.03em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.topbar-new { margin-left: 6px; }
.topbar-brand-mobile { display: none; align-items: center; gap: 8px; }
.topbar-brand-mobile .select { width: auto; max-width: 150px; }

.notif-wrap { position: relative; }
.topbar-bell { position: relative; }
.bell-badge {
  position: absolute; top: 3px; right: 2px;
  min-width: 17px; height: 17px; padding: 0 4px;
  display: grid; place-items: center;
  font: 800 10px/1 var(--font);
  color: var(--primary-contrast); background: var(--primary);
  border: 2px solid var(--bg);
  border-radius: 999px;
}
.notif-panel {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 80;
  width: 380px; max-width: calc(100vw - 24px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: fp-fade-up 0.16s var(--ease);
}
.notif-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--border); }
.notif-list { max-height: min(460px, 70vh); }
.notif-item {
  position: relative;
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 10px 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread::before { content: ""; position: absolute; left: 6px; top: 20px; width: 5px; height: 5px; border-radius: 50%; background: var(--primary); }
.notif-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto; color: var(--text-muted); background: var(--surface-2); }
.notif-due_manual .notif-icon { color: var(--warning); background: var(--warning-soft); }
.notif-published .notif-icon { color: var(--success); background: var(--success-soft); }
.notif-failed .notif-icon { color: var(--danger); background: var(--danger-soft); }
.notif-token_expiring .notif-icon { color: var(--info); background: var(--info-soft); }
.notif-text { flex: 1; min-width: 0; }
.notif-title { font-weight: 600; font-size: 13.5px; }
.notif-item:not(.unread) .notif-title { color: var(--text-muted); font-weight: 500; }
.notif-body { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notif-time { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.notif-del { opacity: 0; transition: opacity 0.12s; }
.notif-item:hover .notif-del, .notif-del:focus-visible { opacity: 1; }
.notif-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 36px 16px; color: var(--text-muted); text-align: center; }
.notif-perm { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 11px; font-size: 12.5px; color: var(--primary); background: var(--primary-soft); border: 0; border-top: 1px solid var(--border); cursor: pointer; }

.app-view { flex: 1 1 auto; padding: 28px; outline: none; min-width: 0; }
.view { animation: fp-fade-up 0.28s var(--ease); max-width: 1480px; margin: 0 auto; }
.view-error { max-width: 560px; margin: 40px auto; }

.shortcut-list { display: flex; flex-direction: column; }
.shortcut-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.shortcut-row:last-child { border-bottom: 0; }
.shortcut-keys { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- onboarding ---------- */

.onboarding { position: relative; min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; overflow: hidden; }
.onb-glow {
  position: absolute; width: 900px; height: 900px; left: 50%; top: 50%; transform: translate(-60%, -60%);
  background: radial-gradient(closest-side, var(--primary-soft), transparent 70%);
  pointer-events: none; filter: blur(10px);
}
.onb-card {
  position: relative;
  width: 100%; max-width: 980px;
  display: grid; grid-template-columns: 1.05fr 1fr; gap: 0;
  padding: 0; overflow: hidden;
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  animation: fp-fade-up 0.4s var(--ease);
}
.onb-intro {
  display: flex; flex-direction: column; gap: 18px;
  padding: 36px;
  background:
    linear-gradient(160deg, var(--primary-soft), transparent 55%),
    repeating-linear-gradient(-35deg, transparent 0 22px, color-mix(in srgb, var(--border) 45%, transparent) 22px 23px),
    var(--bg-elev);
  border-right: 1px solid var(--border);
}
.onb-intro .app-logo { padding: 0; }
.onb-title { font-size: clamp(34px, 4.4vw, 50px); line-height: 1.02; letter-spacing: -0.045em; font-weight: 800; margin-top: 18px; }
.onb-points { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.onb-points li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.onb-points .icon { color: var(--primary); }
.onb-platforms { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 12px; }
.onb-formwrap { padding: 36px; display: flex; flex-direction: column; gap: 8px; }
.onb-step { font: 700 11px/1 var(--font); text-transform: uppercase; letter-spacing: 0.12em; color: var(--primary); }
.onb-form { margin-top: 14px; gap: 16px; }
.onb-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.onb-swatch {
  position: relative; width: 30px; height: 30px; padding: 0;
  border-radius: 9px; border: 2px solid transparent; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
  transition: transform 0.12s var(--ease);
}
.onb-swatch:hover { transform: translateY(-2px); }
.onb-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface) inset; }
.onb-swatch-custom { display: grid; place-items: center; background: var(--surface-2); color: var(--text-muted); overflow: hidden; }
.onb-color-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.onb-preview { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px dashed var(--border-strong); border-radius: 14px; }
.onb-preview-name { font: 650 15px/1.2 var(--font-display); }

/* ---------- responsive: bottom tab bar ---------- */

@media (max-width: 799px) {
  :root { --topbar-h: 56px; }
  .app-shell { display: block; }
  .app-sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0;
    width: auto; height: auto; flex: none;
    flex-direction: row; gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }
  .app-sidebar > .app-logo, .app-sidebar > .brand-switcher, .app-sidebar > .nav-caption, .app-sidebar > .spacer, .app-sidebar > .sidebar-help { display: none; }
  .app-nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav-item { flex: 1; flex-direction: column; justify-content: center; gap: 3px; height: 50px; padding: 0 2px; font-size: 10.5px; }
  .nav-item.active { background: transparent; }
  .nav-item.active::before { left: 30%; right: 30%; top: -7px; bottom: auto; width: auto; height: 3px; border-radius: 0 0 3px 3px; }
  .app-topbar { padding: 0 12px; gap: 8px; }
  .topbar-brand-mobile { display: inline-flex; }
  .topbar-title { display: none; }
  .topbar-new { width: 36px; padding: 0; margin-left: 2px; }
  .topbar-new-label { display: none; }
  .app-view { padding: 16px 14px calc(84px + env(safe-area-inset-bottom)); }
  .page-header h1, .page-header h2 { font-size: 22px; }
  .toast-host { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); align-items: stretch; }
  .toast { max-width: none; }
  .notif-panel { position: fixed; left: 12px; right: 12px; top: calc(var(--topbar-h) + 6px); width: auto; max-width: none; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { width: 100% !important; max-height: 92vh; border-radius: 20px 20px 0 0; }
  .modal-footer { border-radius: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .drawer { width: 100vw !important; }
  .card { padding: 16px; border-radius: 16px; }
  .onb-card { grid-template-columns: 1fr; }
  .onb-intro { border-right: 0; border-bottom: 1px solid var(--border); padding: 26px; }
  .onb-formwrap { padding: 26px; }
  .onb-points, .onb-platforms { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

@media print {
  .app-sidebar, .app-topbar, .toast-host { display: none !important; }
  .app-view { padding: 0; }
  body { background: #fff; color: #000; }
}
