/* ==========================================================================
   BotShop admin - design tokens
   Dark-first palette, 4px spacing base, 1.25 modular type scale.
   ========================================================================== */

:root {
  /* Surfaces: each step up is a lighter elevation layer */
  --surface-sunken: #06080d;
  --surface-canvas: #0a0d14;
  --surface-raised: #11151f;
  --surface-overlay: #171d29;
  --surface-hover: #1d2430;

  --border-subtle: #1e2532;
  --border-strong: #2c3544;
  --border-focus: #4c8dff;

  --text-primary: #e9edf5;
  --text-secondary: #97a2b6;
  --text-tertiary: #68718a;
  --text-inverse: #06080d;

  --brand-400: #7cadff;
  --brand-500: #4c8dff;
  --brand-600: #3576e3;
  --brand-soft: rgba(76, 141, 255, 0.14);

  --success-500: #2fc37d;
  --success-soft: rgba(47, 195, 125, 0.14);
  --warning-500: #efb02a;
  --warning-soft: rgba(239, 176, 42, 0.14);
  --danger-500: #f05a52;
  --danger-soft: rgba(240, 90, 82, 0.14);
  --info-500: #3cbdf0;
  --info-soft: rgba(60, 189, 240, 0.14);

  /* Spacing scale */
  --sp-2xs: 2px;
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 32px;
  --sp-2xl: 48px;
  --sp-3xl: 64px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-full: 999px;

  /* Type scale */
  --fs-caption: 12px;
  --fs-sm: 13px;
  --fs-body: 15px;
  --fs-sub: 18px;
  --fs-h3: 22px;
  --fs-h2: 28px;
  --fs-h1: 34px;

  --lh-tight: 1.25;
  --lh-normal: 1.55;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.45);

  --sidebar-w: 264px;
  --topbar-h: 64px;
  --container-max: 1440px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--surface-canvas);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: var(--fs-body);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--brand-400);
  text-decoration: none;
}

a:hover {
  color: var(--brand-500);
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: var(--lh-tight);
  letter-spacing: -0.015em;
}

code,
.mono {
  font-family: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
  font-size: var(--fs-sm);
}

svg.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

svg.icon-sm {
  width: 15px;
  height: 15px;
}

/* ============================================================ app shell */

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface-sunken);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: var(--sp-lg) var(--sp-lg) var(--sp-md);
  border-bottom: 1px solid var(--border-subtle);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
  display: grid;
  place-items: center;
  color: #fff;
}

.brand-text strong {
  display: block;
  font-size: var(--fs-body);
  letter-spacing: -0.01em;
}

.brand-text span {
  font-size: var(--fs-caption);
  color: var(--text-tertiary);
}

.nav {
  padding: var(--sp-md) var(--sp-sm);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2xs);
  overflow-y: auto;
  flex: 1;
}

.nav-label {
  padding: var(--sp-md) var(--sp-md) var(--sp-sm);
  font-size: var(--fs-caption);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 10px var(--sp-md);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-size: var(--fs-body);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.nav-item:hover {
  background: var(--surface-raised);
  color: var(--text-primary);
}

.nav-item.is-active {
  background: var(--brand-soft);
  color: var(--brand-400);
  box-shadow: inset 2px 0 0 var(--brand-500);
}

.sidebar-foot {
  padding: var(--sp-md);
  border-top: 1px solid var(--border-subtle);
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  padding: 0 var(--sp-xl);
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(10, 13, 20, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 {
  font-size: var(--fs-sub);
  font-weight: 600;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
}

.content {
  padding: var(--sp-xl);
  max-width: var(--container-max);
  width: 100%;
}

.menu-toggle {
  display: none;
}

/* ============================================================= typography */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-md);
  margin-bottom: var(--sp-lg);
  flex-wrap: wrap;
}

.page-head h2 {
  font-size: var(--fs-h2);
  font-weight: 650;
}

.page-head p {
  margin: var(--sp-xs) 0 0;
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  max-width: 68ch;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  margin-bottom: var(--sp-md);
}

.section-head h3 {
  font-size: var(--fs-sub);
  font-weight: 600;
}

.muted {
  color: var(--text-secondary);
}

.dim {
  color: var(--text-tertiary);
}

.caption {
  font-size: var(--fs-caption);
  color: var(--text-tertiary);
}

/* ================================================================== grid */

.grid {
  display: grid;
  gap: var(--sp-md);
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: var(--sp-lg);
  align-items: start;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-lg);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  flex-wrap: wrap;
}

