/* =====================================================================
   Mr. Better Boss — design-system.css
   Shared design tokens + gap-filler components for the logged-in app.

   This file ONLY fills gaps in styles.css — it never redefines what
   styles.css already does well. Load order: styles.css first, then this.

   Tokens:          --text-*, --lh-*, --z-*, --focus-ring, --overlay
   Components:      .btn (+variants) · .empty-title/.empty-text/.empty-actions
                    .skel-btn/.skel-pill/.skel-block · .form-grid · .dlg
                    .tel-link · .kbd · .agent-avatar (+sizes)
   A11y:            global :focus-visible ring, dialog focus styles,
                    prefers-reduced-motion inheritance (no new keyframes
                    here — reuse rise/fade-in/pop-in from styles.css).
   Bar: world class. 390px-safe. Dark-first, light-theme keeps working
   automatically because everything below resolves through CSS vars.
   ===================================================================== */

/* ---------- Tokens (augment styles.css :root — no conflicts) ---------- */
:root {
  /* Type scale: Anton display | DM Sans body | JetBrains Mono numbers */
  --text-xs: 11px;    /* eyebrows, as-of lines, pri-src */
  --text-sm: 12.5px;  /* labels, pill, fine print */
  --text-md: 14px;    /* card body, list rows */
  --text-lg: 16px;    /* section titles, hero numbers' context */
  --text-xl: 20px;    /* page-h2 fallback */
  --text-2xl: 26px;   /* job-head h2 fallback */
  --text-3xl: 34px;   /* page-head h1, brief-card-big */
  --lh-tight: 1.1;    /* display numerals */
  --lh-body: 1.55;    /* long-form reading */
  --lh-cozy: 1.4;     /* cards, rows */

  /* Stacking order */
  --z-nav: 40;
  --z-sheet: 60;
  --z-palette: 70;
  --z-dialog: 80;
  --z-toast: 90;

  /* One focus ring, everywhere */
  --focus-ring: 0 0 0 3px var(--violet-soft);

  /* Modal/sheet scrim */
  --overlay: rgba(4, 4, 8, 0.62);

  /* Brand button text is always white-on-violet, both themes */
  --on-brand: #ffffff;

  /* Agent avatar ring (brand glow, theme-agnostic) */
  --avatar-ring: 2px solid rgba(93, 71, 250, 0.65);
  --avatar-glow: 0 0 18px rgba(93, 71, 250, 0.35);
}

[data-theme="light"] {
  /* design-system.css adds no light-specific token changes: every new
     component resolves through the vars styles.css already overrides. */
  --overlay: rgba(20, 22, 40, 0.42);
  --avatar-glow: 0 0 14px rgba(93, 71, 250, 0.28);
}

/* =====================================================================
   Global :focus-visible — one visible ring on everything focusable.
   (P2 audit item: only .mtab and .push-toggle had this before.)
   ===================================================================== */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
/* Keep the stronger brand-outline variants styles.css already applies
   (input:focus, textarea:focus) — they sit on top via specificity. */

/* =====================================================================
   .btn — unified button base. styles.css has page-specific buttons
   (.btn-primary login-only, .btn-new sidebar-only, .brief-action,
   .prop-confirm/.prop-decline, .followup). This is the generic one for
   everything new. Never 100%-width unless .block.
   ===================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-size: var(--text-md);
  font-weight: 700;
  line-height: var(--lh-tight);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease),
              filter 0.2s var(--ease), background 0.2s var(--ease),
              border-color 0.2s var(--ease), color 0.2s var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; filter: none; }

/* Primary = brand violet gradient (inline, unlike login's full-width .btn-primary) */
.btn.primary {
  background: linear-gradient(135deg, var(--violet), #7a63ff);
  color: var(--on-brand);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); box-shadow: 0 6px 24px var(--violet-glow); }
.btn.primary:active:not(:disabled) { box-shadow: 0 2px 10px var(--violet-glow); }

/* Ghost = violet tint, for secondary actions alongside primary */
.btn.ghost {
  background: var(--violet-soft);
  border-color: rgba(93, 71, 250, 0.35);
  color: var(--text);
}
.btn.ghost:hover:not(:disabled) { background: rgba(93, 71, 250, 0.22); border-color: var(--violet); }
[data-theme="light"] .btn.ghost { color: var(--violet-deep); }

/* Danger = red, for discard/delete/disconnect confirmations */
.btn.danger {
  background: var(--red-dim);
  border-color: rgba(255, 93, 108, 0.45);
  color: var(--red);
}
.btn.danger:hover:not(:disabled) { background: rgba(255, 93, 108, 0.22); }

/* small = compact, for row actions and dense surfaces */
.btn.small { min-height: 36px; padding: 7px 14px; font-size: var(--text-sm); border-radius: var(--r-sm); }
/* block = full width, for sheet footers / standalone pages */
.btn.block { width: 100%; }

