/* ============================================================================
   AssignPad Design System — Navy + Orange
   v2.21.0 rebuild.

   What changed and why:

   1. A SPACING SCALE. Everything used to be spaced by whatever number the last
      person typed — 14px here, 18px there, 22px in the card. Panels never
      lined up because nothing shared a rhythm. All spacing now comes from
      --space-1..8, so blocks written months apart still agree.

   2. NOTHING OVERLAPS. Flex and grid children default to min-width:auto, which
      is why a long client name or a wide table pushed a card out over its
      neighbour. Every layout child here is min-width:0, every wide thing gets
      its own scroll container, and long unbroken strings wrap instead of
      shoving.

   3. ONE ELEVATION LANGUAGE. Three shadows, used for three meanings — resting
      card, raised control, floating layer — instead of a different rgba per
      screen. Borders are 1px hairlines; the old 0.5px vanished entirely on
      non-retina Windows displays, which is most of this app's users.

   4. A REAL Z-INDEX ORDER, declared in one place at the bottom, so a dropdown
      can never open underneath the header again.

   5. MOBILE ACTUALLY WORKS. The sidebar had an .open class and nothing that
      could ever add it — below 880px the navigation was simply gone.

   Class names are unchanged throughout: every existing template keeps working.
   ============================================================================ */

:root {
  /* ── brand ─────────────────────────────────────────────────── */
  --navy-950: #060d24;
  --navy-900: #0a1230;
  --navy-800: #0e1840;
  --navy-700: #142057;
  --navy-600: #1c2c7a;
  --navy-500: #2a3d9b;
  --navy-100: #dde3f6;
  --navy-50:  #eef1fb;

  --orange:     #ee6f1a;
  --orange-600: #d35d12;
  --orange-100: #ffdcc1;
  --orange-50:  #fff4ea;

  --primary: var(--navy-900);
  --primary-dark: var(--navy-950);
  --primary-light: var(--navy-50);
  --accent: var(--orange);
  --accent-dark: var(--orange-600);
  --accent-soft: var(--orange-50);

  /* ── surfaces & text ───────────────────────────────────────── */
  /* Slightly warm neutrals. A pure-grey panel next to an orange accent reads
     cold and cheap; these carry a few degrees of the brand's warmth. */
  --bg:          #f4f6fa;
  --surface:     #ffffff;
  --surface-alt: #f7f8fc;
  --surface-sunk:#eef1f7;

  --text:        #101733;
  --text-muted:  #5a6486;
  --text-light:  #8b93ad;
  --border:      #e3e7f0;
  --border-strong: #cdd4e3;

  /* ── status ────────────────────────────────────────────────── */
  --success:      #15803d;
  --success-bg:   #e7f8ed;
  --success-dark: #14532d;
  --warning:      #9a5b06;
  --warning-bg:   #fff4e0;
  --danger:       #c02626;
  --danger-bg:    #fdecec;
  --info:         var(--navy-600);
  --info-bg:      var(--navy-50);

  /* ── elevation ─────────────────────────────────────────────── */
  --shadow-sm: 0 1px 2px rgba(16, 23, 51, .06);
  --shadow:    0 2px 4px rgba(16, 23, 51, .04), 0 8px 24px -12px rgba(16, 23, 51, .18);
  --shadow-lg: 0 8px 16px rgba(16, 23, 51, .08), 0 24px 48px -16px rgba(16, 23, 51, .24);
  --ring: 0 0 0 3px rgba(42, 61, 155, .16);
  --ring-accent: 0 0 0 3px rgba(238, 111, 26, .22);

  /* ── shape ─────────────────────────────────────────────────── */
  --radius-xs: 6px;
  --radius-sm: 9px;
  --radius:    13px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  /* ── rhythm ────────────────────────────────────────────────── */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 22px;
  --space-6: 28px;
  --space-7: 40px;
  --space-8: 56px;

  /* ── type ──────────────────────────────────────────────────── */
  --font-display: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', Consolas, monospace;

  /* ── layout ────────────────────────────────────────────────── */
  --sidebar-w: 248px;
  --topbar-h: 60px;

  /* ── motion ────────────────────────────────────────────────── */
  --ease: cubic-bezier(.2, 0, 0, 1);
  --fast: 130ms;
  --slow: 240ms;

  /* ── stacking order, declared once ─────────────────────────── */
  --z-sticky: 20;
  --z-topbar: 40;
  --z-sidebar: 60;
  --z-backdrop: 70;
  --z-drawer: 80;
  --z-popup: 3000;
}

/* ── DARK ──────────────────────────────────────────────────────
   Only tokens are redefined. Every component below is written against
   tokens, so the whole panel follows without a single component override. */
