/* ─── Traffic — design tokens + app shell (htmx starter) ─────────── */

:root {
  --sidebar-w:    240px;
  --sidebar-rail: 68px;

  /* surfaces */
  --bg:           #FAFAFA;
  --surface:      #FFFFFF;
  --surface-2:    #F4F4F5;
  --surface-3:    #EFEFF1;

  /* borders */
  --border:       #E4E4E7;
  --border-2:     #D4D4D8;
  --hairline:     rgba(9,9,11,0.06);

  /* text */
  --text:         #09090B;
  --text-2:       #52525B;
  --text-3:       #71717A;
  --text-4:       #A1A1AA;
  --text-on-ink:  #FFFFFF;

  /* primary accent: brand-blue. Used by primary buttons, brand mark,
     and wizard "active" step indicator — a single accent in both themes. */
  --ink:          #2563EB;
  --ink-hover:    #1D4ED8;

  --green:        #16A34A;
  --green-bg:     #F0FDF4;
  --green-border: #BBF7D0;

  --amber:        #B45309;
  --amber-bg:     #FFFBEB;
  --amber-border: #FDE68A;

  --red:          #B91C1C;
  --red-bg:       #FEF2F2;
  --red-border:   #FECACA;

  --blue:         #1D4ED8;
  --blue-bg:      #EFF6FF;
  --blue-border:  #BFDBFE;

  /* elevation */
  --shadow-xs: 0 1px 2px rgba(9,9,11,0.04);
  --shadow-sm: 0 1px 2px rgba(9,9,11,0.04), 0 1px 3px rgba(9,9,11,0.05);
  --shadow-md: 0 2px 4px rgba(9,9,11,0.04), 0 4px 8px rgba(9,9,11,0.04);
  --shadow-lg: 0 4px 6px -2px rgba(9,9,11,0.06), 0 10px 15px -3px rgba(9,9,11,0.06);

  /* radius */
  --r-sm: 4px;
  --r:    6px;
  --r-lg: 8px;
  --r-xl: 10px;

  color-scheme: light;
}

[data-theme="dark"] {
  /* surfaces */
  --bg:           #09090B;
  --surface:      #18181B;
  --surface-2:    #1F1F22;
  --surface-3:    #27272A;

  /* borders */
  --border:       #27272A;
  --border-2:     #3F3F46;
  --hairline:     rgba(255,255,255,0.06);

  /* text */
  --text:         #FAFAFA;
  --text-2:       #D4D4D8;
  --text-3:       #A1A1AA;
  --text-4:       #71717A;
  --text-on-ink:  #FFFFFF;

  /* primary accent in dark mode: brand-blue instead of pure white,
     so CTAs read as "primary" without punching through the dark UI.
     Brand mark, primary buttons and wizard "active" step all inherit
     this through var(--ink). */
  --ink:          #3B82F6;
  --ink-hover:    #60A5FA;

  --green:        #4ADE80;
  --green-bg:     rgba(34,197,94,0.12);
  --green-border: rgba(74,222,128,0.30);

  --amber:        #FBBF24;
  --amber-bg:     rgba(245,158,11,0.12);
  --amber-border: rgba(251,191,36,0.30);

  --red:          #F87171;
  --red-bg:       rgba(239,68,68,0.12);
  --red-border:   rgba(248,113,113,0.30);

  --blue:         #60A5FA;
  --blue-bg:      rgba(59,130,246,0.14);
  --blue-border:  rgba(96,165,250,0.32);

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.40);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.40), 0 1px 3px rgba(0,0,0,0.45);
  --shadow-md: 0 2px 4px rgba(0,0,0,0.40), 0 4px 8px rgba(0,0,0,0.40);
  --shadow-lg: 0 4px 6px -2px rgba(0,0,0,0.50), 0 10px 15px -3px rgba(0,0,0,0.55);

  color-scheme: dark;
}

/* ─── nav progress (loading indicator for navigation) ──────────────
   Thin bar at the top of the screen: shows that a page is loading when
   the network is slow. Driven by HTMX events (see htmx-shell.js). */