/* =====================================================================
   Empty states — .empty-state exists; these are its missing sub-parts.
   (P2 item: truncated empty-state copy → these never truncate.)
   ===================================================================== */
.empty-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0 0 8px;
  line-height: var(--lh-tight);
}
.empty-text {
  color: var(--muted);
  font-size: var(--text-md);
  line-height: 1.6;
  max-width: 42ch;
  margin: 0 auto 16px;
  overflow-wrap: break-word;
  white-space: normal; /* never clipped — P2 truncated-copy fix */
}
.empty-state .empty-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 4px;
}
.empty-state .empty-actions .btn { margin: 0; }

/* =====================================================================
   Skeletons — styles.css has .skel-card/.skel-row/.skel-line/.skel-num/
   .skel-avatar (+ .skel base shimmer). Missing: button, pill, tall block.
   ===================================================================== */
.skel-btn {
  width: 120px; height: 44px; border-radius: var(--r-pill);
}
.skel-pill {
  width: 74px; height: 22px; border-radius: var(--r-pill);
}
.skel-block { height: 200px; margin-bottom: 12px; }
/* .skel-* inherit the shimmer gradient from the shared .skel base class
   in styles.css — always pair: class="skel skel-btn" etc. */

/* =====================================================================
   .form-grid — 2-col form layout, collapses to 1-col under 480px.
   (P2 item: 2-col form grids with no mobile collapse.)
   ===================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
}
.form-grid > * { min-width: 0; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .field-label { margin-top: 2px; }
@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
}

/* =====================================================================
   .dlg — styled native <dialog>. styles.css had no modal/dialog at all
   (P2 items: no focus trap on dialogs, dialog focus styles).
   ===================================================================== */
.dlg {
  border: 1px solid var(--border-soft);
  border-radius: var(--r-xl);
  background: var(--surface-2);
  color: var(--text);
  padding: 0;
  width: min(440px, calc(100vw - 32px));
  max-height: min(80dvh, 640px);
  box-shadow: var(--shadow), 0 0 60px rgba(93, 71, 250, 0.18);
  animation: pop-in 0.28s var(--ease) both;
}
.dlg::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in 0.22s var(--ease) both;
}
.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 12px;
}
.dlg-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0;
}
.dlg-x {
  border: none; background: none; color: var(--muted);
  font-size: 22px; line-height: 1; cursor: pointer;
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.dlg-x:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.dlg-body { padding: 0 20px 16px; }
.dlg-foot {
  display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
  padding: 0 20px 20px;
}
/* Dialog focus: visible ring on the dialog itself and every control inside */
.dlg:focus { outline: none; }
.dlg .dlg-x:focus-visible,
.dlg .btn:focus-visible {
  box-shadow: var(--focus-ring);
  outline: none;
}
/* Native-dialog focus-trap note: <dialog>.showModal() traps focus natively
   in modern browsers; always use showModal(), never show(), so Esc closes
   and background stays inert (P2 item: Esc closes). */

/* =====================================================================
   .tel-link — click-to-call links (Phase 2 tel: requirement).
   Full phone number always shown, never truncated, thumb-sized.
   ===================================================================== */
.tel-link {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--green);
  text-decoration: underline;
  text-decoration-color: rgba(0, 233, 107, 0.5);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  min-height: 36px; /* thumb target */
  padding: 2px 4px;
  border-radius: 6px;
  transition: background 0.15s, text-decoration-color 0.15s;
}
.tel-link:hover { background: var(--green-dim); text-decoration-color: var(--green); }
[data-theme="light"] .tel-link { color: #00963f; }

/* =====================================================================
   .kbd — keyboard shortcut hint chip (⌘K palette, / shortcut).
   ===================================================================== */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--border-soft);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--muted);
}

/* =====================================================================
   .agent-avatar — scheduled-agent character avatar.
   One size system for: agent card (Agents tab), run history entries,
   Outbox rows, Activity entries. Distinct PNG per agent lives at
   static/img/agents/<id>.png (ids: client_update, daily_log, followup,
   estimate_builder, schedule_checker).
   ===================================================================== */
.agent-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  border: var(--avatar-ring);
  box-shadow: var(--avatar-glow);
  background: var(--surface-2);
}
.agent-avatar.sm { width: 32px; height: 32px; }
.agent-avatar.lg { width: 64px; height: 64px; }
/* Pair with .empty-robot art direction: same violet/green brand glow,
   circular crop so the square PNGs read at row/avatar scale. */

/* =====================================================================
   390px safety net for everything this file adds
   ===================================================================== */
@media (max-width: 480px) {
  .btn:not(.small) { padding-left: 16px; padding-right: 16px; }
  .dlg { width: calc(100vw - 24px); border-radius: var(--r-lg); }
  .dlg-foot { justify-content: stretch; }
  .dlg-foot .btn { flex: 1 1 140px; }
  .empty-state { padding: 24px 18px; }
}
