/* ==========================================================================
   BOG CLOUD — COMPONENTS
   One definition per component. The old codebase declared .card 21 times,
   .sidebar 14 times and --gray-100 16 times, across three drifting token
   vocabularies.
   ========================================================================== */

/* ==========================================================================
   BUTTON
   The pattern is always: thick border + flat fill + hard shadow.
   Hover lifts and grows the shadow. Active presses down into it and kills
   the shadow. Immediate, physical, 90ms.
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 12px var(--s-5);
  border: var(--bw) solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--sh-2);
  font-family: var(--font-heading);
  font-size: var(--fs-sm);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--t-lift) var(--ease),
              box-shadow var(--t-lift) var(--ease),
              background-color 180ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.btn:hover  { transform: translate(-2px, -2px); box-shadow: var(--sh-3); }
.btn:active { transform: translate(3px, 3px);  box-shadow: none; }

/* Primary — brand fill. Contract rule 1: white text only. */
.btn--primary { background: var(--brand-700); color: var(--on-brand); }
.btn--primary:hover { background: var(--brand-900); }

/* Flag — the highlighter. Used for the single loudest action on a view. */
.btn--flag { background: var(--flag); color: var(--on-fill); border-color: var(--fill-edge); }
.btn--flag:hover { background: #E8BE24; }

/* Ink — inverted, for use on signal fills. */
.btn--ink { background: var(--ink); color: var(--paper); }
:root[data-theme="dark"] .btn--ink { background: var(--paper); color: var(--ink); }

/* Ghost — structural, low emphasis. */
.btn--ghost { background: transparent; color: var(--text); box-shadow: none; }
.btn--ghost:hover { background: var(--bg); box-shadow: var(--sh-1); transform: translate(-2px, -2px); }
.btn--ghost:active { transform: translate(3px, 3px); box-shadow: none; }

/* Danger — never colour-alone; every instance carries an aria-label. */
.btn--danger { background: var(--err-edge); color: var(--on-danger); }
.btn--danger:hover { background: #851213; }

.btn--lg { padding: 16px var(--s-6); font-size: var(--fs-body); box-shadow: var(--sh-3); }
.btn--sm { padding: 8px var(--s-3); font-size: var(--fs-xs); box-shadow: var(--sh-1); }
.btn--block { display: flex; width: 100%; }

/* Disabled — visible, and readable. The old .btn-brand:disabled was white
   text on #ccc (1.61:1), i.e. invisible in its most important state. */
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--bg);
  color: var(--muted);
  border-color: var(--muted);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

/* Busy state — label swaps via JS, keep the box from resizing. */
.btn[data-busy="true"] { pointer-events: none; }

/* ==========================================================================
   CARD
   ========================================================================== */

.card {
  background: var(--surface);
  border: var(--bw) solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--sh-2);
  padding: var(--s-5);
}
.card--flat  { box-shadow: none; }
.card--lg    { padding: var(--s-6); box-shadow: var(--sh-3); }
.card--tight { padding: var(--s-4); }

/* Lift is reserved for cards that are themselves a target. */
.card--link { display: block; text-decoration: none; color: inherit; }
.card--link:hover { transform: translate(-2px, -2px); box-shadow: var(--sh-3); }
.card--link:active { transform: translate(3px, 3px); box-shadow: var(--sh-1); }

/* Filled card — loud background, structure contains the energy. */
.card--fill-flag  { background: var(--flag);  color: var(--on-fill); border-color: var(--fill-edge); }
.card--fill-sky   { background: var(--sky);   color: var(--on-fill); border-color: var(--fill-edge); }
.card--fill-live  { background: var(--live);  color: var(--on-fill); border-color: var(--fill-edge); }

