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

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --primary: #FF3FAE;
  --primary-hover: #e0318f;
  --primary-dim: rgba(255,63,174,0.10);
  --accent: #00C6FF;
  --accent-dim: rgba(0,198,255,0.10);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --sidebar-w: 240px;
  --transition: 0.18s ease;
  --gradient: linear-gradient(135deg, #FF3FAE 0%, #00C6FF 100%);
}

html, body { height: 100%; }
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; overflow-x: hidden; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
img { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

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

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 90;
}

.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 130;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: left var(--transition), right var(--transition), background var(--transition), border-color var(--transition);
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 24px 20px 20px;
  font-weight: 700; font-size: 15px; color: var(--text);
  border-bottom: 1px solid var(--border);
}
.sidebar-logo svg { flex-shrink: 0; }
.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13.5px; font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-dim); color: var(--primary); }
.nav-section { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); padding: 12px 12px 4px; }
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; color: #fff; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }
.btn-logout {
  background: none; border: none; padding: 4px; border-radius: var(--radius-sm);
  color: var(--text-muted); transition: color var(--transition);
  display: flex; align-items: center;
}
.btn-logout:hover { color: var(--danger); }

/* ── Main content ── */
.main { margin-left: var(--sidebar-w); flex: 1; padding: 32px 36px; min-width: 0; }
.page-header { margin-bottom: 28px; }
.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Stats grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 104px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .05em;
  min-height: 22px;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin-top: 0;
  padding-top: 2px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-value-sm {
  margin-top: 0;
  padding-top: 2px;
  min-height: 34px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-value.green { color: var(--success); }
.stat-value.indigo { color: var(--primary); }
.stat-meta { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; border: none;
  transition: background var(--transition), opacity var(--transition);
}
.btn-primary { background: var(--gradient); color: #fff; }
.btn-primary:hover { background: linear-gradient(135deg, #e0318f 0%, #00b0e6 100%); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); color: var(--danger); }
.btn-success { background: rgba(16,185,129,.15); color: var(--success); border: 1px solid rgba(16,185,129,.3); }
.btn-success:hover { background: rgba(16,185,129,.25); color: var(--success); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 4px 10px; font-size: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 9px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px;
  transition: border-color var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--primary); }
.form-control::placeholder { color: var(--text-muted); }
select.form-control option { background: var(--surface-2); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.form-warning {
  margin-top: 2px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(245, 158, 11, .35);
  background: rgba(245, 158, 11, .10);
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
}
.notice-box {
  margin: 8px 0 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12.5px;
  line-height: 1.45;
}
.notice-box.notice-error {
  border-color: rgba(239, 68, 68, .35);
  background: rgba(239, 68, 68, .10);
  color: #b91c1c;
}
.notice-box.notice-warning {
  border-color: rgba(245, 158, 11, .35);
  background: rgba(245, 158, 11, .10);
  color: var(--text);
}
[data-theme="dark"] .notice-box.notice-error {
  color: #fca5a5;
}

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
.td-actions { display: flex; gap: 8px; align-items: center; }
.td-actions .btn {
  min-width: 122px;
  justify-content: center;
  white-space: nowrap;
}

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600;
}
.badge-green { background: rgba(16,185,129,.15); color: var(--success); }
.badge-red { background: rgba(239,68,68,.15); color: var(--danger); }
.badge-yellow { background: rgba(245,158,11,.15); color: var(--warning); }
.badge-indigo { background: var(--primary-dim); color: var(--primary); }
.badge-gray { background: var(--surface-2); color: var(--text-muted); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 200; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  transform: translateY(16px); transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 20px; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

/* ── Refresh timestamp ── */
.refresh-bar {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-muted); margin-bottom: 20px;
}
.refresh-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }

/* ── Date filter ── */
.filter-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.filter-btn {
  padding: 6px 14px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--border); background: transparent; color: var(--text-muted);
  transition: all var(--transition);
}
.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary-dim); border-color: var(--primary); color: var(--primary); }
.filter-sep { color: var(--border); }

/* ── Top video card ── */
.top-video {
  display: flex; gap: 14px; align-items: flex-start;
}
.top-video-thumb {
  width: 100px; height: 56px; border-radius: var(--radius-sm);
  object-fit: cover; background: var(--surface-2); flex-shrink: 0;
}
.top-video-info { flex: 1; min-width: 0; }
.top-video-title { font-size: 13.5px; font-weight: 600; color: var(--text); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.top-video-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Video list ── */
.video-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.video-item:last-child { border-bottom: none; }
.video-thumb { width: 72px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--surface-2); flex-shrink: 0; }
.video-info { flex: 1; min-width: 0; }
.video-title { font-size: 13px; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.video-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* ── Chart container ── */
.chart-wrap { position: relative; height: 260px; }
.drill-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
  margin-top: 12px; display: none;
}
.drill-card.visible { display: block; }
.drill-row { display: flex; gap: 24px; flex-wrap: wrap; }
.drill-item label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; display: block; }
.drill-item span { font-size: 16px; font-weight: 700; color: var(--text); }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px;
  animation: slideIn .2s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Login page ── */