.nav-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2.5px;
  z-index: 9999;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: var(--ink);
  box-shadow: 0 0 8px var(--ink), 0 0 3px var(--ink);
  opacity: 0;
  pointer-events: none;
  transition: transform 220ms ease;
}
.nav-progress.is-active { opacity: 1; }
.nav-progress.is-done {
  opacity: 0;
  transition: transform 160ms ease, opacity 260ms ease 80ms;
}
@media (prefers-reduced-motion: reduce) {
  .nav-progress { transition-duration: 80ms; }
}

[data-theme="dark"] ::selection { background: rgba(96,165,250,0.35); color: var(--text); }

[data-theme="dark"] .workspace .avatar {
  background: linear-gradient(135deg, #52525B 0%, #27272A 100%);
}

/* theme toggle button */
.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-3);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 80ms ease, color 80ms ease, border-color 80ms ease;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }
.theme-toggle svg { display: block; }
.theme-toggle .ic-sun  { display: none; }
.theme-toggle .ic-moon { display: block; }
[data-theme="dark"] .theme-toggle .ic-sun  { display: block; }
[data-theme="dark"] .theme-toggle .ic-moon { display: none; }

[x-cloak] { display: none !important; }

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  font-feature-settings: 'ss01' on, 'cv11' on, 'cv05' on, 'tnum' on, 'ss03' on;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
ul { list-style: none; }

.mono, code, .num {
  font-family: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, monospace;
  font-feature-settings: 'tnum' on, 'zero' on;
}

::selection { background: #DCE9FF; color: var(--text); }

/* ─── app shell ──────────────────────────────────────────────── */

.app {
  min-height: 100vh;
  transition: padding-left 200ms ease;
}

@media (min-width: 768px) {
  .app {
    padding-left: var(--sidebar-w);
  }
}

.app.sidebar-collapsed {
  --sidebar-w: var(--sidebar-rail);
}

/* ─── sidebar ────────────────────────────────────────────────── */

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  min-width: 0;
  z-index: 40;
  overflow: hidden;
  transition: transform 220ms ease, box-shadow 220ms ease, padding 200ms ease, width 200ms ease;
}

@media (min-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-w);
    overscroll-behavior: contain;
  }
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(9, 9, 11, 0.4);
  z-index: 35;
  opacity: 0;
  transition: opacity 220ms ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  min-width: 0;
  flex-shrink: 0;
}

.brand-home {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  border-radius: var(--r-sm);
  margin: -4px;
  padding: 4px;
  transition: background 80ms ease;
}
.brand-home:hover {
  background: var(--surface-2);
}
.brand-home:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-collapse-btn {
  margin-left: auto;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-3);
  transition: background 80ms ease, color 80ms ease;
}
.sidebar-collapse-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.sidebar-collapse-btn svg { display: block; }

.brand-mark {
  width: 22px; height: 22px;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}

.brand-text {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-text small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex-shrink: 0;
}

.nav-label {
  font-size: 11px;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 16px 8px 6px;
  font-weight: 500;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 450;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
}
.nav a .ic { color: var(--text-3); }
.nav a.active .ic { color: var(--text); }

.nav a .count {
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-4);
}

.sidebar-spacer { flex: 1 1 auto; min-height: 0; max-height: 100%; }

.workspace-wrap {
  position: relative;
  margin-top: 12px;
  flex-shrink: 0;
}

