/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; background: #f1f5f9; color: #0f172a; }

/* ── Layout ── */
#layout { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
#sidebar {
  width: 220px; flex-shrink: 0;
  background: #1e1b4b;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
#sidebar-brand {
  padding: 22px 20px 18px;
  font-size: 18px; font-weight: 900;
  background: linear-gradient(135deg, #a78bfa, #f472b6);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
#sidebar-nav { flex: 1; padding: 12px 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  color: #a5b4fc; font-size: 14px; font-weight: 500;
  text-decoration: none; transition: background .15s, color .15s;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(167,139,250,.15); color: #a78bfa; font-weight: 700; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-logout { margin-top: auto; border-top: 1px solid rgba(255,255,255,.07); color: #94a3b8; }

/* ── Content ── */
#content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  height: 56px; background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; position: sticky; top: 0; z-index: 10;
}
#topbar-title { font-size: 17px; font-weight: 700; color: #1e1b4b; }
#topbar-user  { font-size: 13px; color: #64748b; }
#page-body    { padding: 28px; flex: 1; }

/* ── Cards ── */
.section-card {
  background: #fff; border: 1px solid #e2e8f0;
  border-radius: 12px; padding: 20px;
}
.section-title { font-size: 15px; font-weight: 700; margin-bottom: 16px; color: #1e1b4b; }

/* ── Stats grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.stat-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; }
.stat-card.stat-warn { border-color: #fde68a; background: #fffbeb; }
.stat-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.stat-val   { font-size: 28px; font-weight: 900; color: #1e1b4b; }

/* ── Table ── */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #f1f5f9; }
.table th { font-weight: 700; color: #475569; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; background: #f8fafc; }
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 5px; }
.input {
  width: 100%; padding: 8px 11px;
  border: 1px solid #e2e8f0; border-radius: 8px;
  font-size: 13px; font-family: inherit; color: #0f172a;
  outline: none; transition: border-color .15s, box-shadow .15s;
  background: #fff;
}
.input:focus { border-color: #7c3aed; box-shadow: 0 0 0 3px rgba(124,58,237,.12); }
textarea.input { resize: vertical; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: 1px solid #e2e8f0;
  font-size: 13px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: all .15s; background: #fff; color: #374151;
}
.btn:hover { background: #f8fafc; }
.btn-primary { background: #7c3aed; color: #fff; border-color: #7c3aed; }
.btn-primary:hover { background: #6d28d9; border-color: #6d28d9; }
.btn-danger  { background: #ef4444; color: #fff; border-color: #ef4444; }
.btn-danger:hover  { background: #dc2626; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-full { width: 100%; }

/* ── Badges ── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 700;
  background: #e2e8f0; color: #475569;
}
.badge-ok     { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }

/* ── Toggle switch ── */
.toggle-label { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; }
.toggle-input { display: none; }
.toggle-slider {
  width: 38px; height: 22px; border-radius: 99px;
  background: #cbd5e1; position: relative; flex-shrink: 0; transition: background .2s;
}
.toggle-slider::after {
  content: ''; position: absolute; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; top: 3px; left: 3px;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-input:checked + .toggle-slider { background: #7c3aed; }
.toggle-input:checked + .toggle-slider::after { transform: translateX(16px); }

/* ── Modal ── */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  background: #fff; border-radius: 16px; padding: 28px;
  width: 100%; max-width: 440px; box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 18px; color: #1e1b4b; }
.modal-box {
  background: #fff; border-radius: 16px; padding: 28px;
  width: 100%; max-width: 580px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

/* ── Alert ── */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  padding: 12px 20px; border-radius: 10px;
  background: #1e1b4b; color: #fff;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
  opacity: 0; transform: translateY(10px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #dc2626; }

/* ── Login page ── */
.page-login { background: linear-gradient(135deg, #1e1b4b, #4c1d95); }
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: #fff; border-radius: 20px; padding: 40px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-logo { font-size: 22px; font-weight: 900; background: linear-gradient(135deg,#7c3aed,#ec4899); -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; margin-bottom: 6px; }
.login-title { font-size: 18px; font-weight: 700; margin-bottom: 24px; color: #1e1b4b; }
.login-form .btn { margin-top: 8px; }

/* ── Helpers ── */
.text-muted { color: #94a3b8; font-size: 13px; padding: 16px; text-align: center; display: block; }
hr { border: none; border-top: 1px solid #e2e8f0; }
code { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; background: #f1f5f9; padding: 2px 5px; border-radius: 4px; }

/* ── Upload drag & drop ──────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .18s, background .18s;
  position: relative;
  background: var(--bg);
}
.upload-zone:hover,
.upload-zone.drag-over { border-color: var(--primary); background: rgba(108,99,255,.07); }
.upload-zone input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.upload-zone-icon { font-size: 28px; margin-bottom: 6px; line-height: 1; pointer-events: none; }
.upload-zone-text { font-size: 12px; color: var(--muted); pointer-events: none; }
.upload-zone-text strong { color: var(--primary); }
.upload-zone-hint { font-size: 11px; color: var(--muted); margin-top: 3px; pointer-events: none; }

.upload-preview {
  display: none; border-radius: 8px; border: 1px solid var(--border);
  overflow: hidden; position: relative; background: var(--surface);
}
.upload-preview img { width: 100%; display: block; max-height: 160px; object-fit: contain; }
.upload-preview-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; background: rgba(0,0,0,.4);
  position: absolute; bottom: 0; left: 0; right: 0;
}
.upload-preview-name { font-size: 11px; color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-preview-del { font-size: 14px; cursor: pointer; color: #fff; opacity: .8; background: none; border: none; padding: 0; flex-shrink: 0; }
.upload-preview-del:hover { opacity: 1; }
.upload-progress { display: none; height: 3px; border-radius: 2px; background: var(--border); margin-top: 6px; overflow: hidden; }
.upload-progress-bar { height: 100%; width: 0%; background: var(--primary); transition: width .2s; }

/* ── Ad targeting — device cards ──────────────────────────────────────────── */
.adm-target-opt { display: block; cursor: pointer; }
.adm-target-opt input[type="checkbox"] { display: none; }
.adm-target-card {
  display: flex; align-items: center; justify-content: center;
  padding: 8px 6px; border-radius: 8px; font-size: 13px; font-weight: 600;
  border: 2px solid #e2e8f0; background: #f8fafc; color: #64748b;
  transition: border-color .15s, background .15s, color .15s;
  user-select: none; text-align: center; gap: 4px;
}
.adm-target-opt input[type="checkbox"]:checked + .adm-target-card {
  border-color: #7c3aed; background: rgba(124,58,237,.08); color: #7c3aed;
}
.adm-target-opt:hover .adm-target-card { border-color: #a78bfa; }

/* ── Ad targeting — language pills ───────────────────────────────────────── */
.adm-lang-opt { display: inline-block; cursor: pointer; }
.adm-lang-opt input[type="checkbox"] { display: none; }
.adm-lang-pill {
  display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
  border: 2px solid #e2e8f0; background: #f8fafc; color: #64748b;
  transition: border-color .15s, background .15s, color .15s;
  user-select: none;
}
.adm-lang-opt input[type="checkbox"]:checked + .adm-lang-pill {
  border-color: #7c3aed; background: rgba(124,58,237,.08); color: #7c3aed;
}
.adm-lang-opt:hover .adm-lang-pill { border-color: #a78bfa; }
