/* ==========================================================================
   Ad Panel — design system (FOUNDATION)
   Dark slate sidebar + light content. Zero external requests.
   ========================================================================== */

:root {
  --sidebar-bg: #0F172A;
  --sidebar-bg-2: #1E293B;
  --content-bg: #F1F5F9;
  --card-bg: #FFFFFF;
  --accent: #4F46E5;
  --accent-hover: #4338CA;
  --accent-soft: #EEF2FF;
  --success: #10B981;
  --success-soft: #ECFDF5;
  --danger: #EF4444;
  --danger-soft: #FEF2F2;
  --warning: #F59E0B;
  --warning-soft: #FFFBEB;
  --text: #0F172A;
  --text-2: #475569;
  --text-3: #94A3B8;
  --line: #E2E8F0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 8px 30px rgba(15, 23, 42, .18);
  --sidebar-w: 240px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--content-bg);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
code, pre { font-family: var(--mono); font-size: .86em; }
pre { overflow-x: auto; background: #0F172A; color: #E2E8F0; padding: 14px 16px; border-radius: var(--radius-sm); }
::selection { background: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ==========================================================================
   Shell: sidebar + main
   ========================================================================== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; align-self: flex-start;
  display: flex; flex-direction: column;
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  height: 100vh;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, #111C34 100%);
  color: #CBD5E1;
  padding: 18px 12px;
  gap: 8px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 18px;
  color: #fff; font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; min-width: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7C3AED);
  color: #fff; font-size: 15px;
  box-shadow: 0 4px 14px rgba(79, 70, 229, .45);
}
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #94A3B8; font-weight: 500;
  text-decoration: none;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-item:hover { background: rgba(148, 163, 184, .1); color: #E2E8F0; text-decoration: none; }
.nav-item.active {
  background: linear-gradient(90deg, rgba(79, 70, 229, .28), rgba(79, 70, 229, .12));
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-icon { width: 22px; text-align: center; font-size: 16px; }
.nav-label { flex: 1; white-space: nowrap; }
.badge {
  min-width: 20px; padding: 1px 7px;
  border-radius: 999px;
  background: var(--danger); color: #fff;
  font-size: .72rem; font-weight: 700; text-align: center;
}
.sidebar-footer { border-top: 1px solid rgba(148, 163, 184, .15); padding-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.user-pill { display: flex; align-items: center; gap: 10px; padding: 6px 10px; color: #CBD5E1; font-size: .88rem; }
.user-avatar {
  display: grid; place-items: center;
  width: 28px; height: 28px; min-width: 28px;
  border-radius: 50%;
  background: var(--sidebar-bg-2); color: #A5B4FC;
  font-weight: 700; font-size: .8rem;
  border: 1px solid rgba(148, 163, 184, .25);
}
.user-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-logout:hover { color: #FCA5A5; }
.nav-logout-form { margin: 0; }
button.nav-item { background: none; border: 0; width: 100%; font: inherit; cursor: pointer; text-align: left; }

.main {
  flex: 1; min-width: 0;
  padding: 28px 32px 60px;
  max-width: 1240px;
}

.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.page-sub { color: var(--text-3); margin: 0; font-size: .92rem; }
.page-head .spacer { flex: 1; }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(226, 232, 240, .8);
  padding: 22px;
  margin-bottom: 20px;
}
.card-title { margin-bottom: 2px; }
.card-sub { color: var(--text-3); font-size: .88rem; margin-bottom: 16px; }
.card + .card { margin-top: 0; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  font: inherit; font-weight: 600; font-size: .9rem;
  color: var(--text-2);
  background: #fff;
  border-color: var(--line);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: #F8FAFC; border-color: #CBD5E1; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 2px 10px rgba(79, 70, 229, .35);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; border-color: #DC2626; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: rgba(15, 23, 42, .06); border-color: transparent; }

.btn-sm { padding: 5px 10px; font-size: .82rem; border-radius: 7px; }
.btn-lg { padding: 12px 20px; font-size: 1rem; border-radius: 10px; }
.btn-block { display: flex; width: 100%; }

/* ==========================================================================
   Forms
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > label {
  font-size: .8rem; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .04em;
}
.field .hint { font-size: .8rem; color: var(--text-3); margin: 0; }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="url"], input[type="search"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
textarea { min-height: 110px; resize: vertical; font-family: var(--mono); font-size: .85rem; line-height: 1.55; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }

input[type="color"] {
  width: 42px; height: 38px; min-width: 42px;
  padding: 3px;
  border: 1px solid var(--line); border-radius: 9px;
  background: #fff; cursor: pointer;
}

/* color input + hex text pairing (synced by app.js) */
.color-pair { display: flex; gap: 8px; align-items: center; }
.color-pair input[type="text"] { font-family: var(--mono); text-transform: uppercase; }

/* Form grids */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 18px; }
.grid2 > .card, .grid3 > .card { margin-bottom: 20px; }

/* ==========================================================================
   iOS-style switches — <label class="switch"><input type="checkbox"><span></span> Text</label>
   ========================================================================== */
.switch {
  display: inline-flex; align-items: center; gap: 10px;
  cursor: pointer; font-weight: 500; user-select: none;
  padding: 4px 0;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch input + span {
  position: relative;
  width: 44px; height: 25px; min-width: 44px;
  border-radius: 999px;
  background: #CBD5E1;
  transition: background .2s;
  flex: 0 0 auto;
}
.switch input + span::after {
  content: "";
  position: absolute; top: 2.5px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .35);
  transition: transform .2s cubic-bezier(.4, 0, .2, 1);
}
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px rgba(79, 70, 229, .3); }
.switch input:disabled + span { opacity: .5; }
.switch.switch-accent input:checked + span { background: var(--accent); }

/* ==========================================================================
   Chips / status pills
   ========================================================================== */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2.5px 10px;
  border-radius: 999px;
  font-size: .74rem; font-weight: 700; letter-spacing: .02em;
  background: #E2E8F0; color: var(--text-2);
  white-space: nowrap; vertical-align: middle;
}
.chip-success { background: var(--success-soft); color: #047857; }
.chip-danger  { background: var(--danger-soft);  color: #B91C1C; }
.chip-warning { background: var(--warning-soft); color: #B45309; }
.chip-accent  { background: var(--accent-soft);  color: var(--accent); }
.chip-muted   { background: #F1F5F9; color: var(--text-3); }
.chip code { font-size: .95em; }

/* ==========================================================================
   Sticky save bar (inside forms)
   ========================================================================== */
.savebar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; justify-content: flex-end; align-items: center; gap: 10px;
  margin: 18px -22px -22px;
  padding: 13px 22px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
}
form > .savebar:only-child, .savebar:first-child { margin-top: 0; }
.savebar .savebar-note { margin-right: auto; color: var(--text-3); font-size: .84rem; }

/* Savebar used outside a .card (full-width tab forms) */
.tab-form > .savebar { margin: 18px 0 0; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); }

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs {
  position: sticky; top: 0; z-index: 30;
  display: flex; gap: 2px;
  overflow-x: auto;
  background: rgba(241, 245, 249, .92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 8px 0;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}
.tabs a, .tabs button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: none; background: none;
  border-radius: 9px;
  font: inherit; font-weight: 600; font-size: .9rem;
  color: var(--text-2);
  text-decoration: none; cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.tabs a:hover, .tabs button:hover { background: rgba(15, 23, 42, .06); color: var(--text); text-decoration: none; }
.tabs a.active, .tabs button.active {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 10px rgba(79, 70, 229, .35);
}

/* ==========================================================================
   Waterfall / repeatable drag rows
   ========================================================================== */
.wf-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.wf-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  background: #F8FAFC;
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: box-shadow .15s, border-color .15s, background .15s, opacity .15s;
}
.wf-row:hover { border-color: #CBD5E1; }
.wf-row select { max-width: 160px; }
.wf-row input, .wf-row select { background: #fff; }
.wf-row .wf-grow { flex: 1; min-width: 0; }

.drag-handle {
  cursor: grab;
  color: var(--text-3);
  font-size: 15px; line-height: 1;
  padding: 4px 2px;
  border-radius: 6px;
  user-select: none; touch-action: none;
  flex: 0 0 auto;
}
.drag-handle:hover { color: var(--text-2); background: rgba(15, 23, 42, .06); }
.drag-handle:active { cursor: grabbing; }

.wf-row.dragging {
  opacity: .55;
  border-style: dashed; border-color: var(--accent);
  background: var(--accent-soft);
}
.wf-row.drag-over, .wf-row.drop-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .18);
}
.wf-row .btn-remove { color: var(--danger); }

.sortable.drag-active { border-radius: 10px; outline: 2px dashed rgba(79, 70, 229, .35); outline-offset: 4px; }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3);
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid #EDF2F7; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #F8FAFC; }
td.actions, th.actions { text-align: right; white-space: nowrap; }
tr.unread { background: var(--accent-soft); }
tr.unread:hover { background: #E0E7FF; }
tr.unread td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

/* ==========================================================================
   Stats (dashboard header)
   ========================================================================== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--card-bg);
  border: 1px solid rgba(226, 232, 240, .8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat .stat-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stat .stat-label { color: var(--text-3); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat.stat-accent .stat-value { color: var(--accent); }
.stat.stat-danger .stat-value { color: var(--danger); }
.stat.stat-success .stat-value { color: var(--success); }

/* ==========================================================================
   Empty states
   ========================================================================== */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-3);
}
.empty .empty-emoji { font-size: 44px; display: block; margin-bottom: 10px; }
.empty .empty-title { font-weight: 700; color: var(--text-2); font-size: 1.05rem; margin-bottom: 4px; }
.empty p { margin: 0; font-size: .9rem; }

/* ==========================================================================
   Toasts
   ========================================================================== */
.toasts {
  position: fixed; top: 18px; right: 18px; z-index: 1000;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(92vw, 380px);
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px;
  background: #0F172A; color: #F1F5F9;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--accent);
  font-size: .9rem; font-weight: 500;
  opacity: 0; transform: translateX(24px);
  transition: opacity .25s, transform .25s;
  pointer-events: auto; cursor: pointer;
  word-break: break-word;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast .toast-icon { line-height: 1.35; }

/* ==========================================================================
   Login (dark gradient + centered card)
   ========================================================================== */
.auth-body {
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(79, 70, 229, .4), transparent 60%),
    radial-gradient(800px 500px at 100% 110%, rgba(124, 58, 237, .3), transparent 60%),
    linear-gradient(160deg, #0F172A 0%, #111C34 55%, #0B1120 100%);
  min-height: 100vh;
}
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
  padding: 36px 32px 30px;
  text-align: center;
}
.login-logo {
  display: grid; place-items: center;
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #7C3AED);
  color: #fff; font-size: 24px;
  box-shadow: 0 8px 24px rgba(79, 70, 229, .5);
}
.login-title { font-size: 1.35rem; margin-bottom: 2px; }
.login-sub { color: var(--text-3); font-size: .9rem; margin-bottom: 22px; }
.login-card form { text-align: left; }
.login-card .btn-block { margin-top: 6px; }

/* ==========================================================================
   Misc utilities
   ========================================================================== */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row .spacer, .flex-spacer { flex: 1; }
.muted { color: var(--text-3); }
.small { font-size: .84rem; }
.mono { font-family: var(--mono); font-size: .86em; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.divider { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
.section-label {
  font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); margin: 20px 0 10px;
}
.kbd {
  font-family: var(--mono); font-size: .78em;
  background: #F1F5F9; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px;
}
[data-copy], [data-copy-target] { cursor: pointer; }
.copy-url {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: .8rem;
  background: #F8FAFC; border: 1px dashed var(--line);
  border-radius: 8px; padding: 5px 10px;
  color: var(--text-2); max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.copy-url:hover { border-color: var(--accent); color: var(--accent); }

.img-preview {
  width: 64px; height: 64px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--line); background: #F8FAFC;
}
.img-preview-wide { width: 128px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: #F8FAFC; }

details.expand { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; background: #F8FAFC; }
details.expand summary { cursor: pointer; font-weight: 600; color: var(--text-2); font-size: .86rem; }
details.expand[open] { padding-bottom: 12px; }

/* Notification preview card (push page) */
.notif-preview {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 14px 16px; max-width: 420px;
}
.notif-preview .notif-app { font-size: .74rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.notif-preview .notif-title { font-weight: 700; }
.notif-preview .notif-body { color: var(--text-2); font-size: .9rem; white-space: pre-wrap; }
.notif-preview .notif-image { margin-top: 10px; border-radius: 10px; width: 100%; object-fit: cover; max-height: 180px; }
.notif-preview .notif-buttons { display: flex; gap: 14px; margin-top: 10px; }
.notif-preview .notif-buttons span { color: var(--accent); font-weight: 700; font-size: .82rem; text-transform: uppercase; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 900px) {
  .sidebar { width: 64px; min-width: 64px; padding: 14px 8px; }
  .brand-name, .nav-label, .user-name { display: none; }
  .brand { justify-content: center; padding: 4px 0 14px; }
  .nav-item { justify-content: center; padding: 11px 0; }
  .nav-item .badge { position: absolute; top: 4px; right: 6px; min-width: 16px; padding: 0 5px; font-size: .64rem; }
  .user-pill { justify-content: center; padding: 6px 0; }
  .main { padding: 20px 16px 50px; }
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .savebar { margin: 16px -16px -16px; padding: 12px 16px; }
  .main { padding: 16px 12px 46px; }
  .wf-row { flex-wrap: wrap; }
  .wf-row select { max-width: none; flex: 1; }
}

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