.workspace {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: inherit;
  text-align: left;
  font: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 80ms ease, border-color 80ms ease;
}
.workspace:hover { background: var(--surface-2); }
.workspace[aria-expanded="true"] { background: var(--surface-2); border-color: var(--border-2); }
.workspace .avatar {
  width: 28px; height: 28px;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, #18181B 0%, #52525B 100%);
  color: #fff;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
  letter-spacing: -0.02em;
}
.workspace .who { flex: 1; min-width: 0; line-height: 1.2; }
.workspace .who .name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.workspace .who .email {
  font-size: 11px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.workspace .chev { color: var(--text-4); margin-left: 4px; flex-shrink: 0; }

/* user-menu popover */
.user-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  box-shadow: var(--shadow-md);
  z-index: 50;
}
.user-menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 6px;
  min-height: 32px;
}
.user-menu-label {
  font-size: 13px;
  color: var(--text-2);
}
.theme-seg {
  display: inline-flex;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  gap: 2px;
}
.theme-seg-btn {
  display: grid;
  place-items: center;
  width: 26px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 3px;
  color: var(--text-3);
  cursor: pointer;
  transition: background 80ms ease, color 80ms ease;
}
.theme-seg-btn:hover { color: var(--text); }
.theme-seg-btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border-2), var(--shadow-sm);
}
/* dark: --surface is darker than --surface-2, so the active pill gets lost —
   substitute the lighter --border-2 for contrast. */
[data-theme="dark"] .theme-seg-btn.is-active {
  background: var(--border-2);
  box-shadow: none;
}
.theme-seg-btn svg { display: block; }

/* icon rail — desktop collapsed + tablet narrow (class set in app.js) */
.app.sidebar-rail .brand-text,
.app.sidebar-rail .nav-text,
.app.sidebar-rail .nav a .count,
.app.sidebar-rail .workspace .who,
.app.sidebar-rail .workspace .chev {
  display: none;
}

.app.sidebar-rail .sidebar {
  padding: 12px 10px;
  overflow-x: hidden;
}

.app.sidebar-rail .brand {
  justify-content: center;
  align-items: center;
  gap: 0;
  width: 100%;
  padding: 4px 0 12px;
  margin: 0 0 8px;
  background: transparent;
  border-radius: 0;
}

.app.sidebar-rail .brand-home {
  display: none;
}

.app.sidebar-rail .sidebar-collapse-btn {
  margin: 0;
}

.app.sidebar-rail .nav {
  gap: 2px;
}

.app.sidebar-rail .nav a {
  justify-content: center;
  padding: 9px 6px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.app.sidebar-rail .nav a .ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.app.sidebar-rail .workspace-wrap {
  margin-top: 8px;
}

.app.sidebar-rail .workspace {
  justify-content: center;
  padding: 10px 6px 4px;
  border: none;
  background: transparent;
}
.app.sidebar-rail .workspace[aria-expanded="true"] {
  background: var(--surface-2);
  border-color: transparent;
}

.app.sidebar-rail .workspace .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
}

/* rail mode: the popover does not fit the narrow sidebar (overflow:hidden),
   so it is rendered just to the right via fixed positioning. */
.app.sidebar-rail .user-menu {
  position: fixed;
  left: calc(var(--sidebar-rail) + 6px);
  right: auto;
  bottom: 12px;
  min-width: 220px;
}

/* ─── mobile header ──────────────────────────────────────────── */

.mobile-header {
  display: none;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.sidebar-open-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-2);
  flex-shrink: 0;
}
.sidebar-open-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.sidebar-open-btn svg { display: block; }

.mobile-header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── main area ──────────────────────────────────────────────── */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-3);
}
.crumbs a { color: var(--text-2); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { color: var(--text-4); }
.crumbs .current { color: var(--text); font-weight: 500; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kbd {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-3);
  background: var(--surface);
}

.content {
  padding: 24px;
  max-width: 1320px;
  width: 100%;
  min-width: 0;
}

/* ─── page head ──────────────────────────────────────────────── */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.page-head h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}

.page-head .sub {
  margin-top: 4px;
  font-size: 13.5px;
  color: var(--text-3);
}

.page-head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.page-head > div:first-child {
  flex: 1;
  min-width: 0;
}

