*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { text-decoration: none; color: inherit; }
button, input, textarea, select { font: inherit; }
img { max-width: 100%; display: block; }

/* ── Variables — dark (default) ────────────────────────────────────────────── */
:root {
  --blue:       #3b82f6;
  --blue-dark:  #2563eb;
  --green:      #22c55e;
  --yellow:     #f59e0b;
  --red:        #ef4444;
  --bg:         #0d1117;
  --bg-card:    #161b22;
  --bg-input:   #21262d;
  --bg-hover:   #21262d;
  --border:     #30363d;
  --text:       #e2e8f0;
  --text-muted: #8b949e;
  --sidebar-w:  240px;
  --radius:     8px;
}

/* ── Variables — light ─────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:         #f6f8fa;
  --bg-card:    #ffffff;
  --bg-input:   #eaeef2;
  --bg-hover:   #eaeef2;
  --border:     #d0d7de;
  --text:       #1c2128;
  --text-muted: #57606a;
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */
html, body { height: 100%; }
#layout { display: flex; min-height: 100vh; width: 100%; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  color: var(--blue);
  font-weight: 700;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
}
#sidebar-nav { flex: 1; padding: 8px 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text-muted);
  border-radius: 0;
  transition: background .15s, color .15s;
  cursor: pointer;
  font-size: .9rem;
}
.nav-item:hover  { background: var(--bg-hover); color: var(--text); }
.nav-item.active { color: var(--blue); background: rgba(59,130,246,.08); font-weight: 600; }
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.advertiser-badge { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.advertiser-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; color: #fff;
  flex-shrink: 0;
}
.badge-info { min-width: 0; }
.badge-name    { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-company { font-size: .75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout, .btn-theme {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 4px; border-radius: 4px; flex-shrink: 0;
  transition: color .15s;
}
.btn-logout:hover { color: var(--red); }
.btn-theme:hover  { color: var(--blue); }

/* ── Main content ────────────────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  min-width: 0;       /* prevent flex blowout on wide tables */
  padding: 32px;
  overflow-y: auto;
}

/* ── Auth / onboarding views ─────────────────────────────────────────────────── */
#auth-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 440px;
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 28px; color: var(--blue); font-weight: 700; font-size: 1.1rem;
}
.auth-card h2 { font-size: 1.3rem; margin-bottom: 6px; }
.auth-card p  { color: var(--text-muted); font-size: .9rem; margin-bottom: 24px; }

/* ── Form elements ───────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .85rem; color: var(--text-muted); margin-bottom: 6px; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--blue); }
.form-group textarea { resize: vertical; min-height: 80px; }

/* ── Password visibility toggle ──────────────────────────────────────────────── */
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { flex: 1; padding-right: 40px; }
.pw-eye {
  position: absolute; right: 10px;
  background: none; border: none; padding: 0;
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center;
  transition: color .15s;
}
.pw-eye:hover { color: var(--text); }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--radius);
  border: none; cursor: pointer; font-weight: 600;
  font-size: .9rem; transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--blue);  color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--bg-hover); }
.btn-full { width: 100%; justify-content: center; }

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }

/* ── Stat grid ───────────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; width: 100%; }
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-label  { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.stat-value  { font-size: 1.6rem; font-weight: 700; }
.stat-value.green  { color: var(--green); }
.stat-value.yellow { color: var(--yellow); }
.stat-value.blue   { color: var(--blue); }

/* ── Page header ─────────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; }
.page-header p  { color: var(--text-muted); font-size: .9rem; margin-top: 4px; }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
#toasts { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: .9rem;
  min-width: 240px;
  animation: slideIn .2s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--red);   color: var(--red);   }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Error inline ────────────────────────────────────────────────────────────── */
.error-msg { color: var(--red); font-size: .85rem; margin-top: 12px; display: none; }
.error-msg.show { display: block; }

/* ── Status badge ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 10px;
  border-radius: 12px; font-size: .78rem; font-weight: 600;
}
.badge-active    { background: rgba(34,197,94,.12);  color: var(--green); }
.badge-pending   { background: rgba(245,158,11,.12); color: var(--yellow); }
.badge-suspended { background: rgba(239,68,68,.12);  color: var(--red); }

/* ── Coming soon placeholder ─────────────────────────────────────────────────── */
.coming-soon {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 300px; color: var(--text-muted); gap: 12px;
}
.coming-soon svg { opacity: .3; }
.coming-soon p   { font-size: .9rem; }