.row-tight {
  gap: var(--sp-xs);
}

.push {
  margin-left: auto;
}

/* ================================================================= cards */

.card {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
}

.card-flush {
  padding: 0;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  padding: var(--sp-md) var(--sp-lg);
  border-bottom: 1px solid var(--border-subtle);
}

.card-head h3 {
  font-size: var(--fs-body);
  font-weight: 600;
}

.card-body {
  padding: var(--sp-lg);
}

/* Alert card: the border carries the warning so the surface stays readable,
   unlike a tinted background that fights the text underneath it. */
.card-alert {
  border-color: var(--danger-500);
  background: linear-gradient(var(--danger-soft), var(--danger-soft)), var(--surface-raised);
}

.text-danger {
  color: var(--danger-500);
}

.stat {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}

.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-tertiary);
  font-size: var(--fs-caption);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  background: var(--brand-soft);
  color: var(--brand-400);
}

.stat-value {
  font-size: var(--fs-h2);
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.stat-sub {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.stat-accent-success .stat-icon {
  background: var(--success-soft);
  color: var(--success-500);
}

.stat-accent-warning .stat-icon {
  background: var(--warning-soft);
  color: var(--warning-500);
}

.stat-accent-info .stat-icon {
  background: var(--info-soft);
  color: var(--info-500);
}

.stat-accent-danger .stat-icon {
  background: var(--danger-soft);
  color: var(--danger-500);
}

/* =============================================================== buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  padding: 9px var(--sp-md);
  min-height: 38px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: var(--surface-overlay);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
}

.btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--brand-500);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-600);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--surface-overlay);
  color: var(--text-primary);
}

.btn-danger {
  background: transparent;
  border-color: rgba(240, 90, 82, 0.4);
  color: var(--danger-500);
}

.btn-danger:hover {
  background: var(--danger-soft);
  color: var(--danger-500);
}

.btn-sm {
  min-height: 30px;
  padding: 5px 10px;
  font-size: var(--fs-caption);
}

.btn-icon {
  padding: 7px;
  min-height: 32px;
  width: 32px;
}

.btn-block {
  width: 100%;
}

/* ================================================================= forms */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--sp-md);
}

.field > label {
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text-secondary);
}

.field .hint {
  font-size: var(--fs-caption);
  color: var(--text-tertiary);
}

input[type='text'],
input[type='password'],
input[type='number'],
input[type='datetime-local'],
input[type='search'],
select,
textarea {
  width: 100%;
  padding: 9px var(--sp-sm) 9px 12px;
  background: var(--surface-canvas);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  font-family: inherit;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

textarea {
  min-height: 104px;
  resize: vertical;
  line-height: var(--lh-normal);
}

textarea.mono {
  font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-sm);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  cursor: pointer;
}

.switch input {
  appearance: none;
  width: 38px;
  height: 22px;
  border-radius: var(--r-full);
  background: var(--surface-overlay);
  border: 1px solid var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.15s var(--ease);
  flex: 0 0 auto;
}

.switch input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: var(--r-full);
  background: var(--text-tertiary);
  transition: transform 0.15s var(--ease), background 0.15s var(--ease);
}

.switch input:checked {
  background: var(--brand-500);
  border-color: var(--brand-500);
}

.switch input:checked::after {
  transform: translateX(16px);
  background: #fff;
}

.filters {
  display: flex;
  gap: var(--sp-sm);
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: var(--sp-md);
}

.filters .field {
  margin-bottom: 0;
  min-width: 170px;
}

.filters .field-grow {
  flex: 1;
  min-width: 220px;
}

/* ================================================================ tables */