html[data-theme="dark"] {
  --bg:          #0b0f1a;
  --surface:     #141a27;
  --surface-alt: #1a2130;
  --surface-sunk:#0f1421;

  --text:        #e8ecf6;
  --text-muted:  #98a2bd;
  --text-light:  #737e9c;
  --border:      #262f42;
  --border-strong: #384258;

  --primary-light: #1a2130;
  --info-bg:  #1a2130;
  --success-bg: #10281c;
  --warning-bg: #2c2010;
  --danger-bg:  #2c1618;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger:  #f87171;
  --accent-soft: rgba(238, 111, 26, .13);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 2px 4px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
  --shadow-lg: 0 8px 16px rgba(0, 0, 0, .4), 0 24px 48px -16px rgba(0, 0, 0, .7);
  --ring: 0 0 0 3px rgba(102, 126, 234, .28);
}

/* ============================================================================
   RESET
   ============================================================================ */

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* A page must never scroll sideways because one table was too wide. */
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--text);
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -.015em;
  /* Headings carry the longest unbroken strings in the app (client names,
     domains) and are the usual culprit when a card bleeds into its neighbour. */
  overflow-wrap: anywhere;
}
h1 { font-size: 26px; } h2 { font-size: 21px; } h3 { font-size: 17px; }
h4 { font-size: 15px; } h5, h6 { font-size: 13.5px; }

p { overflow-wrap: break-word; }

a { color: var(--navy-700); text-decoration: none; transition: color var(--fast) var(--ease); }
a:hover { color: var(--accent); }
html[data-theme="dark"] a { color: #93a7f5; }

img, svg, video { max-width: 100%; }
img { height: auto; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

i.ti { vertical-align: -2px; line-height: 1; }

::selection { background: var(--orange-100); color: var(--navy-900); }

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

/* ============================================================================
   AUTH SCREENS
   ============================================================================ */

.auth-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-6) var(--space-4);
  background:
    radial-gradient(ellipse 80% 60% at 15% 20%, rgba(42, 61, 155, .38), transparent 60%),
    radial-gradient(ellipse 70% 60% at 85% 80%, rgba(238, 111, 26, .20), transparent 60%),
    linear-gradient(150deg, #060d24 0%, #0a1230 45%, #16215c 100%);
}
.auth-card {
  width: 100%; max-width: 430px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 32px 64px -12px rgba(0, 0, 0, .55);
  overflow: hidden;
  animation: authIn var(--slow) var(--ease) both;
}
@keyframes authIn { from { opacity: 0; transform: translateY(10px); } }

.auth-header { padding: var(--space-7) var(--space-7) var(--space-4); text-align: center; }
.logo-circle {
  width: 56px; height: 56px;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius);
  background: linear-gradient(140deg, var(--orange), var(--orange-600));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800;
  box-shadow: 0 8px 20px -6px rgba(238, 111, 26, .55);
}
.auth-header h1 { font-size: 23px; margin-bottom: var(--space-2); }
.auth-header p { color: var(--text-muted); font-size: 13.5px; }
.auth-body { padding: var(--space-2) var(--space-7) var(--space-6); }
.auth-footer {
  padding: var(--space-4) var(--space-7); text-align: center;
  font-size: 11.5px; color: var(--text-light);
  background: var(--surface-alt);
  border-top: 1px solid var(--border);
  line-height: 1.7;
}

/* ============================================================================
   APP SHELL
   ============================================================================ */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy-950);
  color: #c2c9e2;
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0;
  z-index: var(--z-sidebar);
  border-right: 1px solid rgba(255, 255, 255, .05);
  /* The nav is the only scrolling part; the brand and version stay put. */
  overflow: hidden;
}

.sidebar-brand {
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  flex: none;
}
.sidebar-brand .brand-row { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.sidebar-brand .brand-mark {
  width: 34px; height: 34px; border-radius: var(--radius-sm); flex: none;
  background: linear-gradient(140deg, var(--orange), var(--orange-600));
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; color: #fff;
  box-shadow: 0 4px 12px -3px rgba(238, 111, 26, .6);
}
.sidebar-brand .brand-name {
  font-family: var(--font-display);
  font-size: 16px; font-weight: 700; color: #fff; letter-spacing: -.01em;
}
.sidebar-brand .subtitle {
  font-size: 10.5px; color: #7a84b2; letter-spacing: .4px; margin-top: 1px;
}

.agency-badge {
  margin-top: var(--space-4);
  background: rgba(255, 255, 255, .045);
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: var(--radius-xs);
  padding: var(--space-2) var(--space-3);
  min-width: 0;
}
.agency-badge .lbl {
  font-size: 9.5px; color: #7a84b2; letter-spacing: .7px; font-weight: 700;
}
.agency-badge .name {
  font-size: 12.5px; color: #fff; font-weight: 600; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.sidebar nav {
  padding: var(--space-3) var(--space-2);
  flex: 1; display: flex; flex-direction: column;
  overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .18) transparent;
}
.sidebar nav::-webkit-scrollbar { width: 6px; }
.sidebar nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .16); border-radius: 3px; }