/* ==========================================================================
   BADGE / PILL
   Status is never colour-alone: every pill pairs its fill with a glyph and a
   text label. Satisfies WCAG 1.4.1.
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 4px var(--s-2);
  border: var(--bw-thin) solid var(--fill-edge);
  border-radius: var(--radius);
  background: var(--flag);
  color: var(--on-fill);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  line-height: 1.4;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: var(--bw-thin) solid var(--edge);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; background: currentColor; flex-shrink: 0; }
.pill--ok    { background: var(--ok-bg);    color: var(--ok-text); }
.pill--warn  { background: var(--warn-bg);  color: var(--warn-text); }
.pill--err   { background: var(--err-bg);   color: var(--err-text); }
.pill--info  { background: var(--info-bg);  color: var(--info-text); }
.pill--mute  { background: var(--bg);       color: var(--muted); }

/* ==========================================================================
   FORM FIELD
   The old forms had zero <label for> and relied on placeholders, which
   vanish on first keystroke. Label is always present and always bound.
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-family: var(--font-heading);
  font-size: var(--fs-sm);
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
}

.field-input,
.field-select,
.field-textarea {
  width: 100%;
  padding: 12px var(--s-4);
  border: var(--bw) solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: 1.4;
  box-shadow: var(--sh-1);
  transition: transform var(--t-lift) var(--ease), box-shadow var(--t-lift) var(--ease);
}
.field-textarea { min-height: 120px; resize: vertical; }
.field-select { appearance: none; padding-right: var(--s-7); cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 20px center, right 14px center;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.field-input::placeholder, .field-textarea::placeholder { color: var(--muted); opacity: 1; }
.field-input:hover, .field-select:hover, .field-textarea:hover { box-shadow: var(--sh-2); }
.field-input:focus-visible, .field-select:focus-visible, .field-textarea:focus-visible {
  outline: var(--focus-ring) solid var(--sky);
  outline-offset: 3px;
}

/* Invalid state carries an icon in the message, not just a red border. */
.field-input[aria-invalid="true"] { border-color: var(--err-edge); background: var(--err-bg); }

.field-hint  { font-size: var(--fs-xs); color: var(--muted); line-height: 1.5; }
.field-error {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--err-text);
  line-height: 1.5;
}
.field-error::before { content: "✕"; font-weight: 700; }
.field-error.is-visible { display: flex; }

/* Password reveal — the old forms had 6 password fields and 0 toggles. */
.reveal { position: relative; }
.reveal .field-input { padding-right: 56px; }
.reveal-btn {
  position: absolute;
  top: 50%; right: 6px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border: var(--bw-thin) solid var(--edge);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.reveal-btn:hover { background: var(--flag); color: var(--on-fill); border-color: var(--fill-edge); }
.reveal-btn svg { width: 18px; height: 18px; }

/* ==========================================================================
   ALERT / MESSAGE
   Every instance carries role="alert" or aria-live in the markup.
   ========================================================================== */

.alert {
  display: none;
  align-items: flex-start;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border: var(--bw-thin) solid var(--edge);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1.5;
}
.alert::before { font-weight: 700; flex-shrink: 0; }
.alert.is-visible { display: flex; }
.alert--error   { background: var(--err-bg);   color: var(--err-text);  border-color: var(--err-edge); }
.alert--error::before   { content: "✕"; }
.alert--success { background: var(--ok-bg);    color: var(--ok-text);   border-color: var(--ok-edge); }
.alert--success::before { content: "✓"; }
.alert--warning { background: var(--warn-bg);  color: var(--warn-text); border-color: var(--warn-edge); }
.alert--warning::before { content: "!"; }
.alert--info    { background: var(--info-bg);  color: var(--info-text); border-color: var(--info-edge); }
.alert--info::before    { content: "i"; }

/* ==========================================================================
   PROGRESS
   role="progressbar" with aria-valuenow/min/max on every instance.
   Track is --bg on a bordered surface so it stays visible in both themes
   (it measured 1.11:1 before).
   ========================================================================== */

.progress {
  height: 14px;
  background: var(--bg);
  border: var(--bw-thin) solid var(--edge);
  border-radius: var(--radius);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--brand-text);
  border-right: var(--bw-thin) solid var(--edge);
  transition: width 220ms var(--ease);
}
/* These two variants invert the track instead of tinting it. --flag and --live
   cannot clear 3:1 against the --bg track (1.51:1 and 1.42:1), and a progress
   fill boundary is meaningful UI, not decoration. Putting a dark track behind
   the fill gives 13.7:1 and 11.2:1. */
.progress--flag { background: var(--ink); }
.progress--live { background: var(--ink); }
.progress--flag .progress-bar { background: var(--flag);  border-right-color: var(--fill-edge); }
.progress--live .progress-bar { background: var(--live);  border-right-color: var(--fill-edge); }
:root[data-theme="dark"] .progress--flag,
:root[data-theme="dark"] .progress--live { background: var(--paper); }

/* ==========================================================================
   TABLE
   Denser and calmer than the surrounding cards: thin dividers, sticky head.
   Every <th> ships with scope.
   ========================================================================== */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: var(--bw) solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--sh-2);
}