.auth-page {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  background: var(--gradient); padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; font-size: 18px; font-weight: 700; }
.auth-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.auth-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 28px; }
.auth-footer { margin-top: 20px; margin-bottom: 12px; text-align: center; font-size: 12.5px; color: var(--text-muted); }

/* ── Video search results (admin) ── */
.search-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; max-width: 100%; overflow: hidden; }
.search-item {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden; cursor: pointer;
  transition: border-color var(--transition); position: relative;
}
.search-item:hover { border-color: var(--primary); }
.search-item.selected { border-color: var(--primary); background: var(--primary-dim); }
.search-item.locked {
  border-color: #3a4352;
  background: #1f2633;
  cursor: not-allowed;
}
.search-item.locked:hover { border-color: #4a5568; }
.search-item.locked img { filter: grayscale(0.85) brightness(0.45); }
.search-item.locked .search-item-title,
.search-item.locked .search-item-views { color: rgba(226, 232, 240, 0.84); }
.search-item img { width: 100%; aspect-ratio: 16/9; object-fit: cover; }
.search-item-info { padding: 10px; }
.search-item-title { font-size: 12.5px; font-weight: 500; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.search-item-views { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.search-item-open {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  width: 26px; height: 26px; background: rgba(0,0,0,0.65); border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; opacity: 0; transition: opacity var(--transition); text-decoration: none;
}
.search-item:hover .search-item-open { opacity: 1; }
.load-more-row {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}
.search-item-lock {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 98px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(148, 163, 184, 0.55);
  box-shadow: 0 8px 18px rgba(2, 6, 23, 0.35);
  font-family: 'Inter', sans-serif;
}
.search-item-lock-icon {
  font-size: 17px;
  line-height: 1;
}
.search-item-lock-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.selection-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.selection-item-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.selection-item-meta img {
  width: 56px;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.selection-item-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.selection-item-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

#selection-items {
  max-height: 420px;
  overflow: auto;
  padding-right: 2px;
}

#selection-bar .btn-xs {
  min-width: 62px;
}

/* ── RPM history ── */
.rpm-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.rpm-row:last-child { border-bottom: none; }

/* ── Separator ── */
.section-gap { margin-top: 24px; }

/* ── Empty state ── */
.empty { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-icon { font-size: 36px; margin-bottom: 12px; }
.empty-text { font-size: 15px; font-weight: 500; }
.empty-sub { font-size: 13px; margin-top: 4px; }

/* ── Users page mobile cards ── */
.users-mobile-list {
  display: grid;
  gap: 12px;
}
.users-mobile-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 12px;
}
.users-mobile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  padding: 4px 0;
}
.users-mobile-row .label {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 10.5px;
}
.users-mobile-row .value {
  text-align: right;
  color: var(--text);
  font-weight: 500;
}
.users-mobile-actions {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

/* ── Creator stats header filters ── */
.creator-stats-head-info {
  min-width: 0;
}
.creator-stats-filters {
  justify-content: flex-end;
}
.creator-stats-date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.creator-video-cell {
  min-width: 300px;
}

.creator-video-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.creator-video-table {
  min-width: 860px;
}

/* ── Cross-browser fallbacks ── */
@supports not (height: 100dvh) {
  .auth-page {
    min-height: 100vh;
  }

  @media (max-width: 768px) {
    .sidebar {
      height: 100vh;
      max-height: 100vh;
    }
  }
}

@supports not (aspect-ratio: 1 / 1) {
  .search-item img {
    height: 112px;
  }
}

@supports not ((-webkit-line-clamp: 2) and (-webkit-box-orient: vertical)) {
  .top-video-title,
  .search-item-title,
  .creator-video-title {
    display: block;
    line-height: 1.35;
    overflow: hidden;
  }

  .top-video-title,
  .search-item-title {
    max-height: calc(1.35em * 2);
  }

  .creator-video-title {
    max-height: calc(1.35em * 4);
  }
}

html.no-dvh .auth-page {
  min-height: 100vh;
}

html.no-dvh .sidebar {
  height: 100vh;
  max-height: 100vh;
}

html.no-aspect-ratio .search-item img {
  height: 112px;
}

html.no-line-clamp .top-video-title,
html.no-line-clamp .search-item-title,
html.no-line-clamp .creator-video-title {
  display: block;
  line-height: 1.35;
  overflow: hidden;
}

html.no-line-clamp .top-video-title,
html.no-line-clamp .search-item-title {
  max-height: calc(1.35em * 2);
}

html.no-line-clamp .creator-video-title {
  max-height: calc(1.35em * 4);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .mobile-menu-btn { display: inline-flex; }
  .sidebar {
    height: 100dvh;
    max-height: 100dvh;
    bottom: auto;
    overflow: hidden;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  }
  .sidebar-nav {
    order: 3;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 10px;
  }
  .sidebar-footer {
    order: 2;
    background: var(--surface);
    border-top: none;
    border-bottom: 1px solid var(--border);
    padding-top: 10px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  body.sidebar-open .mobile-menu-btn {
    left: auto;
    right: 12px;
    background: var(--primary-dim);
    border-color: var(--primary);
    color: var(--primary);
  }

  .main { margin-left: 0; padding: 64px 16px 20px; width: 100%; }
  .main > * { max-width: 100%; }

  .form-row { grid-template-columns: 1fr; }
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 14px;
  }
  .stat-card {
    padding: 14px;
    min-height: 92px;
  }
  .stat-label { min-height: 18px; }
  .stat-value { font-size: 24px; }
  .filter-bar { gap: 8px; }
  .filter-bar .form-control,
  .filter-bar .btn { width: 100% !important; }
  .filter-sep { display: none; }

  .card { padding: 16px; }
  .card-header { gap: 10px; flex-wrap: wrap; }
  .page-title { font-size: 20px; }
  .td-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
  .td-actions .btn {
    width: 100%;
    min-width: 0;
  }

  .modal { padding: 20px; width: calc(100% - 24px); }

  .table-wrap { width: 100%; }
  .chart-wrap canvas { max-width: 100% !important; }
  #an-charts-grid canvas { max-width: 100% !important; display: block; }

  .admin-analytics-filters {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }
  .admin-analytics-filters .form-control,
  .admin-analytics-filters .btn,
  .admin-analytics-filters select {
    width: 100% !important;
    min-width: 0;
  }

  .admin-table-toolbar {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: stretch;
  }
  .admin-table-toolbar .form-control,
  .admin-table-toolbar select {
    width: 100% !important;
    min-width: 0;
  }

  #an-charts-grid { grid-template-columns: 1fr !important; }
  #affiliate-admin-grid { grid-template-columns: 1fr !important; }

  .users-page-header {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px;
  }
  .users-page-header .btn {
    width: 100%;
    justify-content: center;
  }

  .creator-stats-header {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .creator-stats-filters {
    width: 100%;
    justify-content: flex-start;
  }
  .creator-stats-filters .filter-btn {
    flex: 1 1 auto;
    min-width: 0;
    text-align: center;
  }
  .creator-stats-date-row {
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }
  .creator-stats-date-row .form-control {
    width: 100% !important;
    min-width: 0;
  }
  .creator-stats-filters #apply-custom {
    width: auto !important;
  }

  .creator-channel-col {
    display: table-cell;
    min-width: 150px;
  }
  .creator-video-table {
    min-width: 920px;
  }
  .creator-video-cell {
    min-width: 340px;
  }
  .creator-video-channel-mobile {
    display: none !important;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* ── Custom scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}
::-webkit-scrollbar-corner {
  background: var(--bg);
}
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}

/* ── Dark mode ── */
[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
}

[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--bg); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #484f58; }
[data-theme="dark"] .auth-card { box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.7); }
[data-theme="dark"] .toast { background: var(--surface); }

/* ── Theme / Language controls (injected into sidebar) ── */
.sidebar-controls {
  display: flex;
  gap: 6px;
  padding: 10px 16px 14px;
}
.sidebar-controls-top {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  margin: 0;
}
.ctrl-btn {
  flex: 1;
  padding: 5px 4px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all var(--transition);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}
.ctrl-btn:hover { border-color: var(--primary); color: var(--primary); }
.ctrl-btn.active { background: var(--primary-dim); border-color: var(--primary); color: var(--primary); }
.ctrl-sep {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  flex-shrink: 0;
  margin: 2px 0;
}

/* ── Auth page controls (login / reset) ── */
.auth-controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 16px;
}
.auth-ctrl-btn {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.auth-ctrl-btn:hover { border-color: var(--primary); color: var(--primary); }
.auth-ctrl-btn.active { background: var(--primary-dim); border-color: var(--primary); color: var(--primary); }

@media (max-width: 768px) {
  .auth-card {
    padding: 24px 18px;
  }

  .auth-controls {
    margin: 0 0 14px;
    gap: 8px;
    position: relative;
    z-index: 2;
  }

  .auth-ctrl-btn {
    min-width: 64px;
    min-height: 40px;
    padding: 8px 14px;
    font-size: 12px;
  }
}

/* ── Payments ── */
.payment-methods {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}
.payment-method-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
}
.payment-method-btn:hover {
  border-color: var(--primary);
}
.payment-method-btn.active {
  border-color: var(--primary);
  background: var(--primary-dim);
  color: var(--primary);
}
.payment-method-btn.disabled {
  opacity: 0.65;
  cursor: not-allowed;
  background: rgba(148, 163, 184, 0.12);
}
.soon-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(148, 163, 184, 0.5);
  color: #94a3b8;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ── Login canvas background ── */
.auth-page {
  position: relative;
  overflow: hidden;
}
#login-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  z-index: 0;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.auth-card {
  position: relative;
  z-index: 1;
  isolation: isolate;
}

html.ua-safari #login-canvas,
html.ua-firefox #login-canvas {
  opacity: 0.9;
}

html.ua-opera #login-canvas {
  opacity: 0.95;
}