/* ─── buttons ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--r);
  box-shadow: var(--shadow-xs);
  transition: background 80ms ease, border-color 80ms ease, box-shadow 80ms ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-2); }

.btn-primary {
  background: var(--ink);
  color: var(--text-on-ink);
  border-color: var(--ink);
}
.btn-primary:hover { background: var(--ink-hover); border-color: var(--ink-hover); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  color: var(--red);
  background: var(--red-bg);
  border-color: var(--red-border);
}
.btn-danger:hover {
  color: var(--red);
  background: var(--red-bg);
  border-color: var(--red);
}

.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }

.btn .ic { color: var(--text-3); }
.btn-primary .ic { color: var(--text-on-ink); opacity: 0.8; }

/* ─── card ───────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.card-head h3 {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.card-head .meta {
  font-size: 12px;
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
}

.card-body { padding: 16px; }
.card-body-tight { padding: 0; }

/* ─── search input ───────────────────────────────────────────── */

.searchbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-xs);
  min-width: 280px;
}
.searchbar input {
  border: none; background: transparent;
  font-size: 13px;
  width: 100%;
  outline: none;
}
.searchbar input::placeholder { color: var(--text-4); }
.searchbar .ic { color: var(--text-4); }

/* ─── filters row ────────────────────────────────────────────── */

.row-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.row-tools-left { display: flex; gap: 8px; align-items: center; }
.row-tools-right { display: flex; gap: 8px; align-items: center; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--text-2);
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
}
.chip:hover { background: var(--surface-2); }
.chip .num { color: var(--text-3); }

.stat {
  font-size: 12px;
  color: var(--text-3);
}
.stat strong { color: var(--text); font-weight: 500; }

/* ─── tables ─────────────────────────────────────────────────── */

table.data {
  width: 100%;
  border-collapse: collapse;
}

table.data thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.01em;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 48px;
}

table.data thead th:first-child { border-top-left-radius: var(--r-lg); }
table.data thead th:last-child  { border-top-right-radius: var(--r-lg); }

table.data tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13.5px;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }

table.data td.num,
table.data th.num { text-align: right; font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }

.partner-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  color: var(--text);
}
.partner-name .avatar-sm {
  width: 24px; height: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  font-size: 11px;
  color: var(--text-2);
  font-weight: 600;
}
.partner-name .secondary {
  font-weight: 400;
  font-size: 12px;
  color: var(--text-3);
}

/* ─── pills / status ─────────────────────────────────────────── */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  font-size: 11.5px;
  font-weight: 500;
  border-radius: 999px;
  border: 1px solid;
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--border);
}
.pill::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}
.pill.green { color: var(--green); background: var(--green-bg); border-color: var(--green-border); }
.pill.amber { color: var(--amber); background: var(--amber-bg); border-color: var(--amber-border); }
.pill.red   { color: var(--red);   background: var(--red-bg);   border-color: var(--red-border); }
.pill.blue  { color: var(--blue);  background: var(--blue-bg);  border-color: var(--blue-border); }


/* ─── small helpers ──────────────────────────────────────────── */

.muted { color: var(--text-3); }
.faint { color: var(--text-4); }
.right { text-align: right; }
.flex { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }

.ic { display: inline-block; line-height: 0; flex-shrink: 0; }
.ic svg { display: block; }

/* tooltip-like inline note */

.note-card {
  padding: 12px 16px;
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
  border-radius: var(--r);
  font-size: 12.5px;
  color: var(--blue);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.5;
}

/* ─── responsive (shell only) ────────────────────────────────── */

@media (max-width: 1024px) {
  .page-head { flex-direction: column; align-items: stretch; gap: 14px; }
  .page-head-actions { width: 100%; justify-content: flex-start; }
}

/* tablet: narrow icon rail by default, expanded via .sidebar-expanded */
@media (min-width: 768px) and (max-width: 1024px) {
  .app:not(.sidebar-expanded):not(.sidebar-open) {
    --sidebar-w: var(--sidebar-rail);
  }
}