.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }

.table caption {
  padding: var(--s-4) var(--s-4) 0;
  text-align: left;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--s-3) var(--s-4);
  background: var(--bg);
  border-bottom: var(--bw) solid var(--edge);
  text-align: left;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.table tbody td {
  padding: var(--s-3) var(--s-4);
  border-bottom: var(--bw-thin) solid var(--edge);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--brand-50); }
:root[data-theme="dark"] .table tbody tr:hover { background: rgba(163,191,255,0.08); }
.table .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   APP SHELL — topbar, sidebar, drawer, overlay
   Injected by assets/js/shell.js so the markup is defined exactly once.
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  height: 72px;
  padding-inline: var(--s-5);
  background: var(--bg);
  border-bottom: var(--bw) solid var(--edge);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--font-display);
  font-size: var(--fs-h3);
  font-weight: 800;
  letter-spacing: var(--track-tight);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.topbar__mark {
  width: 34px; height: 34px;
  border: var(--bw-thin) solid var(--edge);
  box-shadow: var(--sh-1);
  object-fit: cover;
}
.topbar__spacer { flex: 1; }

.topbar__search { flex: 1; max-width: 480px; position: relative; }
.topbar__search .field-input { padding-left: 40px; box-shadow: none; background: var(--surface); }
.topbar__search svg {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  color: var(--muted);
  pointer-events: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px; height: 44px;      /* exceeds the 24x24 AA target floor */
  border: var(--bw) solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--sh-1);
  cursor: pointer;
  transition: transform var(--t-lift) var(--ease), box-shadow var(--t-lift) var(--ease);
}
.icon-btn:hover { transform: translate(-2px, -2px); box-shadow: var(--sh-2); background: var(--flag); color: var(--on-fill); border-color: var(--fill-edge); }
.icon-btn:active { transform: translate(2px, 2px); box-shadow: none; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn--plain { border: 0; box-shadow: none; background: transparent; }
.icon-btn--plain:hover { border: var(--bw); box-shadow: var(--sh-1); }

.avatar {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  border: var(--bw) solid var(--edge);
  border-radius: var(--radius);
  background: var(--brand-700);
  color: var(--on-brand);
  box-shadow: var(--sh-1);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--fs-sm);
  cursor: pointer;
  text-transform: uppercase;
}
.avatar:hover { background: var(--brand-900); }

/* Dropdown — closes on Escape and on outside click (see shell.js). */
.menu {
  position: absolute;
  right: 0; top: calc(100% + var(--s-2));
  z-index: 200;
  min-width: 240px;
  padding: var(--s-2);
  background: var(--surface);
  border: var(--bw) solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--sh-3);
}
.menu[hidden] { display: none; }
.menu__header { padding: var(--s-3); border-bottom: var(--bw-thin) solid var(--edge); margin-bottom: var(--s-2); }
.menu__item {
  display: block;
  width: 100%;
  padding: var(--s-2) var(--s-3);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu__item:hover { background: var(--flag); color: var(--on-fill); }
.menu__item--danger { color: var(--err-text); font-weight: 600; }
.menu__item--danger:hover { background: var(--err-bg); color: var(--err-text); }

/* Anchor wrapper for a menu trigger. Exists so the shell can compose the
   account menu without emitting an inline style string. */
.menu-anchor { position: relative; display: flex; }
.menu-anchor__name { font-weight: 700; font-size: var(--fs-sm); }
.menu-anchor__email { font-size: var(--fs-xs); color: var(--muted); }

/* Visibility toggle used by JS. Preferred over style.display so the rules
   stay in the stylesheet and stay overridable. */
.is-hidden { display: none !important; }

/* Sidebar / drawer */
.shell { display: flex; align-items: flex-start; }

.sidebar {
  position: sticky;
  top: 72px;
  flex-shrink: 0;
  width: 264px;
  height: calc(100vh - 72px);
  overflow-y: auto;
  padding: var(--s-4);
  background: var(--bg);
  border-right: var(--bw) solid var(--edge);
}
.sidebar__group { margin-bottom: var(--s-5); }
.sidebar__label {
  padding: 0 var(--s-3);
  margin-bottom: var(--s-2);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 10px var(--s-3);
  border: var(--bw-thin) solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-heading);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 120ms var(--ease), transform 120ms var(--ease);
}
.nav-link:hover { background: var(--surface); border-color: var(--edge); transform: translateX(2px); }
.nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }
/* shell.js sets aria-current="page"; this is the visual match. */
.nav-link[aria-current="page"] {
  background: var(--flag);
  border-color: var(--fill-edge);
  box-shadow: var(--sh-1);
  font-weight: 700;
}
.nav-link--danger { color: var(--err-text); font-weight: 600; }
.nav-link--danger:hover { background: var(--err-bg); border-color: var(--err-edge); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(10, 10, 10, 0.55);
  border: 0;
  padding: 0;
  cursor: pointer;
}
.overlay[hidden] { display: none; }