.sidebar nav a {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 9px var(--space-3); border-radius: var(--radius-xs);
  color: #c2c9e2; font-size: 13.5px; font-weight: 500;
  margin-bottom: 2px; min-width: 0;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.sidebar nav a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.sidebar nav a.active {
  background: linear-gradient(100deg, var(--orange), var(--orange-600));
  color: #fff; font-weight: 600;
  box-shadow: 0 4px 12px -4px rgba(238, 111, 26, .7);
}
.sidebar nav a i.ti { font-size: 17px; width: 20px; text-align: center; flex: none; }
.sidebar nav a .badge-count {
  margin-left: auto; flex: none;
  background: var(--orange); color: #fff;
  font-size: 10px; padding: 1px 7px; border-radius: var(--radius-pill); font-weight: 700;
}
.sidebar nav a.active .badge-count { background: rgba(255, 255, 255, .28); }

.sidebar .nav-section {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 1.3px;
  color: #626d94; padding: var(--space-4) var(--space-3) var(--space-1); font-weight: 700;
}
.sidebar .version-tag {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid rgba(255, 255, 255, .06);
  font-size: 10.5px; color: #626d94; flex: none;
}
/* The support number was set at 10.5px along with the version string beside it,
   which is a size for a build number, not for the number somebody dials when
   they are stuck. It is the only piece of help on the screen. */
.sidebar .support-line { display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px; font-size: 13px; color: #c5cae0; }
.sidebar .support-line a { display: inline-flex; align-items: center;
  font-size: 16px; line-height: 1; color: #c5cae0; }
.sidebar .support-line a:hover { color: #fff; }
.sidebar .support-line b { font-weight: 600; letter-spacing: .01em; }
.sidebar .version-tag a { color: #97a0c2; }
.sidebar .version-tag a:hover { color: #fff; }

/* Sidebar submenus (were inline in base.html, now part of the system) */
.nav-group { display: flex; flex-direction: column; }
.nav-group-toggle {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  background: none; border: none; color: #c2c9e2; cursor: pointer;
  padding: 9px var(--space-3); font-size: 13.5px; font-family: inherit;
  border-radius: var(--radius-xs); text-align: left;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.nav-group-toggle:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-group-toggle i.ti { font-size: 17px; width: 20px; text-align: center; flex: none; }
.nav-group-toggle .chev { margin-left: auto; font-size: 14px; transition: transform var(--fast) var(--ease); }
.nav-group-toggle.collapsed .chev { transform: rotate(-90deg); }
.nav-group-items { display: flex; flex-direction: column; }
.nav-group-items:not(.open) { display: none; }
.nav-group-items a { padding-left: 36px !important; font-size: 13px; }

/* ── main column ─────────────────────────────────────────────── */

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  min-height: 100vh;
  /* Without this a wide table inside stretches the column past the viewport
     and drags the whole page sideways under the fixed sidebar. */
  min-width: 0;
}

.topbar {
  /* Frosted, but only just. At 85% the page text scrolling underneath stayed
     legible through the bar and read as two lines of copy on top of each
     other — the exact complaint this rebuild is answering. */
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--space-6);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
  position: sticky; top: 0; z-index: var(--z-topbar);
  min-height: var(--topbar-h);
}
@supports not (backdrop-filter: blur(1px)) { .topbar { background: var(--surface); } }

/* The heading takes the slack so the controls stay pinned right whether or not
   the hamburger is present. */
.topbar-heading { flex: 1; min-width: 0; }
.topbar .page-title {
  font-family: var(--font-display);
  font-size: 18px; font-weight: 700; color: var(--text); letter-spacing: -.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .page-meta { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.topbar .topbar-right { display: flex; align-items: center; gap: var(--space-3); flex: none; }
.topbar .topbar-user .name {
  font-size: 13px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px;
}
.topbar .topbar-user .role { font-size: 11px; color: var(--text-muted); }

/* ── Top-bar scores: Rank in Team, Productive, Trust (core/scores.py) ───────
   On the left of the top bar, after the page title. Rank reads first; the two
   scores it is made from sit beside it, each with a thin meter. The whole
   thing is a link to the Team Scores report. */
.topbar-heading { display: flex; align-items: center; gap: var(--space-4); }
.topbar-heading > .page-title-wrap { min-width: 0; }
.topscore {
  position: relative; flex: none;
  display: flex; align-items: center; gap: 2px;
  color: inherit; text-decoration: none;
  padding: 3px 6px 3px 3px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.topscore:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); text-decoration: none; }
.topscore:hover .ts-chev { color: var(--accent); transform: translateX(2px); }
.topscore:focus-visible { outline: none; box-shadow: var(--ring); }
.ts-item { display: grid; row-gap: 3px; padding: 3px 10px; min-width: 0; }
.ts-item + .ts-item { border-left: 1px solid var(--border); }
.ts-label { font-size: 10.5px; font-weight: 600; color: var(--text-muted); white-space: nowrap; line-height: 1; }
.ts-short { display: none; }
.ts-val {
  font-family: var(--font-display); font-size: 16px; font-weight: 700; line-height: 1;
  color: var(--text); letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.ts-val small { font-size: 11px; font-weight: 600; color: var(--text-muted); letter-spacing: 0; }
.ts-val.ts-new { font-size: 13px; color: var(--text-muted); }
.ts-rank { background: var(--accent-soft); border-radius: 7px; }
.ts-rank .ts-val { color: var(--accent-dark); }
.ts-meter {
  display: block; height: 3px; width: 100%; min-width: 56px;
  border-radius: var(--radius-pill); background: var(--surface-sunk); overflow: hidden;
}
.ts-meter > span { display: block; height: 100%; border-radius: inherit; transition: width var(--slow) var(--ease); }
.ts-meter.band-high > span { background: var(--success); }
.ts-meter.band-mid  > span { background: var(--accent); }
.ts-meter.band-low  > span { background: var(--danger); }
.ts-meter.band-new  > span { background: var(--text-light); }
.ts-chev { font-size: 14px; color: var(--text-light); margin-left: 2px; transition: transform var(--fast) var(--ease); }
html[data-theme="dark"] .ts-rank .ts-val { color: #ffa15c; }

@media (max-width: 1280px) {
  .ts-long { display: none; }
  .ts-short { display: inline; }
}
@media (max-width: 880px) {
  .topbar-heading { gap: var(--space-2); }
  .ts-item { padding: 2px 8px; }
  .ts-meter { min-width: 34px; }
}
/* A phone has no room beside the bell: the scores take their own row under
   the title line, full width, so nothing is pushed off the screen. */
@media (max-width: 560px) {
  .topbar:has(.topscore) { flex-wrap: wrap; row-gap: var(--space-2); }
  .topbar-heading:has(.topscore) { display: contents; }
  .topbar-heading:has(.topscore) > .page-title-wrap { flex: 1; min-width: 0; }
  .topscore { order: 3; flex: 1 0 100%; }
  .topscore .ts-item { flex: 1; }
  .topscore .ts-meter { min-width: 0; }
}

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: linear-gradient(140deg, var(--navy-700), var(--navy-900));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12.5px; overflow: hidden;
}
.avatar img, .avatar-sm img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block;
}
.avatar-sm {
  width: 30px; height: 30px; border-radius: 50%; overflow: hidden; flex: none;
  background: var(--navy-50); color: var(--navy-900);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 11px;
}
html[data-theme="dark"] .avatar-sm { background: var(--surface-alt); color: var(--text); }

.page-content {
  padding: var(--space-5) var(--space-6) var(--space-8);
  flex: 1; min-width: 0;
}

/* Hamburger — hidden on desktop, the only way in on a phone. */
.nav-toggle {
  display: none;
  width: 36px; height: 36px; flex: none;
  align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  background: var(--surface); color: var(--text); cursor: pointer;
  font-size: 19px;
}
.nav-toggle:hover { background: var(--surface-alt); }
.nav-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(6, 13, 36, .55); z-index: var(--z-backdrop);
  backdrop-filter: blur(2px);
}
.nav-backdrop.show { display: block; animation: fadeIn var(--fast) var(--ease); }
@keyframes fadeIn { from { opacity: 0; } }

/* ============================================================================
   CARDS
   ============================================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  min-width: 0;
  transition: box-shadow var(--slow) var(--ease), border-color var(--slow) var(--ease);
}
.card:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap;
  margin-bottom: var(--space-4); padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.card-header > div:first-child { min-width: 0; }
.card-title {
  font-family: var(--font-display);
  font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -.01em;
}

/* ============================================================================
   STATS
   ============================================================================ */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}
.stat-grid > * { min-width: 0; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  position: relative; overflow: hidden; min-width: 0;
  box-shadow: var(--shadow-sm);
  transition: transform var(--slow) var(--ease), box-shadow var(--slow) var(--ease);
}
/* The accent rail sits on the left. On top it competed with the card's own
   border radius and looked like a rendering bug at certain zoom levels. */
.stat-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--navy-700);
}
.stat-card.sc-orange::before { background: var(--orange); }
.stat-card.sc-amber::before  { background: #f5b301; }
.stat-card.sc-green::before  { background: var(--success); }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-card .stat-row { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); }
.stat-card .stat-label {
  font-size: 11px; color: var(--text-muted);
  font-weight: 600; letter-spacing: .5px; text-transform: uppercase;
}
.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 32px; font-weight: 800; color: var(--text);
  margin-top: 2px; line-height: 1.1; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.stat-card .stat-meta { margin-top: var(--space-2); font-size: 12px; font-weight: 600; }

.stat-card .stat-icon, .stat-card .stat-emoji {
  width: 40px; height: 40px; border-radius: var(--radius-sm); flex: none;
  background: var(--surface-alt); color: var(--navy-900);
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.stat-card .stat-icon.icon-orange { background: var(--orange-50); color: var(--orange); }
.stat-card .stat-icon.icon-amber  { background: var(--warning-bg); color: var(--warning); }
.stat-card .stat-icon.icon-green  { background: var(--success-bg); color: var(--success); }
html[data-theme="dark"] .stat-card .stat-icon { background: var(--surface-alt); color: var(--text-muted); }

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--radius-xs);
  font-family: var(--font-body); font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer;
  white-space: nowrap; line-height: 1.25; text-decoration: none;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              color var(--fast) var(--ease), box-shadow var(--fast) var(--ease),
              transform var(--fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--navy-900); color: #fff; box-shadow: 0 1px 2px rgba(10, 18, 48, .3); }
.btn-primary:hover { background: var(--navy-800); color: #fff; box-shadow: 0 4px 12px -3px rgba(10, 18, 48, .45); }

.btn-accent { background: var(--orange); color: #fff; box-shadow: 0 1px 2px rgba(238, 111, 26, .3); }
.btn-accent:hover { background: var(--orange-600); color: #fff; box-shadow: 0 4px 12px -3px rgba(238, 111, 26, .5); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-alt); color: var(--text); border-color: var(--text-light); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #12692f; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a01f1f; color: #fff; }

/* A destructive action that is not the point of the screen. Reads as quiet
   until you reach for it — a row of solid red Remove buttons makes a list look
   like a warning. */
.btn-ghost-danger { background: transparent; color: var(--danger); border-color: var(--border-strong); }
.btn-ghost-danger:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }

.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: var(--radius-xs); }
.btn-lg { padding: 12px 24px; font-size: 14.5px; border-radius: var(--radius-sm); }
.btn-block { width: 100%; }

/* ============================================================================
   FORMS
   ============================================================================ */

.form-row { margin-bottom: var(--space-4); min-width: 0; }
.form-row label, label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--text); margin-bottom: var(--space-2);
}

.input, .form-input,
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=tel], input[type=search],
input[type=date], input[type=time], input[type=datetime-local],
select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-xs);
  font-family: var(--font-body); font-size: 13.5px; color: var(--text);
  background: var(--surface);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