/* ── Data table ──────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table th {
  text-align: left; padding: 12px 16px;
  color: var(--text-muted); font-weight: 600; font-size: .78rem;
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border); background: var(--bg-card);
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg-hover); }

/* ── 2-column form grid ──────────────────────────────────────────────────────── */
.form-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ── Billing layout grid ─────────────────────────────────────────────────────── */
.billing-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

/* ── Date inputs ─────────────────────────────────────────────────────────────── */
input[type="date"] {
  min-width: 0;       /* prevent iOS intrinsic-width blowout in flex/grid */
  max-width: 100%;
}

/* ── Billing date filter row ─────────────────────────────────────────────────── */
.date-filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.date-filter-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
  color: var(--text);
  font-size: .82rem;
  min-width: 0;
  width: auto;
}

/* ── Docs / Help page ────────────────────────────────────────────────────────── */
.docs-card { margin-bottom: 24px; }
.docs-section-title {
  font-size: 1.05rem; font-weight: 700; margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px;
}
.docs-icon {
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
}
.docs-toc { display: flex; flex-wrap: wrap; gap: 8px; }
.docs-toc-btn {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 14px; font-size: .82rem;
  color: var(--text-muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.docs-toc-btn:hover { background: var(--bg-hover); color: var(--blue); }
.docs-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 720px) { .docs-2col { grid-template-columns: 1fr; } }
.docs-diagram {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin: 16px 0;
  overflow-x: auto; text-align: center;
}
.docs-tip {
  background: rgba(59,130,246,.08); border-left: 3px solid var(--blue);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 12px 16px; font-size: .87rem; color: var(--text-muted); margin: 12px 0;
}
.docs-warn {
  background: rgba(245,158,11,.08); border-left: 3px solid var(--yellow);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 12px 16px; font-size: .87rem; color: var(--text-muted); margin: 12px 0;
}
.docs-step-list { list-style: none; counter-reset: step-counter; padding: 0; }
.docs-step-list li {
  counter-increment: step-counter; display: flex;
  gap: 14px; margin-bottom: 18px; align-items: flex-start;
}
.docs-step-list li::before {
  content: counter(step-counter);
  min-width: 26px; height: 26px; border-radius: 50%;
  background: var(--blue); color: #fff;
  font-size: .8rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 1px;
}

/* ── Modal ───────────────────────────────────────────────────────────────────── */
#modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 1000;
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
}

/* ── Content wrapper (flex col on mobile) ─────────────────────────────────── */
#content-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Mobile top bar ──────────────────────────────────────────────────────────── */
#mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
#hamburger-btn, #sidebar-close-btn {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  padding: 4px; border-radius: 4px; flex-shrink: 0;
  display: flex; align-items: center;
  transition: color .15s;
}
#hamburger-btn:hover, #sidebar-close-btn:hover { color: var(--text); }
#sidebar-close-btn { display: none; margin-left: auto; }
.topbar-brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: .95rem; color: var(--blue);
}

/* ── Sidebar overlay ─────────────────────────────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
}
#sidebar-overlay.open { display: block; }

/* ── Mobile responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Show hamburger, hide desktop brand close btn */
  #mobile-topbar    { display: flex; }
  #sidebar-close-btn { display: flex; }

  /* Sidebar becomes a slide-in drawer */
  #sidebar {
    position: fixed;
    left: 0; top: 0;
    height: 100%;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }

  /* Main content — let the page scroll on mobile instead of the inner box */
  #main-content { padding: 16px; overflow-y: visible; }

  /* Auth card */
  .auth-card { padding: 24px 20px; margin: 0 8px; }

  /* Modal full-width */
  #modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box {
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 92vh;
    padding: 24px 16px;
  }

  /* Tables — horizontal scroll */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* Collapse 2-column form grids and billing layout */
  .form-grid-2col,
  .billing-grid {
    grid-template-columns: 1fr;
  }

  /* Date filter row stacks nicely */
  .date-filter-input { flex: 1; min-width: 120px; }

  /* Page header */
  .page-header { margin-bottom: 16px; }
  .page-header h1 { font-size: 1.2rem; }

  /* Stat grid — 2 cols on mobile */
  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  /* Button rows */
  .docs-toc { gap: 6px; }
}

@media (max-width: 480px) {
  #main-content { padding: 12px; }
  .stat-grid { grid-template-columns: 1fr; }
  .modal-box { padding: 20px 14px; }
  .auth-card { padding: 20px 16px; }
}