.table-wrap {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.table-wrap::-webkit-scrollbar {
  height: 8px;
}

.table-wrap::-webkit-scrollbar-track {
  background: var(--surface-canvas);
}

.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

thead th {
  text-align: left;
  padding: 11px var(--sp-md);
  font-size: var(--fs-caption);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  font-weight: 600;
  background: var(--surface-overlay);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

tbody td {
  padding: 12px var(--sp-md);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.015);
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.actions {
  text-align: right;
  white-space: nowrap;
}

/* Row actions keep to one line; the table scrolls sideways instead of a cell
   growing two rows tall and throwing off the rhythm of the whole table. */
td.actions .row {
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.cell-main {
  font-weight: 550;
  color: var(--text-primary);
}

.cell-sub {
  font-size: var(--fs-caption);
  color: var(--text-tertiary);
}

/* ================================================================ badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: var(--fs-caption);
  font-weight: 550;
  letter-spacing: 0.01em;
  background: var(--surface-overlay);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  background: currentColor;
}

.badge-success {
  background: var(--success-soft);
  color: var(--success-500);
  border-color: transparent;
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger-500);
  border-color: transparent;
}

.badge-warning {
  background: var(--warning-soft);
  color: var(--warning-500);
  border-color: transparent;
}

.badge-info {
  background: var(--info-soft);
  color: var(--info-500);
  border-color: transparent;
}

.badge-muted {
  color: var(--text-tertiary);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  background: var(--surface-overlay);
  border: 1px solid var(--border-subtle);
  font-size: var(--fs-caption);
  color: var(--text-secondary);
}

/* ================================================================= misc */

.flash {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 12px var(--sp-md);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-lg);
  font-size: var(--fs-sm);
  border: 1px solid transparent;
}

.flash-success {
  background: var(--success-soft);
  color: var(--success-500);
}

.flash-danger {
  background: var(--danger-soft);
  color: var(--danger-500);
}

.empty {
  padding: var(--sp-2xl) var(--sp-lg);
  text-align: center;
  color: var(--text-tertiary);
}

.empty svg.icon {
  width: 34px;
  height: 34px;
  margin-bottom: var(--sp-sm);
  opacity: 0.6;
}

.empty h4 {
  color: var(--text-secondary);
  font-size: var(--fs-body);
  font-weight: 550;
  margin: 0 0 var(--sp-xs);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  padding: var(--sp-md) var(--sp-lg);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  flex-wrap: wrap;
}

.pagination-pages {
  display: flex;
  gap: var(--sp-xs);
}

.page-link {
  min-width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0 var(--sp-sm);
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
}

.page-link:hover {
  background: var(--surface-overlay);
  color: var(--text-primary);
}

.page-link.is-current {
  background: var(--brand-500);
  border-color: var(--brand-500);
  color: #fff;
}

.page-link.is-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 140px;
  padding-top: var(--sp-sm);
}

.bar {
  flex: 1;
  min-width: 8px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  align-items: center;
  height: 100%;
}

.bar-fill {
  width: 100%;
  border-radius: var(--r-sm) var(--r-sm) 2px 2px;
  background: linear-gradient(180deg, var(--brand-500), rgba(76, 141, 255, 0.25));
  min-height: 3px;
}

.bar-label {
  font-size: 10px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.kv {
  display: grid;
  grid-template-columns: minmax(120px, 170px) 1fr;
  gap: var(--sp-sm) var(--sp-md);
  font-size: var(--fs-sm);
}

.kv dt {
  color: var(--text-tertiary);
}

.kv dd {
  margin: 0;
  color: var(--text-primary);
}

.snippet {
  background: var(--surface-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  padding: var(--sp-sm) 12px;
  font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  font-size: var(--fs-sm);
  color: var(--text-primary);
  word-break: break-all;
}

/* Prose variant: keeps the admin's line breaks without breaking mid-word. */
.snippet-prose {
  font-family: inherit;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: var(--lh-normal);
  color: var(--text-secondary);
}

.tabs {
  display: flex;
  gap: var(--sp-xs);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--sp-lg);
}

.tab {
  padding: var(--sp-sm) 12px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
}

.tab.is-active {
  color: var(--brand-400);
  border-bottom-color: var(--brand-500);
}

/* ================================================================= login */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-lg);
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(76, 141, 255, 0.12), transparent 70%),
    var(--surface-canvas);
}

.auth-card {
  width: 100%;
  max-width: 408px;
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-xl);
  box-shadow: var(--shadow-lg);
}

.auth-mark {
  width: 46px;
  height: 46px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
  display: grid;
  place-items: center;
  color: #fff;
  margin-bottom: var(--sp-md);
}

.auth-card h1 {
  font-size: var(--fs-h3);
  font-weight: 650;
  margin-bottom: var(--sp-xs);
}

.auth-card p.lead {
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  margin: 0 0 var(--sp-lg);
}

.auth-foot {
  margin-top: var(--sp-lg);
  padding-top: var(--sp-md);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--fs-caption);
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ================================================================= mail */

.maillist {
  list-style: none;
}

/* A shared left border carries the grouping, so each row needs no box. */
.maillist-item + .maillist-item {
  border-top: 1px solid var(--border-subtle);
}

.maillist-link {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-sm);
  padding: 12px var(--sp-lg);
  color: inherit;
  text-decoration: none;
  transition: background 0.15s var(--ease);
}

