/* ============================================================
   AdControl — Shared Design System
   Deep Navy / Slate · Notion-inspired Professional
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600;700&family=Geist+Mono:wght@400;500&display=swap');

:root {
  /* ── Core Palette ── */
  --navy-950:  #060a12;
  --navy-900:  #0b1120;
  --navy-850:  #0f1829;
  --navy-800:  #141f33;
  --navy-750:  #192540;
  --navy-700:  #1e2d4d;
  --navy-600:  #243560;
  --slate-500: #334878;
  --slate-400: #4a6097;
  --slate-300: #6b80aa;
  --slate-200: #8fa3c8;
  --slate-100: #b8cce0;
  --slate-50:  #dce6f0;

  /* ── Semantic ── */
  --bg:        var(--navy-950);
  --bg-card:   var(--navy-900);
  --bg-raised: var(--navy-850);
  --bg-hover:  var(--navy-800);
  --bg-active: var(--navy-750);
  --border:    rgba(100, 140, 200, 0.10);
  --border-md: rgba(100, 140, 200, 0.16);
  --border-hi: rgba(100, 140, 200, 0.28);

  /* ── Text ── */
  --text:       #e8edf5;
  --text-2:     #a8b8d0;
  --text-3:     #6b80aa;
  --text-4:     #3d5070;

  /* ── Accent ── */
  --accent:      #4f83f0;
  --accent-soft: rgba(79, 131, 240, 0.12);
  --accent-mid:  rgba(79, 131, 240, 0.24);
  --accent-glow: rgba(79, 131, 240, 0.40);

  /* ── Status ── */
  --green:      #34d399;
  --green-soft: rgba(52, 211, 153, 0.10);
  --amber:      #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.10);
  --red:        #f87171;
  --red-soft:   rgba(248, 113, 113, 0.10);
  --purple:     #a78bfa;
  --purple-soft:rgba(167, 139, 250, 0.10);

  /* ── Typography ── */
  --font:      'Geist', -apple-system, sans-serif;
  --font-mono: 'Geist Mono', 'Fira Code', monospace;

  /* ── Spacing & Shape ── */
  --radius-sm: 6px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --nav-w:     220px;
  --header-h:  56px;

  /* ── Transitions ── */
  --ease:      cubic-bezier(0.16, 1, 0.3, 1);
  --dur:       0.18s;
}

/* ── Light Mode ── */
[data-theme="light"] {
  --bg:        #f5f7fa;
  --bg-card:   #ffffff;
  --bg-raised: #edf0f5;
  --bg-hover:  #e2e8f0;
  --bg-active: #d5dde8;
  --border:    rgba(15, 30, 80, 0.08);
  --border-md: rgba(15, 30, 80, 0.14);
  --border-hi: rgba(15, 30, 80, 0.28);
  --text:      #0f172a;
  --text-2:    #334155;
  --text-3:    #64748b;
  --text-4:    #94a3b8;
  --green:      #059669;
  --green-soft: rgba(5, 150, 105, 0.10);
  --amber:      #d97706;
  --amber-soft: rgba(217, 119, 6, 0.10);
  --red:        #dc2626;
  --red-soft:   rgba(220, 38, 38, 0.10);
}
[data-theme="light"] .nav-sidebar { background: #fff; }
[data-theme="light"] .page-header { background: #fff; }
[data-theme="light"] .controls-panel { background: #fff; }
[data-theme="light"] .ad-list-panel { background: #fafbfd; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--navy-700); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }

/* ============================================================
   SIDEBAR NAVIGATION
   ============================================================ */
.nav-sidebar {
  width: var(--nav-w);
  height: 100vh;
  background: var(--navy-900);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 50;
  padding: 0 0 16px;
  transition: width 0.22s var(--ease);
  overflow: hidden;
}

/* ── Collapsed sidebar ── */
.nav-sidebar.collapsed { width: 54px; }
.nav-sidebar.collapsed .nav-logo-text,
.nav-sidebar.collapsed .nav-section-label { display: none; }
.nav-sidebar.collapsed .nav-item { justify-content: center; padding: 7px 0; margin: 1px 6px; width: calc(100% - 12px); position: relative; }
.nav-sidebar.collapsed .nav-item > span,
.nav-sidebar.collapsed .nav-item > .nav-item-badge { display: none; }
.nav-sidebar.collapsed .nav-item svg { margin: 0; opacity: 1; }
.nav-sidebar.collapsed .nav-logo { justify-content: center; padding: 18px 10px 16px; }
.nav-sidebar.collapsed .nav-item[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 46px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--navy-700);
  color: var(--text);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 200;
  border: 1px solid var(--border-md);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.nav-sidebar.collapsed .nav-item[data-tip]:hover::after { opacity: 1; }

/* ── Collapse toggle button ── */
.nav-collapse-btn {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-md);
  background: var(--bg-raised);
  cursor: pointer;
  color: var(--text-3);
  transition: all var(--dur);
  flex-shrink: 0;
}
.nav-collapse-btn:hover { background: var(--bg-hover); color: var(--text); }
.nav-collapse-btn svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2; transition: transform 0.22s var(--ease); }
.nav-sidebar.collapsed .nav-collapse-btn { margin: 0 auto; width: 30px; height: 30px; }
.nav-sidebar.collapsed .nav-collapse-btn svg { transform: rotate(180deg); }

.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  text-decoration: none;
}
.nav-logo-mark {
  width: 30px; height: 30px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.nav-logo-mark svg { width: 16px; height: 16px; fill: #fff; stroke: none; }
.nav-logo-text { line-height: 1.2; }
.nav-logo-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  display: block;
}
.nav-logo-sub {
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-4);
  padding: 12px 16px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 16px;
  margin: 1px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-3);
  font-size: 13px;
  font-weight: 450;
  transition: all var(--dur) var(--ease);
  cursor: pointer;
  border: none;
  background: none;
  width: calc(100% - 16px);
  text-align: left;
}
.nav-item svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; flex-shrink: 0; opacity: 0.8; }
.nav-item:hover { background: var(--bg-hover); color: var(--text-2); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}
.nav-item.active svg { opacity: 1; }