textarea { line-height: 1.6; resize: vertical; min-height: 90px; }

.input:focus, .form-input:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--navy-500);
  box-shadow: var(--ring);
}
input::placeholder, textarea::placeholder { color: var(--text-light); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }

html[data-theme="dark"] .input,
html[data-theme="dark"] .form-input,
html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="email"],
html[data-theme="dark"] input[type="url"],
html[data-theme="dark"] input[type="tel"],
html[data-theme="dark"] input[type="search"],
html[data-theme="dark"] input[type="password"],
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] input[type="date"],
html[data-theme="dark"] input[type="time"],
html[data-theme="dark"] input[type="datetime-local"],
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: var(--surface-alt); color: var(--text); border-color: var(--border-strong);
}
html[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
html[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator,
html[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(.85);
}

.form-help { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; line-height: 1.6; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 5px; font-weight: 500; }

/* A row of buttons at the end of a form, wrapping instead of overflowing. */
.form-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }

/* ============================================================================
   TABLES
   ============================================================================ */

.table-wrap, .submissions-table, .table-scroll {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  /* Wide tables scroll inside their own box. Before this, they widened the
     page and every fixed element drifted out of place with it. */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

table.data, .data { width: 100%; border-collapse: collapse; }
.data th {
  text-align: left; padding: 11px var(--space-4);
  background: var(--surface-alt);
  font-size: 10.5px; font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.data td {
  padding: 12px var(--space-4);
  border-bottom: 1px solid var(--border);
  font-size: 13.5px; vertical-align: middle;
}
.data tr:last-child td { border-bottom: none; }
.data tbody tr { transition: background var(--fast) var(--ease); }
.data tbody tr:hover td { background: var(--surface-alt); }

/* ============================================================================
   BADGES
   ============================================================================ */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: var(--radius-pill);
  font-size: 10.5px; font-weight: 700; letter-spacing: .2px;
  white-space: nowrap; line-height: 1.5;
}
.badge-success { background: var(--success-bg); color: var(--success-dark); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-info    { background: var(--info-bg);    color: var(--navy-700); }
.badge-orange  { background: var(--orange-50);  color: var(--orange-600); }
.badge-navy    { background: var(--navy-50);    color: var(--navy-900); }
html[data-theme="dark"] .badge-success { color: var(--success); }
html[data-theme="dark"] .badge-info,
html[data-theme="dark"] .badge-navy { color: #93a7f5; }
html[data-theme="dark"] .badge-orange { background: var(--accent-soft); color: #ffa15c; }

/* ============================================================================
   MESSAGES / ALERTS
   ============================================================================ */

.message, .alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: 13.5px; line-height: 1.6;
  margin-bottom: var(--space-3);
  border: 1px solid transparent;
  border-left-width: 3px;
}
.message.success, .alert-success { background: var(--success-bg); border-color: var(--success); color: var(--success-dark); }
.message.warning, .alert-warning { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.message.danger, .alert-danger, .message.error { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.message.info, .alert-info { background: var(--info-bg); border-color: var(--info); color: var(--navy-700); }
html[data-theme="dark"] .message.success, html[data-theme="dark"] .alert-success { color: var(--success); }
html[data-theme="dark"] .message.info, html[data-theme="dark"] .alert-info { color: #93a7f5; }

/* ============================================================================
   PAGE HEADER
   ============================================================================ */

.page-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: var(--space-5); flex-wrap: wrap; gap: var(--space-4);
}
.page-header > div { min-width: 0; }
.page-header h2 { font-size: 21px; margin: 0; }
.page-header .meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ============================================================================
   UTILITIES
   ============================================================================ */

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12.5px; }
.text-center { text-align: center; }
.mb-2 { margin-bottom: var(--space-3); }
.mb-3 { margin-bottom: var(--space-5); }
.mt-1 { margin-top: var(--space-2); }
.mt-2 { margin-top: var(--space-4); }
.mt-3 { margin-top: var(--space-5); }
.stack   { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-lg { display: flex; flex-direction: column; gap: var(--space-5); }

code {
  background: var(--surface-sunk); color: var(--navy-700);
  padding: 2px 6px; border-radius: var(--radius-xs);
  font-size: 12.5px; font-family: var(--font-mono);
  overflow-wrap: anywhere;
}
html[data-theme="dark"] code { color: #93a7f5; }

.empty-state { padding: var(--space-8) var(--space-5); text-align: center; color: var(--text-muted); }

/* Content settles in rather than snapping. Applied to the immediate children of
   the page so a long list does not animate a hundred rows at once. */
.page-content > * { animation: fadeUp var(--slow) var(--ease) both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } }

/* ============================================================================
   TOPBAR CONTROLS
   ============================================================================ */

.theme-toggle, .notif-bell {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-muted); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease),
              border-color var(--fast) var(--ease);
}
.theme-toggle:hover, .notif-bell:hover {
  background: var(--surface-alt); color: var(--text); border-color: var(--border-strong);
}
html[data-theme="dark"] .theme-toggle { color: #ffd27a; }
.notif-bell { position: relative; color: var(--text); font-size: 18px; }
.notif-bell .notif-badge {
  position: absolute; top: -4px; right: -4px;
  background: #e0342c; color: #fff; font-size: 9.5px; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: var(--radius-pill);
  align-items: center; justify-content: center; padding: 0 4px;
  border: 2px solid var(--surface); line-height: 1;
}

/* ============================================================================
   CHAT POPUP  (was inline in base.html)
   ============================================================================ */

#chatPopup {
  display: none; position: fixed; right: var(--space-5); bottom: var(--space-5);
  width: 420px; height: 600px;
  max-width: calc(100vw - 32px); max-height: calc(100vh - 40px);
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-popup); overflow: hidden; flex-direction: column;
  border: 1px solid var(--border);
}
#chatPopup.open { display: flex; animation: popIn var(--slow) var(--ease) both; }
@keyframes popIn { from { opacity: 0; transform: translateY(12px) scale(.98); } }
#chatPopup .cp-head {
  background: var(--navy-900); color: #fff; padding: var(--space-3) var(--space-4);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; font-weight: 600; flex: none;
}
#chatPopup .cp-head .cp-actions { display: flex; align-items: center; gap: var(--space-3); }
#chatPopup .cp-head button, #chatPopup .cp-head a {
  background: none; border: none; color: #fff; cursor: pointer;
  font-size: 15px; text-decoration: none; line-height: 1;
}
#chatPopup .cp-body { flex: 1; position: relative; overflow: hidden; }
#chatPopup iframe { border: none; width: 100%; height: 100%; display: block; }
#chatPopup .cp-loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 13px; background: var(--surface);
}