/* Below the breakpoint the sidebar becomes a focus-trapped drawer. */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    z-index: 95;
    height: 100vh;
    width: min(300px, 84vw);
    transform: translateX(-100%);
    transition: transform var(--t-lift) var(--ease);
    box-shadow: none;
  }
  .sidebar.is-open { transform: translateX(0); box-shadow: var(--sh-4); }
  .sidebar__close { display: inline-grid !important; }
}
.sidebar__close { display: none; margin-left: auto; }

/* When the drawer is open, page scroll is locked by shell.js. */
body.is-locked { overflow: hidden; }

.main { flex: 1; min-width: 0; padding: var(--s-6); }
@media (max-width: 768px) { .main { padding: var(--s-4); } }

/* ==========================================================================
   STATES — loading skeleton and empty state
   The project had exactly one of each across 23 screens.
   ========================================================================== */

.skeleton {
  background: var(--bg);
  border: var(--bw-thin) solid var(--edge);
  border-radius: var(--radius);
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}
@keyframes skeleton-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--s-3);
  padding: var(--s-8) var(--s-5);
  border: var(--bw) dashed var(--edge);
  border-radius: var(--radius);
  text-align: center;
}
.empty-state__icon {
  display: grid;
  place-items: center;
  width: 56px; height: 56px;
  border: var(--bw) solid var(--fill-edge);
  box-shadow: var(--sh-2);
  background: var(--flag);
  color: var(--on-fill);
}
.empty-state__icon svg { width: 26px; height: 26px; }
.empty-state h3 { font-size: var(--fs-h3); }
.empty-state p  { color: var(--muted); font-size: var(--fs-sm); max-width: 46ch; }

/* ==========================================================================
   STAT TILE — real hierarchy: mono label, brand numeral, muted context.
   ========================================================================== */

.stat {
  background: var(--surface);
  border: var(--bw) solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--sh-2);
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}
.stat__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
}
.stat__value {
  font-family: var(--font-heading);
  font-size: clamp(26px, 3vw, 34px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: var(--track-tight);
  color: var(--brand-text);
  font-variant-numeric: tabular-nums;
}
.stat__context { font-size: var(--fs-xs); color: var(--muted); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s-4);
}

/* ==========================================================================
   MODAL
   Shell.js traps focus, restores it on close, and handles Escape.
   ========================================================================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: var(--s-4);
  background: rgba(10, 10, 10, 0.6);
}
.modal[hidden] { display: none; }
.modal__panel {
  width: min(520px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--s-6);
  background: var(--surface);
  border: var(--bw-thick) solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--sh-4);
}
.modal__head { display: flex; align-items: flex-start; gap: var(--s-3); margin-bottom: var(--s-5); }
.modal__head h2 { flex: 1; }
.modal__actions { display: flex; gap: var(--s-3); margin-top: var(--s-6); }

/* ==========================================================================
   FOOTER
   ========================================================================== */

.site-footer {
  margin-top: var(--s-9);
  border-top: var(--bw-thick) solid var(--edge);
  background: var(--bg);
}
.site-footer__grid {
  display: grid;
  grid-template-columns: 1.6fr repeat(3, 1fr);
  gap: var(--s-6);
  padding-block: var(--s-8);
}
@media (max-width: 900px) { .site-footer__grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .site-footer__grid { grid-template-columns: 1fr; } }

.site-footer h3 {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--s-3);
}
.site-footer ul { list-style: none; display: flex; flex-direction: column; gap: var(--s-2); }
.site-footer a { color: var(--text); text-decoration: none; font-size: var(--fs-sm); }
.site-footer a:hover { color: var(--text); text-decoration: underline; text-decoration-thickness: 2px; }

.site-footer__base {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  justify-content: space-between;
  align-items: center;
  padding-block: var(--s-4);
  border-top: var(--bw-thin) solid var(--edge);
  font-size: var(--fs-xs);
  color: var(--muted);
}