.nav-item-badge {
  margin-left: auto;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 100px;
  font-family: var(--font-mono);
}

.nav-bottom {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.page-header {
  height: var(--header-h);
  background: var(--navy-900);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}
.page-header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.page-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; flex-shrink: 0; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: #3d72e0; border-color: #3d72e0; }

.btn-secondary {
  background: var(--bg-raised);
  color: var(--text-2);
  border-color: var(--border-md);
}
.btn-secondary:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-hi); }

.btn-ghost {
  background: transparent;
  color: var(--text-3);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-2); }

.btn-danger {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(248, 113, 113, 0.2);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.18); }

.btn-success {
  background: var(--green-soft);
  color: var(--green);
  border-color: rgba(52, 211, 153, 0.2);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
}
.btn-lg {
  padding: 9px 18px;
  font-size: 14px;
}

.btn-icon {
  padding: 7px;
  width: 32px; height: 32px;
  justify-content: center;
}
.btn-icon svg { width: 14px; height: 14px; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-sm { padding: 14px 16px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.card-subtitle {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color var(--dur) var(--ease);
}
.stat-card:hover { border-color: var(--border-md); }
.stat-card-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}
.stat-card-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1;
  font-family: var(--font);
}
.stat-card-meta {
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 4px;
}
.stat-card-meta .up { color: var(--green); }
.stat-card-meta .down { color: var(--red); }

/* ============================================================
   BADGES / PILLS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.badge-green  { background: var(--green-soft);  color: var(--green); }
.badge-amber  { background: var(--amber-soft);  color: var(--amber); }
.badge-red    { background: var(--red-soft);    color: var(--red); }
.badge-blue   { background: var(--accent-soft); color: var(--accent); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-gray   { background: var(--bg-active);   color: var(--text-3); }

.badge-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* ============================================================
   INPUTS & FORM
   ============================================================ */
.input, .select, .textarea {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  line-height: 1.4;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-4); }
.select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath stroke='%234a6097' stroke-width='1.5' d='m1 1 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.textarea { resize: vertical; min-height: 72px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 5px;
}
.form-hint {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
}
.form-row {
  display: flex;
  gap: 12px;
}
.form-row > * { flex: 1; min-width: 0; }

/* Range */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 3px;
  background: var(--bg-active);
  border: none;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  padding: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--bg-card);
}
.range-row { display: flex; align-items: center; gap: 10px; }
.range-val {
  font-size: 11px;
  color: var(--accent);
  font-family: var(--font-mono);
  min-width: 36px;
  text-align: right;
}

/* Color */
.color-row { display: flex; align-items: center; gap: 8px; }
input[type="color"] {
  width: 28px; height: 28px;
  padding: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-md);
  background: var(--bg-raised);
  cursor: pointer;
  flex-shrink: 0;
}

/* Toggle */
.toggle {
  width: 36px; height: 20px;
  background: var(--bg-active);
  border-radius: 100px;
  cursor: pointer;
  position: relative;
  transition: all var(--dur) var(--ease);
  flex-shrink: 0;
  border: 1px solid var(--border-md);
}
.toggle.on { background: var(--accent); border-color: var(--accent); }
.toggle-knob {
  width: 14px; height: 14px;
  background: var(--text-3);
  border-radius: 50%;
  position: absolute;
  top: 2px; left: 2px;
  transition: all var(--dur) var(--ease);
}
.toggle.on .toggle-knob { left: 18px; background: #fff; }

/* Chip group */
.chip-group { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border-md);
  background: var(--bg-raised);
  color: var(--text-3);
  transition: all var(--dur) var(--ease);
  font-family: var(--font);
}
.chip.active { background: var(--accent-soft); border-color: var(--accent-mid); color: var(--accent); }

/* ============================================================
   DIVIDER
   ============================================================ */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ============================================================
   NOTIFICATION TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--navy-800);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s var(--ease);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: rgba(52, 211, 153, 0.3); }
.toast.error   { border-color: rgba(248, 113, 113, 0.3); }
.toast-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.toast.success .toast-dot { background: var(--green); }
.toast.error   .toast-dot { background: var(--red); }

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; }
table.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.ds-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ds-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}
.ds-table tbody tr { transition: background var(--dur) var(--ease); }
.ds-table tbody tr:hover td { background: var(--bg-hover); }
.ds-table tbody tr:last-child td { border-bottom: none; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(6, 10, 18, 0.75);
  display: none; align-items: center; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(6px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-xl);
  width: 540px; max-width: 94vw;
  max-height: 85vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(100,140,200,0.05);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.modal-body { flex: 1; overflow-y: auto; padding: 20px; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: 4px;
  border-radius: var(--radius-sm);
  transition: all var(--dur) var(--ease);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text); }

/* ============================================================
   UTILITY
   ============================================================ */
.hidden { display: none !important; }
.text-accent { color: var(--accent); }
.text-green  { color: var(--green); }
.text-amber  { color: var(--amber); }
.text-red    { color: var(--red); }
.text-muted  { color: var(--text-3); }
.font-mono   { font-family: var(--font-mono); }
.truncate    { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.grid { display: grid; }
.grid-2 { grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); gap: 16px; }