.maillist-link:hover {
  background: var(--surface-hover);
  color: inherit;
}

.maillist-link:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: -2px;
}

/* Unread is the one state worth spotting at a glance, so only it gets a mark. */
.maillist-dot {
  flex: none;
  width: 7px;
  height: 7px;
  margin-top: 7px;
  border-radius: 50%;
  background: transparent;
}

.maillist-item.is-unread .maillist-dot {
  background: var(--brand-500);
}

.maillist-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.maillist-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-sm);
}

.maillist-from {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.maillist-date {
  flex: none;
  font-size: var(--fs-caption);
  color: var(--text-tertiary);
}

.maillist-subject {
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.maillist-item.is-unread .maillist-subject {
  font-weight: 650;
}

.maillist-preview {
  font-size: var(--fs-caption);
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.maillist-flag {
  flex: none;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* Mail bodies assume a white page, so the frame keeps its own light surface. */
.mailbody {
  display: block;
  width: 100%;
  height: 620px;
  border: 0;
  background: #fff;
}

.linklist {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
}

.linklist li {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
}

.linklist-url {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  background: var(--surface-canvas);
  border: 1px solid var(--border-subtle);
  font-size: var(--fs-caption);
  font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
}

.linklist-url span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.linklist-url svg.icon {
  flex: none;
  color: var(--text-tertiary);
}

@media (max-width: 640px) {
  .maillist-top {
    flex-direction: column;
    gap: 0;
  }

  .mailbody {
    height: 440px;
  }
}

/* ============================================================ copy chip */

.copy-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: var(--r-sm);
  /* Font comes from the .mono class on the same element. */
}

.copy-chip svg.icon {
  color: var(--text-tertiary);
  transition: color 0.15s var(--ease);
}

.copy-chip:hover svg.icon {
  color: var(--brand-500);
}

.copy-chip:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ================================================================ modal */

/* A scrim pushes the page to ground so the dialog reads as the only figure. */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  place-items: center;
  padding: var(--sp-lg);
  background: rgba(3, 5, 9, 0.72);
}

.modal.is-open {
  display: grid;
}

.modal-dialog {
  width: 100%;
  max-width: 440px;
  background: var(--surface-overlay);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-lg);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-md);
  margin-bottom: var(--sp-md);
}

.modal-mark {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  background: var(--danger-soft);
  color: var(--danger-500);
}

.modal-mark-primary {
  background: var(--brand-soft);
  color: var(--brand-500);
}

.modal-title {
  font-size: var(--fs-sub);
  font-weight: 650;
  line-height: var(--lh-tight);
}

.modal-text {
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
  margin: 0 0 var(--sp-lg);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-sm);
}

@media (max-width: 480px) {
  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions .btn {
    width: 100%;
  }
}

/* ================================================================ toast */

/* Sits just under the sticky topbar so it never covers the session chips. */
.toast-region {
  position: fixed;
  top: calc(var(--topbar-h) + var(--sp-md));
  right: var(--sp-xl);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
  width: min(360px, calc(100vw - var(--sp-lg)));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-sm);
  padding: 12px var(--sp-md);
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-overlay);
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
  pointer-events: auto;
  animation: toast-in 0.18s var(--ease);
}

.toast svg.icon {
  flex: none;
  margin-top: 1px;
}

.toast-success svg.icon {
  color: var(--success-500);
}

.toast-danger svg.icon {
  color: var(--danger-500);
}

.toast-text {
  flex: 1;
  min-width: 0;
}

.toast-close {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
}

.toast-close:hover {
  color: var(--text-primary);
}

.toast-close:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.toast.is-leaving {
  animation: toast-out 0.16s var(--ease) forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .toast.is-leaving {
    animation: none;
  }
}

/* =========================================================== responsive */

@media (max-width: 1180px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s var(--ease);
    box-shadow: var(--shadow-lg);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  body.nav-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 30;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .topbar {
    padding: 0 var(--sp-md);
  }

  .content {
    padding: var(--sp-md);
  }

  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* A width floor lets .table-wrap actually overflow and scroll, instead of
     crushing every column until the last ones fall off the viewport. */
  .table-wrap table {
    min-width: 780px;
  }

  .table-wrap .cell-main,
  .table-wrap .cell-sub {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 30ch;
  }
}

@media (max-width: 680px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: minmax(0, 1fr);
  }

  .page-head h2 {
    font-size: var(--fs-h3);
  }

  .stat-value {
    font-size: var(--fs-h3);
  }

  .topbar-meta .hide-sm {
    display: none;
  }
}