/* Chat rendered inside the popup's iframe — hide the app chrome. */
body.embed-mode .sidebar,
body.embed-mode .topbar,
body.embed-mode .nav-backdrop,
body.embed-mode #chatPopup { display: none !important; }
body.embed-mode .main-content { margin: 0 !important; }
body.embed-mode .page-content { padding: 0 !important; }

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 1100px) {
  .page-content { padding: var(--space-4) var(--space-5) var(--space-7); }
  .topbar { padding: var(--space-3) var(--space-5); }
}

@media (max-width: 880px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--slow) var(--ease);
    z-index: var(--z-drawer);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .nav-toggle { display: inline-flex; }
  .topbar { padding: var(--space-3) var(--space-4); gap: var(--space-3); }
  .topbar .topbar-user { display: none; }
  .page-content { padding: var(--space-4) var(--space-4) var(--space-7); }
  .stat-card .stat-value { font-size: 27px; }
  #chatPopup { right: 0; bottom: 0; width: 100vw; height: 100vh;
               max-width: 100vw; max-height: 100vh; border-radius: 0; border: none; }
}

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); }
  .card { padding: var(--space-4); }
  .page-header { align-items: flex-start; }
  .btn { padding: 9px 14px; }
  #live-clock { display: none; }
}

@media print {
  .sidebar, .topbar, #chatPopup, .nav-backdrop, .btn { display: none !important; }
  .main-content { margin: 0 !important; }
  .card { box-shadow: none; border-color: #ccc; }
}

/* ============================================================================
   DARK MODE — catch-all for inline-styled content.

   Many older pages carry inline `style="background:#fff"` / `color:#666`.
   Inline styles beat normal CSS, so these attribute selectors with !important
   are the only thing that can reach them. New markup should use tokens and
   never need this section; it exists so the pages written before dark mode
   stay readable rather than being rewritten all at once.
   ============================================================================ */

html[data-theme="dark"] h1, html[data-theme="dark"] h2, html[data-theme="dark"] h3,
html[data-theme="dark"] h4, html[data-theme="dark"] h5, html[data-theme="dark"] h6,
html[data-theme="dark"] .page-title, html[data-theme="dark"] .section-title,
html[data-theme="dark"] .card-title, html[data-theme="dark"] .stat-card .stat-value,
html[data-theme="dark"] .topbar .topbar-user .name { color: var(--text); }
html[data-theme="dark"] table { color: var(--text); }
html[data-theme="dark"] th { color: var(--text-muted); }

html[data-theme="dark"] [style*="background:#fff"],
html[data-theme="dark"] [style*="background: #fff"],
html[data-theme="dark"] [style*="background:white"],
html[data-theme="dark"] [style*="background: white"],
html[data-theme="dark"] [style*="background-color:#fff"],
html[data-theme="dark"] [style*="background-color: #fff"],
html[data-theme="dark"] [style*="background:#ffffff"],
html[data-theme="dark"] [style*="background: #ffffff"] {
  background: var(--surface) !important;
  border-color: var(--border) !important;
}
html[data-theme="dark"] [style*="background:#f8f9fa"],
html[data-theme="dark"] [style*="background: #f8f9fa"],
html[data-theme="dark"] [style*="background:#f9fafb"],
html[data-theme="dark"] [style*="background:#f5f5f5"],
html[data-theme="dark"] [style*="background:#fafafa"],
html[data-theme="dark"] [style*="background:#f4f6fb"],
html[data-theme="dark"] [style*="background:#eef"],
html[data-theme="dark"] [style*="background:#f0f"] {
  background: var(--surface-alt) !important;
}

html[data-theme="dark"] [style*="color:#000"],
html[data-theme="dark"] [style*="color: #000"],
html[data-theme="dark"] [style*="color:#111"],
html[data-theme="dark"] [style*="color:#222"],
html[data-theme="dark"] [style*="color:#333"],
html[data-theme="dark"] [style*="color: #333"],
html[data-theme="dark"] [style*="color:#1b2a6b"],
html[data-theme="dark"] [style*="color:var(--navy-900)"],
html[data-theme="dark"] [style*="color:var(--navy-800)"],
html[data-theme="dark"] [style*="color:var(--navy-700)"] {
  color: var(--text) !important;
}
html[data-theme="dark"] [style*="color:#444"],
html[data-theme="dark"] [style*="color:#555"],
html[data-theme="dark"] [style*="color:#666"],
html[data-theme="dark"] [style*="color: #666"],
html[data-theme="dark"] [style*="color:#777"],
html[data-theme="dark"] [style*="color:#888"],
html[data-theme="dark"] [style*="color: #888"],
html[data-theme="dark"] [style*="color:#999"],
html[data-theme="dark"] [style*="color:#aaa"] {
  color: var(--text-muted) !important;
}

html[data-theme="dark"] [style*="border:1px solid #f0f0f0"],
html[data-theme="dark"] [style*="border:1px solid #eee"],
html[data-theme="dark"] [style*="border-bottom:1px solid #f0f0f0"],
html[data-theme="dark"] [style*="border-top:1px solid #f0f0f0"],
html[data-theme="dark"] td[style*="border"],
html[data-theme="dark"] tr[style*="border"] {
  border-color: var(--border) !important;
}

/* ── Taking your own submission back (core.withdrawal) ──────────────────
   Shown on the detail page of anything the person filed themselves while
   the ten-day window is still open. Quiet on purpose: this is an exit, not
   an action anybody should be nudged towards. */
.withdraw-box {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}
.withdraw-box h3 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
}
.withdraw-box p {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}
.btn-outline-danger {
  display: inline-block;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-outline-danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ── Show-password eye ──────────────────────────────────────────────────
   The button sits INSIDE the field's box rather than beside it, so the form
   keeps its column alignment on the narrow auth screens. Padding on the right
   of the input keeps long passwords from running under the icon. */
.pw-wrap { position: relative; display: block; }
.pw-wrap > input { width: 100%; padding-right: 40px; }
.pw-eye {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
}
.pw-eye:hover { color: var(--text); background: var(--surface-sunk); }
.pw-eye:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── Activity chip: one colour + icon per link-building type (backlinks/styles.py) ── */
.act-pill { display:inline-flex; align-items:center; gap:5px; padding:3px 9px 3px 7px; border-radius:999px;
  font-size:12px; font-weight:600; line-height:1.3; white-space:nowrap;
  color:var(--act); background:color-mix(in srgb, var(--act) 10%, #fff);
  border:1px solid color-mix(in srgb, var(--act) 22%, #fff); }
.act-pill i { font-size:14px; }

/* Upload a file, or paste a snip (base.html) */
.snap-pair { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:4px; }
.snap-box { position:relative; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:4px;
  min-height:128px; padding:14px 12px; border:1.5px dashed #c4cad4; border-radius:12px; background:var(--surface, #fff);
  text-align:center; cursor:pointer; transition:border-color .15s, background .15s, box-shadow .15s; }
.snap-box:hover { border-color:var(--accent, #f97316); background:var(--accent-soft, #fff7ed); }
.snap-box.on { border-color:var(--accent, #f97316); border-style:solid; background:var(--accent-soft, #fff7ed); }
.snap-paste:focus { outline:none; border-style:solid; border-color:var(--accent, #f97316);
  background:var(--accent-soft, #fff7ed); box-shadow:0 0 0 3px rgba(249,115,22,.18); }
.snap-ico { display:grid; place-items:center; width:36px; height:36px; border-radius:10px; font-size:19px;
  background:#f2f4f7; color:#475467; margin-bottom:2px; }
.snap-paste .snap-ico { background:var(--accent-soft, #fff7ed); color:var(--accent, #f97316); }
.snap-h { font-size:13.5px; font-weight:700; color:var(--text, #101828); }
.snap-s { font-size:12px; color:var(--text-muted, #667085); }
.snap-file { font-size:12px; color:var(--text-muted, #667085); max-width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.snap-pair.has .snap-file { color:#067647; font-weight:600; }
.snap-steps { margin:2px 0 0; padding:0 0 0 18px; text-align:left; font-size:12px; line-height:1.7; color:#475467; }
.snap-steps kbd, .snap-ready kbd { display:inline-block; padding:0 5px; border:1px solid #d0d5dd; border-bottom-width:2px;
  border-radius:4px; background:#fff; font-size:11px; font-weight:600; line-height:1.5; color:#344054; }
.snap-ready { display:none; font-size:12.5px; font-weight:700; color:var(--accent, #f97316); }
.snap-paste:focus .snap-steps { display:none; }
.snap-paste:focus .snap-ready { display:block; }
.snap-input { position:absolute; width:1px; height:1px; opacity:0; overflow:hidden; clip:rect(0 0 0 0); }
.snap-preview { display:none; grid-column:1 / -1; align-items:center; gap:10px; padding:8px; border:1px solid #abefc6;
  background:#f6fef9; border-radius:10px; }
.snap-pair.has-img .snap-preview { display:flex; }
.snap-preview img { max-height:120px; max-width:60%; border-radius:6px; border:1px solid var(--border, #e4e7ec); }
.snap-clear { margin-left:auto; appearance:none; border:1px solid #d0d5dd; background:#fff; border-radius:8px;
  padding:5px 10px; font:inherit; font-size:12.5px; cursor:pointer; color:#344054; }
.snap-clear:hover { background:#f9fafb; }
@media (max-width:640px) { .snap-pair { grid-template-columns:1fr; } .snap-paste { display:none; } }