@media (max-width: 767px) {
  .app { padding-left: 0; }
  .sidebar-backdrop { display: block; pointer-events: none; }
  .app.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .sidebar {
    position: fixed; left: 0; top: 0;
    width: min(280px, 88vw);
    transform: translateX(-105%);
    box-shadow: none; padding-top: 12px;
  }
  .app.sidebar-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-collapse-btn { display: none; }
  .mobile-header { display: flex; }
  .content { padding: 16px; }
  .page-head { flex-direction: column; gap: 12px; padding-bottom: 16px; margin-bottom: 16px; }
  .page-head-actions { width: 100%; flex-wrap: wrap; }
  .row-tools { flex-direction: column; align-items: stretch; }
  .row-tools-left, .row-tools-right { flex-wrap: wrap; }
  .searchbar { min-width: 0; width: 100%; }
  table.data { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.data.report { display: table; }
  table.data.report .name { width: 170px; min-width: 170px; max-width: 170px; }
}

@media (max-width: 640px) {
  .page-head h1 { font-size: 20px; overflow-wrap: anywhere; }
  .page-head .sub { font-size: 12.5px; line-height: 1.45; }
  .page-head-actions { flex-direction: column; align-items: stretch; }
  .page-head-actions .btn { width: 100%; justify-content: center; }
}

/* drawer open on mobile: always show full labels */
.app.sidebar-open .brand-text,
.app.sidebar-open .nav-text,
.app.sidebar-open .nav a .count,
.app.sidebar-open .workspace .who,
.app.sidebar-open .workspace .chev { display: revert; }
.app.sidebar-open .brand { justify-content: flex-start; padding-left: 8px; padding-right: 8px; }
.app.sidebar-open .nav a { justify-content: flex-start; padding-left: 8px; padding-right: 8px; }
.app.sidebar-open .workspace { justify-content: flex-start; padding: 8px; }

/* ─── sign-in screen (/login) ────────────────────────────────── */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 28px 24px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.auth-brand .brand-mark { width: 32px; height: 32px; border-radius: 8px; }
.auth-brand .brand-text { font-weight: 600; line-height: 1.1; }
.auth-brand .brand-text small {
  display: block;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-weight: 500;
}
.auth-title { font-size: 19px; font-weight: 600; margin: 0 0 4px; }
.auth-sub { font-size: 13px; margin: 0 0 18px; }
.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-size: 12px; font-weight: 500; color: var(--text-2); }
.auth-form input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  outline: none;
  font-size: 14px;
}
.auth-form input:hover { border-color: var(--border-2); }
.auth-form input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(24,24,27,0.06); }
.auth-code { letter-spacing: 0.35em; text-align: center; font-size: 18px; }
.auth-submit { width: 100%; height: 38px; justify-content: center; margin-top: 8px; }
.auth-resend { margin-top: 12px; display: flex; justify-content: center; }
.auth-actions { margin-top: 12px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.auth-actions .auth-resend { margin-top: 0; }
a.auth-back { text-decoration: none; }
.auth-error {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red);
  border-radius: var(--r);
  padding: 8px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
}
.auth-dev {
  background: var(--surface-2);
  border: 1px dashed var(--border-2);
  color: var(--text-2);
  border-radius: var(--r);
  padding: 8px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* logout row in the user menu */
.logout-form { width: 100%; }
.logout-btn { width: 100%; justify-content: flex-start; }

/* ─── portal pages (dashboard, channels, lander, people) ─────────── */

.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
a.tool-card { display: block; padding: 18px; text-decoration: none; color: inherit; transition: border-color 80ms ease, box-shadow 80ms ease; }
a.tool-card:hover { border-color: var(--border-2); box-shadow: var(--shadow-sm); }
.tool-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.tool-card p { font-size: 13px; color: var(--text-3); line-height: 1.5; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 11.5px; font-weight: 500; color: var(--text-3); }
.field-grow { flex: 1 1 360px; }
.input {
  height: 32px; padding: 0 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow-xs); font-size: 13px; outline: none; width: 100%;
}
.input:hover { border-color: var(--border-2); }
.input:focus { border-color: var(--ink); }
.input-cc { width: 72px; text-transform: uppercase; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); height: 32px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 12px 14px; }
.kpi .label { font-size: 11.5px; color: var(--text-3); }
.kpi .value { font-size: 19px; font-weight: 600; margin-top: 2px; font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }

table.data tr.totals td { font-weight: 600; background: var(--surface-2); }
table.data tbody.pair tr.pair-main { cursor: pointer; }
table.data tr.series td { background: var(--surface-2); font-size: 12.5px; padding-top: 6px; padding-bottom: 6px; }
table.data tr.series td:first-child { padding-left: 36px; }
.twisty { display: inline-block; width: 14px; color: var(--text-4); transition: transform 120ms ease; }
.twisty.open { transform: rotate(90deg); }
.pair-name { font-weight: 500; }
.pair-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.kpi .sub { font-size: 11.5px; color: var(--text-3); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* channel report: wide table, FB / Google / итог header groups (as in the ironfli original).
   One line per pair: the name is cut with an ellipsis (full name in the tooltip). */
.report-tools { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 12.5px; }
.report-tools .input { width: 280px; max-width: 100%; }
.report-wrap { overflow: auto; max-height: calc(100vh - 140px); }
table.data.report { width: auto; min-width: 100%; border-collapse: separate; border-spacing: 0; }
table.data.report th, table.data.report td { white-space: nowrap; text-align: right;
  font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
table.data.report td { padding: 5px 8px; font-size: 12.5px; border-bottom: 1px solid var(--border); }
table.data.report .l { text-align: left; font-family: inherit; }
table.data.report thead th { position: sticky; z-index: 3; padding: 0 8px; height: 28px; border-radius: 0;
  background: var(--surface-2); font-family: inherit; }
table.data.report thead tr.grp th { top: 0; height: 24px; text-align: center; font-size: 10.5px;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-2); border-bottom: none; }
table.data.report thead tr.cols th { top: 24px; }
table.data.report thead tr.totals th { top: 52px; height: 30px; color: var(--text); font-weight: 600; font-size: 12.5px;
  font-family: 'JetBrains Mono', monospace; box-shadow: inset 0 -1px 0 var(--border-2); }
table.data.report thead th a { color: inherit; text-decoration: none; display: block; }
table.data.report thead th.on { color: var(--text); }
table.data.report .b { border-left: 1px solid var(--border); }
table.data.report .name { position: sticky; left: 0; z-index: 1; text-align: left; font-family: inherit;
  width: 290px; min-width: 290px; max-width: 290px; background: var(--surface); box-shadow: inset -1px 0 0 var(--border); }
table.data.report thead th.name { z-index: 4; background: var(--surface-2); }
table.data.report tr.pair-main { cursor: pointer; }
table.data.report tr.pair-main:hover td, table.data.report tr.pair-main.open td { background: var(--surface-2); }
table.data.report tr.series td { background: var(--surface-2); font-size: 12px; padding-top: 3px; padding-bottom: 3px; color: var(--text-2); }
table.data.report tr.series td.name { padding-left: 30px; font-family: 'JetBrains Mono', monospace; }
table.data.report .pair-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 500; }
table.data.report .pair-name .nm { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
table.data.report .pair-sub { overflow: hidden; text-overflow: ellipsis; padding-left: 20px; margin-top: 1px; font-size: 11.5px; }
table.data.report tr.open .twisty { transform: rotate(90deg); }
.tag { flex: none; font-size: 10.5px; line-height: 16px; padding: 0 5px; border-radius: 4px; font-weight: 500;
  font-family: inherit; }
.tag.red { color: var(--red); background: var(--red-bg); }
.tag.amber { color: var(--amber); background: var(--amber-bg); }

.alert { padding: 12px 16px; border-radius: var(--r); border: 1px solid; font-size: 13px; line-height: 1.5; margin-bottom: 16px; }
.alert.red { color: var(--red); background: var(--red-bg); border-color: var(--red-border); }
.alert.amber { color: var(--amber); background: var(--amber-bg); border-color: var(--amber-border); }
.empty { padding: 32px 16px; text-align: center; color: var(--text-3); font-size: 13.5px; line-height: 1.6; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { min-width: 0; overflow-wrap: anywhere; }
.htmx-indicator { opacity: 0; transition: opacity 150ms ease; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.shot-thumb { max-width: 120px; max-height: 90px; border: 1px solid var(--border); border-radius: var(--r-sm); display: block; }
.stack > * + * { margin-top: 16px; }
