/* ==========================================================================
   Agentic Platform — Design System
   "Calm Authority" — adapted from Process Monitor
   Warm dark surfaces, copper accent, editorial typography.
   Consumer-facing: Source Serif 4 headings, Plus Jakarta Sans body.
   ========================================================================== */

/* --- Design Tokens ---------------------------------------------------- */

:root {
  /* Text-size preference: every font-size in this file is in rem, so this
     one factor scales all type. Set per device from Settings (localStorage,
     applied in base.html before first paint). */
  --font-scale: 1;

  /* Surfaces */
  --bg: #1A1A1A;
  --surface: #222222;
  --surface-raised: #2A2A2A;
  --surface-accent: #3A3530;
  --surface-overlay: rgba(26,26,26,0.97);
  --border: #2E2E2E;
  --border-strong: #3A3A3A;
  --input: #252525;
  --bg-recessed: #181818;

  /* Text */
  --text-primary: #EDE8E2;
  --text-body: #A8A39D;
  --text-muted: #8A8480;
  --text-inverse: #1A1A1A;

  /* Accent — copper */
  --copper: #C78C5C;
  --copper-hover: #D49A6A;
  --copper-muted: rgba(199,140,92,0.08);
  --copper-border: rgba(199,140,92,0.18);
  --copper-strong: rgba(199,140,92,0.25);

  /* Status */
  --status-red: #C75C5C;
  --status-red-bg: rgba(199,92,92,0.12);
  --status-red-border: rgba(199,92,92,0.25);
  --status-amber: #D4A017;
  --status-amber-bg: rgba(212,160,23,0.12);
  --status-amber-border: rgba(212,160,23,0.25);
  --status-green: #5C8A5C;
  --status-green-bg: rgba(92,138,92,0.12);
  --status-green-border: rgba(92,138,92,0.25);
  --status-blue: #5C7A8A;
  --status-blue-bg: rgba(92,122,138,0.12);
  --status-blue-border: rgba(92,122,138,0.25);

  /* Typography */
  --font-serif: 'Source Serif 4', Georgia, serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont,
    'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  /* Spacing (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 48px;
  --space-10: 64px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  --shadow-overlay: 0 12px 40px rgba(0,0,0,0.6);

  /* Motion */
  --ease-default: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast: 100ms;
  --duration-normal: 150ms;
  --duration-slow: 250ms;
}

/* --- Light Mode Overrides --------------------------------------------- */

/* Explicit light mode via data attribute. */
[data-theme="light"] {
  --bg: #F5F1EB;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --surface-accent: #F0EBE4;
  --surface-overlay: rgba(245,241,235,0.97);
  --border: #E0DBD3;
  --border-strong: #CCC7BF;
  --input: #FAFAF8;
  --bg-recessed: #EDEBE6;

  --text-primary: #1C1B18;
  --text-body: #6E6B65;
  --text-muted: #9C9990;
  --text-inverse: #FFFFFF;

  --copper: #A06E3C;
  --copper-hover: #8B5E30;
  --copper-muted: rgba(160,110,60,0.06);
  --copper-border: rgba(160,110,60,0.18);
  --copper-strong: rgba(160,110,60,0.2);

  --status-red: #C43D37;
  --status-red-bg: rgba(196,61,55,0.08);
  --status-red-border: rgba(196,61,55,0.2);
  --status-amber: #B8860B;
  --status-amber-bg: rgba(184,134,11,0.08);
  --status-amber-border: rgba(184,134,11,0.2);
  --status-green: #1B7A45;
  --status-green-bg: rgba(27,122,69,0.08);
  --status-green-border: rgba(27,122,69,0.2);
  --status-blue: #2D6A8F;
  --status-blue-bg: rgba(45,106,143,0.08);
  --status-blue-border: rgba(45,106,143,0.2);

  --shadow-sm: 0 1px 3px rgba(28,27,24,0.06);
  --shadow-md: 0 4px 12px rgba(28,27,24,0.08);
  --shadow-lg: 0 8px 24px rgba(28,27,24,0.1);
  --shadow-overlay: 0 12px 40px rgba(28,27,24,0.14);

  color-scheme: light;
}

/* System preference: when no explicit data-theme, respect the OS. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #F5F1EB;
    --surface: #FFFFFF;
    --surface-raised: #FFFFFF;
    --surface-accent: #F0EBE4;
    --surface-overlay: rgba(245,241,235,0.97);
    --border: #E0DBD3;
    --border-strong: #CCC7BF;
    --input: #FAFAF8;
    --bg-recessed: #EDEBE6;

    --text-primary: #1C1B18;
    --text-body: #6E6B65;
    --text-muted: #9C9990;
    --text-inverse: #FFFFFF;

    --copper: #A06E3C;
    --copper-hover: #8B5E30;
    --copper-muted: rgba(160,110,60,0.06);
    --copper-border: rgba(160,110,60,0.18);
    --copper-strong: rgba(160,110,60,0.2);

    --status-red: #C43D37;
    --status-red-bg: rgba(196,61,55,0.08);
    --status-red-border: rgba(196,61,55,0.2);
    --status-amber: #B8860B;
    --status-amber-bg: rgba(184,134,11,0.08);
    --status-amber-border: rgba(184,134,11,0.2);
    --status-green: #1B7A45;
    --status-green-bg: rgba(27,122,69,0.08);
    --status-green-border: rgba(27,122,69,0.2);
    --status-blue: #2D6A8F;
    --status-blue-bg: rgba(45,106,143,0.08);
    --status-blue-border: rgba(45,106,143,0.2);

    --shadow-sm: 0 1px 3px rgba(28,27,24,0.06);
    --shadow-md: 0 4px 12px rgba(28,27,24,0.08);
    --shadow-lg: 0 8px 24px rgba(28,27,24,0.1);
    --shadow-overlay: 0 12px 40px rgba(28,27,24,0.14);

    color-scheme: light;
  }
}

/* --- Reset & Base ----------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overscroll-behavior-y: contain; }

/* One rem = 16px × the user's text-size preference. */
html { font-size: calc(100% * var(--font-scale)); }

body {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--copper);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-default);
}
a:hover { color: var(--copper-hover); }

h1, h2, h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--text-primary);
}

::selection {
  background: var(--copper);
  color: var(--text-inverse);
}

:focus-visible {
  outline: 2px solid var(--copper);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Skeleton Loading ------------------------------------------------- */

@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: 400px 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-raised) 50%, var(--surface) 100%);
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-heading { height: 24px; width: 60%; margin-bottom: 12px; }
.skeleton-block { height: 80px; }

/* --- Entrance Choreography -------------------------------------------- */

@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.page-head,
.page .card,
.page .empty-state,
.page .markdown,
.page .section-title {
  animation: rise-in 420ms var(--ease-default) backwards;
}
.page .card:nth-of-type(2), .page .empty-state:nth-of-type(2) { animation-delay: 60ms; }
.page .card:nth-of-type(3) { animation-delay: 120ms; }
.page .card:nth-of-type(4) { animation-delay: 180ms; }
.page .card:nth-of-type(n+5) { animation-delay: 240ms; }

/* --- Navigation ------------------------------------------------------- */

.topnav {
  display: flex;
  align-items: center;
  flex-shrink: 0; /* body is a flex column: iOS shrinks sticky headers on
                     long pages, spilling the wrapped nav row into content */
  flex-wrap: wrap; /* large text-size settings must wrap, never overflow */
  gap: var(--space-2) var(--space-6);
  padding: var(--space-2) var(--space-5);
  min-height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.0625rem;
  color: var(--copper);
  letter-spacing: -0.01em;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.brand-mark {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.brand-word { color: var(--text-primary); }
.brand-word em { font-style: italic; font-weight: 400; color: var(--copper); }

.navlinks {
  display: flex;
  gap: var(--space-1);
  flex: 1;
}

.navlinks a {
  text-decoration: none;
  color: var(--text-body);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--duration-fast) var(--ease-default);
}
.navlinks a:hover {
  background: var(--surface-accent);
  color: var(--text-primary);
}
.navlinks a.active {
  background: var(--copper-muted);
  color: var(--copper);
  border: 1px solid var(--copper-border);
}

.navuser {
  font-size: 0.875rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}
.navuser a {
  color: var(--text-body);
  font-weight: 500;
}
.navuser a:hover { color: var(--copper); }

.nav-more-btn,
.nav-overflow,
.nav-overflow-backdrop { display: none; }

.badge {
  background: var(--status-red);
  color: var(--text-primary);
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 1px 7px;
  vertical-align: middle;
  margin-left: var(--space-1);
}

/* --- Layout ----------------------------------------------------------- */

.page {
  width: 100%;
  margin: 0 auto;
  padding: var(--space-7) var(--space-5) var(--space-10);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}

.page-head h1 {
  font-size: 1.375rem;
  letter-spacing: -0.01em;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 600;
  margin-top: var(--space-8);
  margin-bottom: var(--space-4);
}

.muted { color: var(--text-body); }
.small { font-size: 0.8125rem; }

.flashes { margin-bottom: var(--space-5); }

.flash {
  background: var(--status-amber-bg);
  border: 1px solid var(--status-amber-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  font-size: 0.875rem;
  color: var(--status-amber);
}

/* --- Cards ------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  margin: var(--space-4) 0;
  transition: border-color var(--duration-normal) var(--ease-default);
}
.card:hover { border-color: var(--border-strong); }

.card h2 {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 600;
  margin-top: 0;
  margin-bottom: var(--space-2);
}

.empty-state {
  text-align: center;
  padding: var(--space-9) 0;
  color: var(--text-body);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}
.empty-state p { margin: var(--space-2) 0; }

/* --- Status Badges ---------------------------------------------------- */

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  padding: 4px 12px;
  margin-right: var(--space-2);
  text-transform: capitalize;
}

.status-chip.executed {
  background: var(--status-green-bg);
  border: 1px solid var(--status-green-border);
  color: var(--status-green);
}

.status-chip.rejected,
.status-chip.failed {
  background: var(--status-red-bg);
  border: 1px solid var(--status-red-border);
  color: var(--status-red);
}

/* --- Buttons ---------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--duration-fast) var(--ease-default);
  line-height: 1.2;
}
.btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-accent);
}

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

.btn.danger {
  color: var(--status-red);
  border-color: var(--status-red-border);
  background: var(--status-red-bg);
}
.btn.danger:hover {
  background: rgba(199,92,92,0.2);
}

.btn.small {
  padding: 6px 12px;
  font-size: 0.8125rem;
}

.btn.wide { width: 100%; }

.btn.icon {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* --- Forms ------------------------------------------------------------ */

input[type=text],
input[type=email],
input[type=password] {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  width: 100%;
  background: var(--input);
  color: var(--text-primary);
  transition: border-color var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-fast) var(--ease-default);
}

input::placeholder { color: var(--text-muted); }

input:focus {
  outline: none;
  border-color: var(--copper);
  box-shadow: 0 0 0 2px rgba(199,140,92,0.12);
}

/* Password fields: show/hide toggle (pw-toggle.js wraps every
   input[type=password] in .pw-wrap and appends the eye button). */
.pw-wrap {
  position: relative;
  display: block;
  flex: 1;
  min-width: 0;
}

.pw-wrap input {
  padding-right: 44px;
}

.pw-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.pw-toggle:hover { color: var(--text-primary); }

/* Inline form feedback: failures must read as failures, not footnotes. */
.form-error {
  margin: var(--space-2) 0;
  padding: 10px 14px;
  border: 1px solid var(--status-red-border);
  border-radius: var(--radius-md);
  background: var(--status-red-bg);
  color: var(--status-red);
  font-size: 0.875rem;
  font-weight: 500;
}

.flash.success {
  background: var(--status-green-bg);
  border-color: var(--status-green-border);
  color: var(--status-green);
}

label {
  display: block;
  margin: var(--space-3) 0 var(--space-1);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-body);
}

.inline-form {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.inline-form input { flex: 1; }

.form-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
}
.form-row label { flex: 1; }
.form-row label.narrow { flex: 0 0 90px; }
.form-row label.checkbox {
  flex: 0 0 auto;
  padding-bottom: 11px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.form-row .checkbox input { width: auto; }

/* -- Select ----------------------------------------------------------- */

select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 38px 11px 14px;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  background-color: var(--input);
  color: var(--text-primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8L9.5 4.5' stroke='%238A8480' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-fast) var(--ease-default);
}
select:focus {
  outline: none;
  border-color: var(--copper);
  box-shadow: 0 0 0 2px rgba(199,140,92,0.12);
}
select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
select option {
  background: var(--surface-raised);
  color: var(--text-primary);
}
select.small {
  padding: 7px 32px 7px 10px;
  font-size: 0.8125rem;
}

[data-theme="light"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8L9.5 4.5' stroke='%239C9990' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8L9.5 4.5' stroke='%239C9990' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}

/* -- Textarea --------------------------------------------------------- */

textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.7;
  width: 100%;
  min-height: 120px;
  resize: vertical;
  background: var(--input);
  color: var(--text-primary);
  transition: border-color var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-fast) var(--ease-default);
}
textarea::placeholder { color: var(--text-muted); }
textarea:focus {
  outline: none;
  border-color: var(--copper);
  box-shadow: 0 0 0 2px rgba(199,140,92,0.12);
}
textarea:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* -- Search + Number -------------------------------------------------- */

input[type=search],
input[type=number] {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  width: 100%;
  background: var(--input);
  color: var(--text-primary);
  transition: border-color var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-fast) var(--ease-default);
}
input[type=search]::-webkit-search-decoration,
input[type=search]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] { -moz-appearance: textfield; }

/* -- Range slider ----------------------------------------------------- */

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  outline: none;
  cursor: pointer;
  border: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--copper);
  border: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: box-shadow 100ms ease;
}
input[type=range]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--copper);
  border: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  cursor: pointer;
}
input[type=range]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(199,140,92,0.25), 0 1px 4px rgba(0,0,0,0.3);
}
input[type=range]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* -- Checkbox --------------------------------------------------------- */

input[type=checkbox] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  min-width: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--input);
  cursor: pointer;
  vertical-align: middle;
  transition: all var(--duration-fast) var(--ease-default);
  flex-shrink: 0;
}
input[type=checkbox]:checked {
  background: var(--copper);
  border-color: var(--copper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6L5 8.5L9.5 3.5' stroke='%23fff' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px;
}
input[type=checkbox]:focus { box-shadow: none; }
input[type=checkbox]:focus-visible {
  outline: 2px solid var(--copper);
  outline-offset: 2px;
}
input[type=checkbox]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* -- Radio ------------------------------------------------------------ */

input[type=radio] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  min-width: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: 50%;
  background: var(--input);
  cursor: pointer;
  vertical-align: middle;
  transition: all var(--duration-fast) var(--ease-default);
  flex-shrink: 0;
}
input[type=radio]:checked {
  border-color: var(--copper);
  background: var(--copper);
  box-shadow: inset 0 0 0 3px var(--input);
}
input[type=radio]:focus { box-shadow: none; }
input[type=radio]:checked:focus {
  box-shadow: inset 0 0 0 3px var(--input);
}
input[type=radio]:focus-visible {
  outline: 2px solid var(--copper);
  outline-offset: 2px;
}
input[type=radio]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* -- Error + small variant -------------------------------------------- */

.input-error {
  border-color: var(--status-red) !important;
  box-shadow: 0 0 0 2px var(--status-red-bg) !important;
}

input.small {
  padding: 7px 10px;
  font-size: 0.8125rem;
}
@media (max-width: 640px) {
  select.small,
  input.small {
    padding: 11px 38px 11px 14px;
    font-size: 0.9375rem;
  }
  input.small {
    padding: 11px 14px;
  }
}

/* --- Auth Pages ------------------------------------------------------- */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: var(--space-5);
  background: var(--bg);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-8);
  width: 400px;
  max-width: 100%;
  animation: rise-in 480ms var(--ease-default) backwards;
}

.auth-card h1 {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  font-weight: 700;
  margin: 0 0 var(--space-1);
  letter-spacing: -0.01em;
}

.auth-card p { font-size: 0.875rem; color: var(--text-body); }
.auth-card form { margin: var(--space-5) 0; }

.auth-card .btn {
  margin-top: var(--space-5);
  padding: 12px 18px;
}

/* --- Chat ------------------------------------------------------------- */

.chat-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 75rem;
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--space-5);
  min-height: 0;
  position: relative;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-1);
}

.chat-empty {
  text-align: center;
  margin-top: 12vh;
  color: var(--text-body);
  animation: rise-in 480ms var(--ease-default) backwards;
}

.chat-empty h2 {
  font-family: var(--font-serif);
  color: var(--text-primary);
  font-size: clamp(1.375rem, 4vw, 2.25rem);
  font-weight: 700;
  margin-bottom: var(--space-4);
  letter-spacing: -0.02em;
}

.chat-empty p { font-size: 0.875rem; color: var(--text-muted); }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-5);
  padding: 0;
}

.suggestion {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text-body);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  animation: rise-in 420ms var(--ease-default) backwards;
}
.suggestion:nth-child(2) { animation-delay: 70ms; }
.suggestion:nth-child(3) { animation-delay: 140ms; }
.suggestion:hover {
  border-color: var(--copper-border);
  color: var(--copper);
  background: var(--copper-muted);
}

.followup-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-2) 0;
  animation: msg-in 260ms var(--ease-default) backwards;
}

.followup-chips .suggestion {
  font-size: 0.8125rem;
  padding: 6px 14px;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.msg {
  display: flex;
  margin: 14px 0;
  animation: msg-in 260ms var(--ease-default) backwards;
}

.msg .bubble {
  position: relative;
  /* 78% of an ultrawide pane is an unreadable line length — cap in ch-ish rem. */
  max-width: min(78%, 46rem);
  padding: 12px 16px;
  border-radius: var(--radius-xl);
  font-size: 0.9375rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user { justify-content: flex-end; }

.msg.user .bubble {
  background: var(--copper);
  color: var(--text-inverse);
  border-bottom-right-radius: var(--space-1);
}

.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--space-1);
  white-space: normal;
}

/* Rendered markdown inside assistant bubbles */
.bubble p { margin: 0 0 var(--space-2); }
.bubble > *:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 var(--space-2); padding-left: 1.3em; }
.bubble li { margin: 2px 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  font-weight: 700;
  margin: var(--space-3) 0 var(--space-1);
}
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child { margin-top: 0; }
.bubble code {
  background: var(--bg-recessed);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  font-size: 0.85em;
  font-family: 'JetBrains Mono', monospace;
}
.bubble pre {
  background: var(--bg-recessed);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  overflow-x: auto;
  font-size: 0.8125rem;
  margin: 0 0 var(--space-2);
  font-family: 'JetBrains Mono', monospace;
}
.bubble pre code { background: none; border: none; padding: 0; }

.code-block-wrapper { position: relative; margin: 0 0 var(--space-2); }
.code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-default);
}
.code-block-wrapper:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { color: var(--copper); border-color: var(--copper-border); }

.msg-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  opacity: 0.35;
  transition: opacity var(--duration-fast) var(--ease-default);
  z-index: 1;
  color: var(--text-muted);
}
.msg .bubble:hover .msg-copy-btn { opacity: 0.6; }
.msg-copy-btn:hover { opacity: 1 !important; color: var(--copper); }
.msg-copy-btn:focus-visible { opacity: 0.6; }
.msg-copy-btn svg { width: 16px; height: 16px; }
.msg.user .msg-copy-btn { color: rgba(255, 255, 255, 0.9); }
.msg.user .msg-copy-btn:hover { color: #fff; }
.msg-copy-btn.copied { opacity: 1; color: var(--copper); }

.table-scroll-wrapper { overflow-x: auto; margin: 0 0 var(--space-2); }
.bubble table {
  border-collapse: collapse;
  font-size: 0.875rem;
  min-width: 60%;
}
.bubble th, .bubble td {
  text-align: left;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.bubble th {
  font-weight: 700;
  color: var(--text-body);
  border-bottom: 2px solid var(--border-strong);
}
.bubble tr:last-child td { border-bottom: none; }

.bubble blockquote {
  margin: 0 0 var(--space-2);
  padding-left: var(--space-3);
  border-left: 3px solid var(--copper-border);
  color: var(--text-body);
}

.mermaid-block { margin: 0 0 var(--space-2); }
.mermaid-preview { text-align: center; overflow-x: auto; }
.mermaid-preview svg { max-width: 100%; height: auto; }
.mermaid-preview p { margin: 0; line-height: 1.2; }
.mermaid-preview span, .mermaid-preview div { line-height: 1.2; }
.mermaid-loading, .mermaid-error {
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: var(--space-4);
}
.mermaid-source summary {
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.mermaid-source[open] summary { margin-bottom: var(--space-2); }

/* Inline images in chat bubbles */
.bubble .md-img-link { display: block; margin: 0 0 var(--space-2); }
.bubble .md-img {
  display: block;
  max-width: 100%;
  max-height: 340px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  cursor: zoom-in;
}

/* Inline map card — rendered under replies that link a place */
.map-card {
  margin: var(--space-2) 0 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-recessed);
}
.map-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 6px 10px;
  font-size: 0.75rem;
}
.map-card-place {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-card-open { flex-shrink: 0; }
.map-card-frame {
  display: block;
  width: 100%;
  height: 260px;
  border: 0;
}
@media (max-width: 640px) {
  .map-card-frame { height: 200px; }
}

.msg.thinking .bubble {
  color: var(--text-muted);
  font-style: italic;
  animation: thinking-pulse 1.5s ease-in-out infinite;
}

@keyframes thinking-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.bubble.nudge { animation: bubble-nudge 320ms var(--ease-default); }
@keyframes bubble-nudge {
  30% { transform: scale(1.05); }
  100% { transform: none; }
}

.chat-input.busy { opacity: 0.92; }

/* ---- draft cards: agent-queued actions rendered inside the thread ---- */
.msg.action-holder { justify-content: flex-start; }

.draft-card {
  width: min(92%, 46rem);
  background: var(--surface);
  border: 1px solid var(--copper);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.06));
}

.draft-card.resolved { border-color: var(--border); }

.draft-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

.draft-card-head .status-chip {
  margin-right: 0;
  font-size: 0.75rem;
  /* Chip labels are sentences ("Waiting for your approval"), not statuses. */
  text-transform: none;
}

.status-chip.pending {
  background: var(--status-amber-bg);
  border: 1px solid var(--status-amber-border);
  color: var(--status-amber);
}

.draft-card-title {
  font-weight: 600;
  font-size: 0.875rem;
}

.draft-card-meta {
  font-size: 0.8438rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.draft-card-body {
  margin: var(--space-2) 0 0;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-raised);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.8438rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.draft-card-body.collapsed {
  max-height: 7.5em;
  overflow: hidden;
  /* Fade the cut-off so "there is more" reads at a glance. */
  -webkit-mask-image: linear-gradient(to bottom, black 65%, transparent);
  mask-image: linear-gradient(to bottom, black 65%, transparent);
}

.draft-card-expand {
  border: none;
  background: none;
  color: var(--copper);
  font-size: 0.8125rem;
  padding: 4px 0;
  cursor: pointer;
}

.draft-card .unknown-warning { margin-top: var(--space-2); }

.draft-card-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  flex-wrap: wrap;
}

/* Flex/inline-flex display rules defeat the hidden attribute — the card
   toggles display/edit modes with [hidden], so pin it for everything
   inside a card (buttons included). */
.draft-card [hidden] { display: none !important; }

.draft-card-editor {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.draft-card-editor label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.draft-card-editor input,
.draft-card-editor textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.8438rem;
  font-family: inherit;
}

.draft-card-error {
  margin-top: var(--space-2);
  font-size: 0.8125rem;
  color: var(--status-red);
}

/* -- chat attachments: staging strip, drop overlay, bubble + card chips -- */

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-1) 0;
}
.chat-attachments[hidden] { display: none !important; }

.chat-attachments .att-chip { font-size: 0.75rem; padding: 3px 10px; }
.att-chip.uploading { color: var(--text-muted); font-style: italic; }

.chat-att-error {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--status-red);
}

.chat-drop-zone { position: relative; }

.chat-drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay-scrim, rgba(0, 0, 0, 0.18));
  border: 2px dashed var(--copper);
  border-radius: var(--radius-lg);
  pointer-events: none; /* drops fall through to the zone's own handler */
}
.chat-drop-overlay[hidden] { display: none !important; }

.chat-drop-overlay span {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--copper);
  background: var(--surface);
  border: 1px solid var(--copper-border);
  border-radius: var(--radius-full);
  padding: 10px 20px;
  box-shadow: var(--shadow-md);
}

.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

.msg.user .msg-attachments .att-chip {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.35);
  color: inherit;
}
.msg.user .msg-attachments .att-chip svg,
.msg.user .msg-attachments .att-size { color: inherit; opacity: 0.85; }

.draft-card-attachments {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-1);
}
.draft-card-attachments.editing { margin-top: var(--space-2); }

/* Approvals editor: attachments row + drop feedback while editing */
.edit-attachments {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.email-edit.drop-ready {
  outline: 2px dashed var(--copper);
  outline-offset: 4px;
  border-radius: var(--radius-md);
}
.mail-compose-view.drop-ready {
  outline: 2px dashed var(--copper);
  outline-offset: -6px;
  border-radius: var(--radius-lg);
}

.action-chat-link {
  display: inline-block;
  font-size: 0.8125rem;
  color: var(--copper);
  margin: var(--space-1) 0;
}

/* Tools inside a chat pane header (mail, calendar) and on the briefing
   chat — New chat + History live on every surface. */
.chat-head-tools {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  /* Pane headers are uppercase; the tools are controls, not headings. */
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}
.chat-head-tools .btn { white-space: nowrap; }

.mc-chat-tools {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-1);
}

/* ---- /chats: chat history across every surface ---- */
.chats-head {
  display: block;
  margin-bottom: var(--space-4);
}
.chats-head p { margin-top: var(--space-1); max-width: 60ch; }

.chats-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.chats-filters {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
}

.chats-filter {
  padding: 6px 14px;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.chats-filter:hover { color: var(--copper); border-color: var(--copper); }

.chats-filter.active {
  background: var(--copper-muted);
  border-color: var(--copper);
  color: var(--copper);
  font-weight: 600;
}

.chats-search {
  width: 260px;
  max-width: 100%;
  padding: 8px 12px;
  font-size: 0.875rem;
}

.chats-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}

.chats-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default);
}

.chats-row:last-child { border-bottom: none; }
.chats-row:hover { background: var(--surface-raised); }
.chats-row:focus-visible { outline: 2px solid var(--copper); outline-offset: -2px; }

.chats-row-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.chats-row-info { flex-shrink: 0; }

.chats-row-actions {
  display: flex;
  gap: var(--space-1);
  flex-shrink: 0;
}

.kind-badge {
  flex-shrink: 0;
  display: inline-block;
  min-width: 70px;
  text-align: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface-raised);
}

.kind-badge.kind-chat { color: var(--copper); border-color: var(--copper); background: var(--copper-muted); }
.kind-badge.kind-mail { color: var(--status-blue, #2563eb); border-color: currentColor; background: transparent; }
.kind-badge.kind-calendar { color: var(--status-green, #15803d); border-color: currentColor; background: transparent; }

/* Read-only transcript viewer */
.chats-viewer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.chats-viewer-backdrop[hidden] { display: none; }

.chats-viewer {
  width: min(720px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.chats-viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.chats-viewer-head > div {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.chats-viewer-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chats-viewer-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

.chats-viewer-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

@media (max-width: 640px) {
  .chats-row { flex-wrap: wrap; }
  .chats-row-title { flex-basis: 100%; order: -1; white-space: normal; }
}

.chat-tools {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding-top: var(--space-3);
}
.chat-tools[hidden] { display: none; }

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}
.btn.ghost:hover {
  color: var(--copper);
  background: var(--copper-muted);
  transform: none;
  box-shadow: none;
}
.btn.ghost.armed {
  color: var(--status-red);
  border-color: var(--status-red-border);
  background: var(--status-red-bg);
}

/* Floating pill composer */
.chat-input {
  display: flex;
  gap: var(--space-1);
  align-items: flex-end;
  padding: 6px;
  margin: var(--space-2) 0 var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  transition: border-color var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-normal) var(--ease-default),
              border-radius var(--duration-fast) var(--ease-default);
}
.chat-input.single-line { border-radius: var(--radius-full); }
.chat-input:focus-within {
  border-color: var(--copper);
  box-shadow: 0 0 0 2px rgba(199,140,92,0.12), var(--shadow-md);
}

.chat-input textarea {
  flex: 1;
  min-width: 0;
  min-height: 0;
  border: none;
  background: transparent;
  padding: 10px 12px;
  resize: none;
  overflow-y: hidden;
  line-height: 1.4;
  max-height: 7.8em; /* ~5 lines at 1.4 line-height + padding */
}
.chat-input textarea.scrollable { overflow-y: auto; }
.chat-input textarea:focus { box-shadow: none; outline: none; }

.chat-input .btn.icon,
.chat-input .btn.primary { border-radius: var(--radius-full); }
.chat-input .btn.icon { border-color: transparent; background: transparent; }
.chat-input .btn.icon:hover { background: var(--copper-muted); transform: none; box-shadow: none; }

#mic-btn.listening,
.chat-input .btn.icon.listening {
  background: var(--status-red);
  color: var(--text-primary);
  border-color: var(--status-red);
}

/* --- Voice mode (hands-free conversation) -----------------------------
   The mic button IS the voice UI: its colour carries the state, the
   composer placeholder carries the wording. No separate bar. */
.voice-mic { transition: background 200ms var(--ease-default, ease), box-shadow 200ms; }
.chat-input .btn.icon.voice-connecting,
.chat-input .btn.icon.voice-connecting:hover,
.voice-mic.voice-connecting {
  background: var(--surface-accent);
  color: var(--text-muted);
  animation: voicePulse 1.2s infinite;
}
.chat-input .btn.icon.voice-listening,
.chat-input .btn.icon.voice-listening:hover,
.voice-mic.voice-listening {
  background: var(--status-red);
  color: var(--text-primary);
  border-color: var(--status-red);
  animation: voiceGlow 2s infinite;
}
.chat-input .btn.icon.voice-thinking,
.chat-input .btn.icon.voice-thinking:hover,
.voice-mic.voice-thinking {
  background: var(--status-amber);
  color: var(--text-inverse);
  border-color: var(--status-amber);
  animation: voicePulse 0.9s infinite;
}
.chat-input .btn.icon.voice-speaking,
.chat-input .btn.icon.voice-speaking:hover,
.voice-mic.voice-speaking {
  background: var(--copper);
  color: var(--text-inverse);
  border-color: var(--copper);
  animation: voiceGlow 0.9s infinite;
}
.chat-input .btn.icon.voice-error,
.chat-input .btn.icon.voice-error:hover,
.voice-mic.voice-error {
  background: var(--status-red-bg);
  color: var(--status-red);
  border: 1px solid var(--status-red-border);
}
@keyframes voicePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@keyframes voiceGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(199, 92, 92, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(199, 92, 92, 0); }
}
/* Voice-state wording lives in the placeholder — keep it readable. */
.chat-input input[type=text]::placeholder { transition: color 200ms; }

@media (prefers-reduced-motion: reduce) {
  .voice-mic { animation: none !important; }
}

/* --- People ------------------------------------------------------------ */

.people-head { margin-bottom: var(--space-5); }
.people-head h1 { font-family: var(--font-serif); font-size: 1.5rem; font-weight: 700; }
.people-tier { margin-bottom: var(--space-4); }
.people-tier-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.people-tier-head h2 { display: inline; }
.people-tier details summary { cursor: pointer; list-style: none; }
.person-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border-subtle, rgba(128, 128, 128, 0.15));
  text-decoration: none;
  color: inherit;
}
.person-row:hover .person-name { text-decoration: underline; }
.person-avatar {
  flex-shrink: 0;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  background: var(--bg-subtle, rgba(128, 128, 128, 0.12));
}
.person-avatar.lg { width: 3.2rem; height: 3.2rem; font-size: 1.3rem; }
.person-avatar.tier-warm { background: rgba(46, 160, 67, 0.18); }
.person-avatar.tier-cooling { background: rgba(212, 130, 30, 0.22); }
.person-avatar.tier-cold { background: rgba(128, 128, 128, 0.12); opacity: 0.75; }
.person-avatar.tier-new,
.person-avatar.tier-learning { background: rgba(9, 105, 218, 0.14); }
.person-avatar.tier-muted { background: rgba(128, 128, 128, 0.1); opacity: 0.7; }
.person-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.person-name { font-weight: 600; }
.person-followed {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--copper);
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 4px;
  vertical-align: 2px;
}
.person-why { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-meta { flex-shrink: 0; text-align: right; }
.person-head-row { display: flex; gap: var(--space-4); align-items: center; }
.person-head-main h1 { font-family: var(--font-serif); font-size: 1.375rem; }
.person-warmth.tier-cooling strong { color: rgb(180, 105, 20); }
.person-warmth.tier-warm strong { color: rgb(40, 130, 55); }
.person-actions { margin-top: var(--space-3); display: flex; gap: var(--space-2); }
.person-notes { white-space: pre-wrap; }
.person-history-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border-subtle, rgba(128, 128, 128, 0.15));
}
.person-history-kind { flex-shrink: 0; opacity: 0.6; }
.person-history-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
@media (max-width: 640px) {
  .person-meta { display: none; }
  .person-why { white-space: normal; }
}

/* --- Mission Control -------------------------------------------------- */

.mc-head { margin-bottom: var(--space-6); animation: rise-in 420ms var(--ease-default) backwards; }

.mc-briefing {
  margin-bottom: var(--space-5);
  border-left: 3px solid var(--copper);
}
.mc-brief-content > p,
.mc-briefing > p {
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  line-height: 1.65;
  margin: 0 0 var(--space-3);
  overflow-wrap: anywhere;
}
.mc-briefing-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.mc-briefing .brief-headline {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 600;
}
.brief-needs { margin: 0 0 var(--space-3); }
.brief-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border-subtle, rgba(128, 128, 128, 0.15));
}
.brief-row .brief-line {
  font-size: 0.9375rem;
  line-height: 1.45;
  min-width: 0;
  overflow-wrap: anywhere;
}
.brief-row .brief-act { flex-shrink: 0; }
.mc-briefing .brief-day { font-size: 0.9375rem; margin-bottom: var(--space-3); }
.brief-voices {
  margin: 0 0 var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md, 8px);
  background: var(--bg-subtle, rgba(128, 128, 128, 0.07));
}
.brief-voices-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.6;
  margin-bottom: var(--space-2);
}
.brief-voice {
  font-size: 0.9375rem;
  line-height: 1.5;
  margin-bottom: var(--space-2);
  overflow-wrap: anywhere;
}
.brief-voice:last-child { margin-bottom: 0; }
/* Briefing grid: content 2/3, chat 1/3 on wide screens */
.mc-briefing-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}
@media (min-width: 768px) {
  .mc-briefing-grid {
    grid-template-columns: 2fr 1fr;
  }
}
.mc-brief-content { min-width: 0; }
.mc-brief-chat { min-width: 0; }

/* Chat column inside the briefing card */
.mc-brief-chat {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border-subtle, rgba(128, 128, 128, 0.15));
  padding-top: var(--space-3);
}
@media (min-width: 768px) {
  .mc-brief-chat {
    border-top: none;
    border-left: 1px solid var(--border-subtle, rgba(128, 128, 128, 0.15));
    padding-top: 0;
    padding-left: var(--space-4);
    max-height: 400px;
  }
}
.mc-brief-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  min-height: 0;
  max-height: 280px;
}
@media (min-width: 768px) {
  .mc-brief-chat-messages { max-height: none; }
}
.mc-brief-chat-messages:empty { display: none; }
.mc-brief-chat-messages .msg { margin: 8px 0; }
.mc-brief-chat-messages .msg .bubble { font-size: 0.8125rem; padding: 8px 12px; }
.mc-brief-chat-empty {
  flex: 1;
  display: flex;
  align-items: flex-end;
  margin-bottom: var(--space-2);
}
.mc-brief-suggestions {
  justify-content: flex-start;
  margin-top: 0;
  gap: var(--space-1);
}
.mc-brief-suggestions .suggestion {
  font-size: 0.8125rem;
  padding: 5px 12px;
}
.mc-brief-chat-input {
  margin: 0;
  box-shadow: none;
  border-color: var(--border-subtle, rgba(128, 128, 128, 0.15));
}
.mc-brief-chat-input textarea { padding: 8px 12px; font-size: 0.875rem; }
.mc-brief-chat-standalone {
  border-top: none;
  padding-top: 0;
  margin-bottom: var(--space-5);
}

.mc-head h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.375rem, 3vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.mc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  align-items: start;
}
.mc-col { min-width: 0; display: flex; flex-direction: column; gap: var(--space-5); }
.mc-col .card { margin: 0; }
@media (max-width: 767px) {
  .mc-page { overflow-x: hidden; }
  .mc-briefing { max-width: 100%; min-width: 0; overflow: hidden; }
  .mc-grid { display: flex; flex-direction: column; }
  .mc-col { display: contents; }
  .mc-grid .card { max-width: 100%; min-width: 0; overflow: hidden; }
  #panel-calendar { order: 1; }
  #panel-tasks { order: 2; }
  #panel-actions { order: 3; }
  #panel-email { order: 4; }
  #panel-health { order: 5; }
}

.mc-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.mc-panel-head h2 { font-size: 0.9375rem; font-weight: 700; }

.mc-nudge { text-align: center; padding: var(--space-7); }
.mc-nudge .btn { margin-top: var(--space-3); }

/* Tasks */
.task-group-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: var(--space-3) 0 var(--space-1);
}
.task-group-label.overdue { color: var(--status-red); }
.task-group-label.due { color: var(--copper); }

.task-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  transition: opacity var(--duration-normal) var(--ease-default);
}
.task-row:last-of-type { border-bottom: none; }
.task-row.done { opacity: 0.35; }
.task-row.done .task-title { text-decoration: line-through; }

.task-check {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border-strong);
  background: transparent;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
}
.task-check:hover { border-color: var(--copper); background: var(--copper-muted); }
.task-row.done .task-check { background: var(--status-green); border-color: var(--status-green); }

.task-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px var(--space-3);
}
.task-title { flex: 1; min-width: 65%; }
.task-due { flex-shrink: 0; font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 0.8125rem; }
#quick-task { margin-top: var(--space-4); }

/* Email snapshot */
.email-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  min-width: 0;
}
.email-row:last-of-type { border-bottom: none; }
.email-row:hover .email-subject { color: var(--copper); }
.unread-dot {
  width: 7px; height: 7px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  background: var(--copper);
  align-self: center;
}
.email-sender { font-weight: 600; flex-shrink: 0; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-subject {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-body);
  transition: color var(--duration-fast) var(--ease-default);
}
.email-age { flex-shrink: 0; font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 0.8125rem; }

.mc-approvals-link {
  display: block;
  margin-top: var(--space-3);
  font-size: 0.875rem;
  font-weight: 600;
}

/* Calendar timeline */
.next-event {
  display: flex;
  flex-direction: column;
  background: var(--copper-muted);
  border: 1px solid var(--copper-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
}
.next-event-lead { font-size: 0.75rem; font-weight: 700; color: var(--copper); text-transform: uppercase; letter-spacing: 0.05em; }
.next-event-title { font-weight: 600; }

.timeline {
  position: relative;
  height: 340px;
  margin-left: 44px;
}
.timeline-hour {
  position: absolute;
  left: -44px;
  right: 0;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}
.timeline-hour span { position: relative; top: -0.7em; background: var(--surface); padding-right: 4px; }
.timeline-now {
  position: absolute;
  left: -6px;
  right: 0;
  border-top: 2px solid var(--status-red);
  z-index: 2;
}
.timeline-now::before {
  content: '';
  position: absolute;
  left: 0; top: -5px;
  width: 8px; height: 8px;
  border-radius: var(--radius-full);
  background: var(--status-red);
}
.timeline-event {
  position: absolute;
  left: 8px;
  right: 0;
  min-height: 22px;
  background: var(--copper-muted);
  border-left: 3px solid var(--copper);
  border-radius: var(--radius-sm);
  padding: 3px 10px;
  overflow: hidden;
  font-size: 0.875rem;
  z-index: 1;
}
.timeline-event.conflict { border-left-color: var(--status-red); }
.timeline-event.conflict.lane-0 { right: 51%; }
.timeline-event.lane-1 { left: 51%; }
.timeline-event.past { opacity: 0.45; }
.timeline-event-title { font-weight: 600; display: block; line-height: 1.3; }
.timeline-event-time { color: var(--text-body); font-size: 0.75rem; }

/* Quick actions */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}
.btn.quick { justify-content: flex-start; padding: 12px 16px; }

/* Health strip */
.mc-health {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
  color: var(--text-body);
}
.health-item { display: inline-flex; align-items: center; gap: 6px; text-transform: capitalize; }
.health-dot { width: 8px; height: 8px; border-radius: var(--radius-full); }
.health-dot.ok { background: var(--status-green); }
.health-dot.err { background: var(--status-red); }
.mc-health .btn { margin-left: auto; }

/* --- Welcome (onboarding) --------------------------------------------- */

.welcome-page {
  max-width: 620px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-9) var(--space-5) var(--space-10);
}

.welcome-head {
  text-align: center;
  margin-bottom: var(--space-8);
  animation: rise-in 480ms var(--ease-default) backwards;
}
.welcome-head h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-2);
}

.setup-step {
  display: flex;
  gap: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-4);
  animation: rise-in 420ms var(--ease-default) backwards;
  transition: border-color var(--duration-normal) var(--ease-default);
}
.setup-step:nth-of-type(2) { animation-delay: 80ms; }
.setup-step.done { border-color: var(--status-green-border); }

.step-marker {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--copper-muted);
  border: 1px solid var(--copper-border);
  color: var(--copper);
  font-weight: 700;
}
.setup-step.done .step-marker {
  background: var(--status-green-bg);
  border-color: var(--status-green-border);
  color: var(--status-green);
}

.step-body { flex: 1; min-width: 0; }
.step-body h2 {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.welcome-foot {
  text-align: center;
  margin-top: var(--space-7);
  animation: rise-in 420ms var(--ease-default) 160ms backwards;
}
.btn.big { padding: 14px 32px; font-size: 0.9375rem; }

/* Onboarding: step rail + plan picker */
.welcome-page:has(.welcome-wide) { max-width: 980px; }
.welcome.welcome-wide { max-width: 980px; margin: 0 auto; }

.welcome-steps {
  display: flex;
  justify-content: center;
  gap: var(--space-6);
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-7);
  counter-reset: wstep;
  animation: rise-in 420ms var(--ease-default) 60ms backwards;
}
.welcome-steps li {
  counter-increment: wstep;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
}
.welcome-steps li::before {
  content: counter(wstep);
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.75rem;
}
.welcome-steps li.current { color: var(--copper); }
.welcome-steps li.current::before {
  background: var(--copper-muted);
  border-color: var(--copper-border);
  color: var(--copper);
}
.welcome-steps li.done { color: var(--status-green); }
.welcome-steps li.done::before {
  content: "✓";
  background: var(--status-green-bg);
  border-color: var(--status-green-border);
  color: var(--status-green);
}

.plan-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
  gap: var(--space-5);
  align-items: stretch;
}
.plan-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  animation: rise-in 420ms var(--ease-default) backwards;
}
.plan-card:nth-child(2) { animation-delay: 60ms; }
.plan-card:nth-child(3) { animation-delay: 120ms; }
.plan-card.hero {
  border-color: var(--copper-border);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
}
.plan-flag {
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--copper);
  color: var(--bg);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 12px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.plan-card h2 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  margin-bottom: var(--space-2);
}
.plan-price { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
.plan-price span { font-size: 0.875rem; font-weight: 500; color: var(--text-muted); }
.plan-credits {
  font-size: 0.875rem;
  color: var(--text-body);
  margin: var(--space-3) 0;
  min-height: 2.6em;
}
.plan-features {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-5);
  flex: 1;
}
.plan-features li {
  font-size: 0.875rem;
  color: var(--text-body);
  padding: 5px 0 5px 24px;
  position: relative;
}
.plan-features li::before {
  content: "✓";
  position: absolute;
  left: 2px;
  color: var(--copper);
  font-weight: 700;
}
.plan-trial {
  font-size: 0.8125rem;
  color: var(--status-green);
  font-weight: 600;
  margin-bottom: var(--space-3);
}
.plan-footnote { text-align: center; margin-top: var(--space-6); }

.connect-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: var(--space-4) 0 var(--space-3);
}

/* Nell-led welcome: the connect/done steps are a conversation. The action
   strip (connect buttons / Mission Control) sits between Nell's messages
   and the composer — the click-through path stays one glance away. */
.welcome-nell {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  animation: rise-in 420ms var(--ease-default) backwards;
}
.welcome-chat-messages {
  flex: none;
  max-height: min(46vh, 30rem);
  min-height: 9rem;
  overflow-y: auto;
  padding: var(--space-2) var(--space-1);
}
.welcome-actions {
  text-align: center;
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.welcome-actions .connect-buttons {
  justify-content: center;
  margin: 0 0 var(--space-2);
}
.welcome-actions .muted.small { margin: var(--space-2) 0 0; }

/* Auth: social sign-in divider + full-width Google button */
.auth-card .google-btn.wide {
  width: 100%;
  justify-content: center;
  margin-top: var(--space-4);
}
.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-4) 0 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--copper-border);
  border-top-color: var(--copper);
  border-radius: var(--radius-full);
  display: inline-block;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Credits: nav meter, degradation banner, Plan & usage panel -------- */

.credit-meter {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--status-green-border);
  background: var(--status-green-bg);
  color: var(--status-green);
  text-decoration: none;
  white-space: nowrap;
}
.credit-meter.warn {
  border-color: var(--copper-border);
  background: var(--copper-muted);
  color: var(--copper);
}
.credit-meter.over {
  border-color: var(--status-red-border);
  background: var(--status-red-bg);
  color: var(--status-red);
}
.credit-meter[hidden] { display: none; }

.credit-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: 10px var(--space-5);
  font-size: 0.875rem;
  background: var(--status-red-bg);
  border-bottom: 1px solid var(--status-red-border);
  color: var(--text-heading);
}
.credit-banner[hidden] { display: none; }

.flash-success {
  background: var(--status-green-bg);
  border-color: var(--status-green-border);
}

.billing-plan-name {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  margin-right: var(--space-2);
}
.billing-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.chip-danger {
  background: var(--status-red-bg) !important;
  color: var(--status-red) !important;
  border-color: var(--status-red-border) !important;
}
.billing-degraded {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

/* Pre-cancel card: calm, factual, no guilt. */
.billing-cancel-card {
  margin-top: var(--space-4);
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.billing-cancel-card[hidden] { display: none !important; }
.billing-cancel-card h3 {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  margin-bottom: var(--space-2);
}
.billing-cancel-facts {
  margin: var(--space-3) 0;
  padding-left: 18px;
  line-height: 1.7;
}
.billing-cancel-card textarea {
  width: 100%;
  margin-top: var(--space-1);
  resize: vertical;
}
.billing-cancel-card .billing-actions { margin-top: var(--space-3); }

.credit-figures { margin: var(--space-3) 0; }
.credit-big {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.credit-big span {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 6px;
}

.credit-track {
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--bg-recessed);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-top: var(--space-3);
}
.credit-track-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--status-green);
  transition: width 300ms var(--ease-default);
}
.credit-track-fill.warn { background: var(--copper); }
.credit-track-fill.over { background: var(--status-red); }

.burn-chart { margin-top: var(--space-4); }
.burn-svg {
  width: 100%;
  height: 120px;
  display: block;
}
.burn-svg rect { fill: var(--copper); opacity: 0.75; }
.burn-svg rect:hover { opacity: 1; }
.burn-axis {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-1);
}

.billing-ledger { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.billing-ledger td {
  padding: 8px 10px 8px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.billing-ledger tr:last-child td { border-bottom: none; }
.ledger-amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.ledger-amt.pos { color: var(--status-green); }
.ledger-amt.neg { color: var(--text-muted); }

/* --- Provider Cards & Google Button ----------------------------------- */

.provider-card {
  display: flex;
  gap: var(--space-5);
  align-items: flex-start;
}
.provider-mark {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--bg-recessed);
  border: 1px solid var(--border);
}
.provider-body { flex: 1; min-width: 0; }
.provider-body h2 { margin-bottom: var(--space-1); }

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--surface-raised);
  border-color: var(--border);
  font-weight: 600;
}

.advanced-connect summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-body);
}
.advanced-connect summary:hover { color: var(--copper); }
.advanced-connect[open] summary { margin-bottom: var(--space-3); }

/* --- Approvals -------------------------------------------------------- */

.action-card .action-summary {
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: var(--space-2);
}

.email-preview {
  font-size: 0.875rem;
  border-left: 3px solid var(--copper-border);
  padding-left: var(--space-3);
  margin: var(--space-3) 0;
  color: var(--text-body);
}

.email-body {
  white-space: pre-wrap;
  font-family: var(--font-sans);
  background: var(--bg-recessed);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-primary);
  margin-top: var(--space-2);
}

.unknown-recipient {
  color: var(--status-amber);
  font-weight: 600;
  border-bottom: 1px dashed var(--status-amber);
}

.unknown-warning {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-3) 0;
  padding: var(--space-2) var(--space-3);
  background: var(--status-amber-bg);
  border: 1px solid var(--status-amber-border);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  color: var(--status-amber);
  font-weight: 500;
}

.unknown-warning svg { flex-shrink: 0; }

/* Resolved (Recent) cards — click to drill into the full correspondence. */
details.resolved-card > summary {
  list-style: none;
  cursor: pointer;
  margin: calc(-1 * var(--space-5)) calc(-1 * var(--space-6));
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-lg);
}
details.resolved-card[open] > summary {
  margin-bottom: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
details.resolved-card > summary::-webkit-details-marker { display: none; }
details.resolved-card > summary:hover { background: var(--bg-recessed); }
details.resolved-card > summary:focus-visible {
  outline: 2px solid var(--copper);
  outline-offset: -2px;
}
details.resolved-card[data-empty] > summary { cursor: default; }
details.resolved-card[data-empty] > summary:hover { background: none; }

.resolved-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.resolved-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.9375rem;
  overflow-wrap: anywhere;
}
.resolved-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}
details.resolved-card[open] .resolved-chevron { transform: rotate(90deg); }

.resolved-meta { display: block; margin-top: var(--space-1); }
.resolved-meta .action-chat-link { margin-left: var(--space-2); }
.resolved-result { display: block; margin-top: 2px; overflow-wrap: anywhere; }

.resolved-detail {
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
  margin-top: var(--space-3);
  overflow-wrap: anywhere;
}
.resolved-detail .email-preview { margin-bottom: 0; }
.resolved-detail .rule-origin { margin-bottom: var(--space-2); }
.sent-provenance { margin-bottom: var(--space-2); }
.signature-note { margin-top: calc(-1 * var(--space-2)); }
.resolved-detail > .action-chat-link { margin-top: var(--space-3); }

@media (prefers-reduced-motion: reduce) {
  .resolved-chevron { transition: none; }
}

/* Track the mobile .card padding (640px override) so the summary hit-area
   stays flush with the card edge instead of poking past it. */
@media (max-width: 640px) {
  details.resolved-card > summary {
    margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-5));
    padding: var(--space-4) var(--space-5);
  }
}

.email-edit {
  margin: var(--space-3) 0;
}

.email-edit label {
  display: block;
  margin: var(--space-2) 0 var(--space-1);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-body);
}

.email-edit input[type=text],
.email-edit textarea {
  padding: 8px 12px;
  font-size: 0.875rem;
  margin-top: var(--space-1);
}

.email-edit textarea {
  line-height: 1.6;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

/* --- Connections ------------------------------------------------------ */

.connection {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.connection-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.connection-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
  align-items: center;
}

.connection-note {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-body);
}

/* "Set this up with Nell" strip — the conversational path into a settings
   note, sitting above the raw editor for those who'd rather type. */
.card.with-nell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  border-color: var(--copper-border);
  background: var(--copper-muted);
}
.card.with-nell h2 { margin-bottom: var(--space-1); }
.card.with-nell .with-nell-body { flex: 1 1 20rem; min-width: 0; }
.card.with-nell .with-nell-body p { margin: 0; }
.card.with-nell .btn { flex-shrink: 0; }
.connection-note[hidden] { display: none !important; }

.connection .muted { margin-left: var(--space-2); }

/* --- Calendar (agenda view) ------------------------------------------- */

.agenda-day { margin-bottom: var(--space-7); }

.agenda-day-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.agenda-day-name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
}
.agenda-day-name.today { color: var(--copper); }
.agenda-day-date {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.event-row {
  display: flex;
  align-items: stretch;
  gap: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  transition: border-color var(--duration-fast) var(--ease-default);
}
.event-row:hover { border-color: var(--border-strong); }

.event-time {
  display: flex;
  flex-direction: column;
  flex: 0 0 52px;
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  line-height: 1.5;
}
.event-time-start { font-weight: 600; color: var(--text-primary); }
.event-time-end { color: var(--text-muted); }

.event-rail {
  flex: 0 0 3px;
  border-radius: var(--radius-full);
  background: var(--copper);
  opacity: 0.55;
}
.event-rail.warn { background: var(--status-red); opacity: 0.7; }

.event-body { flex: 1; min-width: 0; align-self: center; }
.event-title { font-weight: 600; }
.event-meta {
  color: var(--text-body);
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.warn {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  padding: 1px 8px;
  margin-left: var(--space-2);
  vertical-align: 2px;
  background: var(--status-amber-bg);
  border: 1px solid var(--status-amber-border);
  color: var(--status-amber);
}

.chip.task-remind {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  gap: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius-full);
  padding: 1px 8px;
  margin-left: var(--space-2);
  background: var(--surface-raised, var(--surface));
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* --- Calendar (legacy markdown block) --------------------------------- */

.markdown {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6) 28px;
  white-space: pre-wrap;
  font-size: 0.875rem;
  line-height: 1.7;
}

/* --- Responsive ------------------------------------------------------- */

@media (max-width: 640px) {
  .topnav {
    flex-wrap: wrap;
    height: auto;
    padding: var(--space-3) var(--space-4);
    gap: var(--space-2);
  }

  .navlinks {
    order: 3;
    flex: 0 0 100%;
    align-items: center;
    min-width: 0;
    overflow: hidden;
  }

  .navuser { margin-left: auto; }

  .navlinks a {
    white-space: nowrap;
    font-size: 0.75rem;
    padding: 6px 10px;
  }

  .navuser {
    font-size: 0.75rem;
  }

  .nav-more-btn {
    display: inline-flex;
    order: 3;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-body);
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 5px 12px;
    border-radius: var(--radius-full);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--duration-fast) var(--ease-default);
  }
  .nav-more-btn:active,
  .nav-more-btn.open {
    background: var(--surface-accent);
    color: var(--text-primary);
  }

  .nav-overflow {
    display: flex;
    flex-direction: column;
    position: absolute;
    right: var(--space-4);
    top: 100%;
    margin-top: var(--space-1);
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    z-index: 101;
    padding: var(--space-2);
    min-width: 160px;
    animation: nav-overflow-in var(--duration-normal) var(--ease-default);
  }
  .nav-overflow[hidden] { display: none; }
  .nav-overflow a {
    text-decoration: none;
    color: var(--text-body);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-weight: 500;
    transition: background var(--duration-fast) var(--ease-default);
  }
  .nav-overflow a:hover,
  .nav-overflow a:active {
    background: var(--surface-accent);
    color: var(--text-primary);
  }
  .nav-overflow a.active {
    background: var(--copper-muted);
    color: var(--copper);
  }

  @keyframes nav-overflow-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .nav-overflow-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 99;
  }
  .nav-overflow-backdrop[hidden] { display: none; }

  .page {
    padding: var(--space-5) var(--space-4) var(--space-8);
  }

  .page-head { flex-direction: column; align-items: flex-start; gap: var(--space-3); }
  .page-head h1 { font-size: 1.125rem; }

  .card { padding: var(--space-4) var(--space-5); }

  .auth-card { padding: var(--space-6); }

  .form-row { flex-direction: column; }
  .form-row label.narrow { flex: 1; }

  .msg .bubble { max-width: 88%; }
}

/* --- Scrollbar Styling (webkit) --------------------------------------- */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Mail workspace ---------------------------------------------------- */

.mail-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0 var(--space-5);
  min-height: 0;
}

.mail-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(340px, 520px);
  gap: var(--space-5);
  padding: var(--space-5) 0;
  min-height: 0;
}

.mail-left,
.mail-chat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* -- list view -- */

.mail-list-view,
.mail-read-view {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.mail-list-view[hidden],
.mail-read-view[hidden] { display: none; }

.mail-list-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5) 0;
}

.mail-list-head .mail-sync {
  margin-left: auto;
  align-self: center;
}

.mail-list-head h1 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.mail-unread-count {
  font-size: 0.75rem;
  color: var(--copper);
}

.mail-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.mail-filter {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--text-body);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 4px 12px;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
}

.mail-filter:hover { border-color: var(--border-strong); color: var(--text-primary); }

.mail-filter.active {
  background: var(--copper-muted);
  border-color: var(--copper-border);
  color: var(--copper);
}

.mail-rows {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  overscroll-behavior-y: contain;
}

/* -- pull to refresh -- */
.ptr-indicator {
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ptr-indicator.releasing {
  transition: height 0.25s var(--ease-default);
}
.ptr-ring {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--copper);
  border-radius: 50%;
  opacity: 0.5;
  transition: opacity 0.15s;
}
.ptr-indicator.ready .ptr-ring { opacity: 1; }
.ptr-indicator.refreshing .ptr-ring {
  opacity: 1;
  animation: ptr-spin 0.7s linear infinite;
}
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* -- sync indicator (shared by pull-to-refresh + Sync button) -- */
.mail-sync-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 8px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.mail-sync-bar[hidden] { display: none; }
.sync-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--copper);
  border-radius: 50%;
  animation: sync-spin 0.8s linear infinite;
}
@keyframes sync-spin { to { transform: rotate(360deg); } }

.mail-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5) var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default);
}

.mail-row:hover { background: var(--surface-raised); }
.mail-row:focus-visible { outline: 2px solid var(--copper); outline-offset: -2px; }

.mail-row-tick {
  padding: 2px var(--space-1) 0 var(--space-2);
  cursor: pointer;
}

.mail-row-main { flex: 1; min-width: 0; }

.mail-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
}

.mail-row-sender {
  font-size: 0.875rem;
  color: var(--text-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-row.unread .mail-row-sender {
  color: var(--text-primary);
  font-weight: 600;
}

.mail-row.unread .mail-row-sender::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--copper);
  margin-right: 7px;
  vertical-align: 1px;
}

.mail-row-age {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.mail-row-subject {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.mail-row.unread .mail-row-subject { color: var(--text-body); }

.mail-row-atts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

/* ---- Swipe-to-act -------------------------------------------------- */

.mail-row-swipe {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.mail-row-swipe .mail-row {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-bottom: none;
  will-change: transform;
  touch-action: pan-y;
}

.swipe-actions {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: stretch;
}

.swipe-actions-left { left: 0; }
.swipe-actions-right { right: 0; }

.swipe-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  border: none;
  padding: 0 var(--space-2);
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #fff;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.swipe-action:active { filter: brightness(0.85); }

.swipe-action-unread { background: var(--copper); }
.swipe-action-archive { background: var(--text-muted); }
.swipe-action-trash { background: var(--status-red); }

@media (prefers-reduced-motion: reduce) {
  .mail-row-swipe .mail-row { transition: none !important; }
}

.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6875rem;
  color: var(--text-body);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 1px 8px;
  max-width: 220px;
}

.att-chip svg { flex-shrink: 0; color: var(--text-muted); }

.att-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.att-size { color: var(--text-muted); flex-shrink: 0; }

a.att-download {
  text-decoration: none;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default);
}
a.att-download:hover {
  border-color: var(--copper-border);
  color: var(--copper);
}

/* -- empty states -- */

.mail-empty {
  text-align: center;
  padding: var(--space-9) var(--space-5);
  color: var(--text-body);
}

.mail-empty h2 {
  font-family: var(--font-serif);
  color: var(--text-primary);
  font-size: 1.125rem;
  margin-bottom: var(--space-2);
}

.mail-empty p { font-size: 0.8125rem; color: var(--text-muted); margin-bottom: var(--space-4); }

/* -- reading view -- */

.mail-read-head {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.mail-read-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  min-height: 0;
}

.mail-read-body h2 {
  font-family: var(--font-serif);
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-2);
}

.mail-read-meta {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: 0.8125rem;
  color: var(--text-body);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-3);
}

.mail-read-sender { overflow: hidden; text-overflow: ellipsis; }

.mail-read-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.mail-read-attachments:not(:empty) { margin-bottom: var(--space-3); }

.mail-read-text {
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* -- original-HTML view -- */

.mail-read-html {
  display: block;
  width: 100%;
  min-height: 120px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.mail-read-html[hidden] { display: none; }

.mail-view-toggle {
  display: inline-flex;
  gap: 2px;
  margin-bottom: var(--space-3);
  background: var(--bg-recessed);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 2px;
}

.mail-view-toggle[hidden] { display: none; }

.viewbtn {
  border: none;
  background: none;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--text-body);
  padding: 3px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
}

.viewbtn.active {
  background: var(--surface-raised);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* -- attachment viewer modal -- */

.att-chip.att-preview {
  cursor: pointer;
  font-family: var(--font-sans);
  transition: border-color var(--duration-fast) var(--ease-default),
              background var(--duration-fast) var(--ease-default);
}

.att-chip.att-preview:hover {
  border-color: var(--copper);
  background: var(--surface-raised);
}

.att-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.att-modal-backdrop[hidden] { display: none; }

.att-modal {
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-overlay);
  width: min(960px, 100%);
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: rise-in 200ms var(--ease-default);
}

.att-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.att-modal-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.att-modal-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.att-modal-close { font-size: 1.05rem; line-height: 1; }

.att-modal-body {
  overflow: auto;
  padding: var(--space-4);
  min-height: 160px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.att-modal-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

.att-modal-body .att-pdf {
  width: 100%;
  height: 74dvh;
  border: none;
  border-radius: var(--radius-sm);
  background: #fff;
}

.att-modal-body .att-text {
  width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.att-loading,
.att-fallback {
  align-self: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  padding: var(--space-6) var(--space-4);
  max-width: 400px;
}

.mail-row-selectlabel { cursor: pointer; display: inline-flex; gap: var(--space-2); align-items: center; }

/* -- chat pane -- */

.mail-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-body);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.mail-sheet-close { display: none; font-size: 1rem; line-height: 1; }

.mail-chat-messages { padding: var(--space-4); }

.mail-chat-empty { margin-top: 8vh; }
.mail-chat-empty p { font-size: 0.8125rem; line-height: 1.7; }

.mail-chat .chat-input { margin: 0 var(--space-4) var(--space-4); }

.mail-selection {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-4);
}

.mail-selection[hidden] { display: none; }

.sel-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--copper);
  background: var(--copper-muted);
  border: 1px solid var(--copper-border);
  border-radius: var(--radius-full);
  padding: 2px 4px 2px 10px;
  max-width: 240px;
}

.sel-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sel-chip-x {
  background: none;
  border: none;
  color: var(--copper);
  font-size: 0.875rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-full);
}

.sel-chip-x:hover { background: var(--copper-strong); color: var(--text-primary); }

/* -- ask pill + bottom sheet (mobile) -- */

.mail-ask-pill { display: none; }
.mail-sheet-backdrop { display: none; }

@media (max-width: 900px) {
  .mail-page { padding: 0 var(--space-3); }

  .mail-layout {
    grid-template-columns: 1fr;
    padding: var(--space-3) 0 calc(var(--space-10) + var(--space-6));
  }

  /* Chat pane becomes a bottom sheet. */
  .mail-chat {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    height: 78dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-overlay);
    transform: translateY(105%);
    transition: transform 280ms var(--ease-default);
    z-index: 60;
  }

  .mail-chat.open { transform: translateY(0); }

  .mail-sheet-close { display: inline-flex; }

  .mail-ask-pill {
    display: block;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    background: var(--copper);
    color: #1A1A1A;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-full);
    padding: 12px 22px;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    z-index: 50;
  }

  .mail-ask-pill:active { background: var(--copper-hover); }

  .mail-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 55;
  }

  .mail-sheet-backdrop[hidden] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .mail-chat { transition: none; }
}

/* --- Provider keys & model routing -------------------------------------- */

.provider-list, .tier-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.provider-row, .tier-row {
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
  background: var(--surface-raised, transparent);
}

.provider-head, .tier-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.provider-name, .tier-name { font-weight: 600; color: var(--text-body); }

.provider-head .status-chip { margin-left: auto; }
.provider-head a { margin-left: auto; }

.routing-toggle {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin: var(--space-3) 0;
}
.routing-toggle label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-weight: 400;
}


.tier-row .inline-form select { flex: 0 0 auto; max-width: 45%; }
.tier-row .inline-form input { min-width: 0; }

@media (max-width: 640px) {
  .tier-row .inline-form { flex-wrap: wrap; }
  .tier-row .inline-form select { flex: 1 1 100%; max-width: none; }
  .tier-row .inline-form input { flex: 1 1 100%; }
}

/* --- Theme toggle -------------------------------------------------------- */

.theme-toggle {
  display: flex;
  gap: var(--space-1);
  margin: var(--space-3) 0;
  background: var(--bg-recessed);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
}

.theme-opt {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-body);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 0;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
}

.theme-opt:hover { color: var(--text-primary); }

.theme-opt.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--copper);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* --- Text size setting -------------------------------------------------- */

.fontscale-control {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-3) 0;
}

.fontscale-a {
  font-family: var(--font-serif);
  color: var(--text-muted);
  line-height: 1;
}

/* Fixed px on purpose: the slider's own labels must not scale away. */
.fontscale-a.small { font-size: 13px; }
.fontscale-a.large { font-size: 22px; }

.fontscale-control input[type=range] {
  flex: 1;
  max-width: 320px;
}

.fontscale-value {
  font-family: var(--font-mono, monospace);
  font-size: 0.8125rem;
  color: var(--copper);
  min-width: 3.2em;
  text-align: right;
}

.fontscale-sample {
  color: var(--text-body);
  border-left: 2px solid var(--copper-border);
  padding-left: var(--space-3);
  margin-top: var(--space-2);
}

/* --- Calendar week view ------------------------------------------------- */

.cal-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0 var(--space-5);
  min-height: 0;
}

.cal-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 500px);
  gap: var(--space-5);
  padding: var(--space-5) 0;
  min-height: 0;
}

.cal-main,
.cal-chat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-4) var(--space-5) var(--space-3);
}

.cal-head h1 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.cal-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.cal-week-label {
  font-size: 0.875rem;
  color: var(--text-body);
  margin: 0 var(--space-2);
  white-space: nowrap;
}

.cal-connect-banner {
  margin: 0 var(--space-5) var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--copper-muted);
  border: 1px solid var(--copper-border);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  color: var(--text-body);
}

/* -- day header row -- */

.cal-headrow {
  display: grid;
  border-bottom: 1px solid var(--border);
  padding-right: var(--space-2);
}

.cal-headcell {
  display: flex;
  align-items: baseline;
  gap: 6px;
  justify-content: center;
  padding: var(--space-2) 0;
  border-left: 1px solid var(--border);
}

.cal-headname {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cal-headnum {
  font-size: 0.9375rem;
  color: var(--text-body);
  font-weight: 600;
}

.cal-headcell.today .cal-headnum {
  background: var(--copper);
  color: var(--text-inverse);
  border-radius: var(--radius-full);
  padding: 1px 8px;
}

.cal-headcell.today .cal-headname { color: var(--copper); }

/* -- all-day row -- */

.cal-allday {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.cal-allday[hidden] { display: none; }

.cal-allday-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-body);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 2px 10px;
}

.cal-allday-day {
  color: var(--copper);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.6875rem;
}

/* -- the grid -- */

.cal-grid-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.cal-grid-scroll .cal-headrow {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 5;
}

.cal-grid {
  display: grid;
  position: relative;
}

.cal-gutter { position: relative; }

.cal-hourlabel {
  position: absolute;
  right: 8px;
  transform: translateY(-50%);
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.cal-daycol {
  position: relative;
  border-left: 1px solid var(--border);
  background-image: linear-gradient(to bottom, var(--border) 1px, transparent 1px);
}

.cal-daycol.today { background-color: rgba(199, 140, 92, 0.04); }

.cal-event {
  position: absolute;
  overflow: hidden;
  background: var(--surface-accent);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--copper);
  border-radius: var(--radius-sm);
  padding: 3px 7px;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-default),
              background var(--duration-fast) var(--ease-default);
  z-index: 2;
}

.cal-event:hover {
  background: var(--surface-raised);
  border-color: var(--copper);
  z-index: 3;
}

.cal-event-time {
  display: block;
  font-size: 0.6875rem;
  color: var(--text-muted);
  line-height: 1.3;
  white-space: nowrap;
}

.cal-event-title {
  display: block;
  font-size: 0.75rem;
  color: var(--text-primary);
  font-weight: 500;
  line-height: 1.3;
  overflow: hidden;
}

.cal-event.short { padding: 1px 7px; }
.cal-event.short .cal-event-title { white-space: nowrap; text-overflow: ellipsis; }

.cal-event.conflict { border-left-color: var(--status-amber); }
.cal-event.past { opacity: 0.55; }

.cal-nowline {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--status-red);
  z-index: 4;
  pointer-events: none;
}

.cal-nowline::before {
  content: '';
  position: absolute;
  left: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--status-red);
}

/* Event detail popover */
.ev-detail {
  position: absolute;
  z-index: 50;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  min-width: 200px;
  max-width: 280px;
  box-shadow: var(--shadow-overlay);
  animation: rise-in 180ms var(--ease-default);
}
.ev-detail-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}
.ev-detail-row {
  font-size: 0.8125rem;
  color: var(--text-body);
  margin-bottom: var(--space-1);
}
.ev-detail-actions {
  margin-top: var(--space-3);
  display: flex;
  gap: var(--space-2);
}
.ev-detail-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--copper);
  font-size: 0.8125rem;
  text-decoration: none;
}
.ev-detail-link:hover {
  text-decoration: underline;
}
.ev-detail-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
  max-height: 3.6em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.cal-empty-note {
  text-align: center;
  padding: var(--space-3);
  border-top: 1px solid var(--border);
}

.cal-empty-note[hidden] { display: none; }

/* -- day picker (shown by JS whenever fewer than 7 days fit) -- */

.cal-daypicker {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.cal-daypicker[hidden] { display: none; }

.cal-daychip {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 6px 0;
  cursor: pointer;
}

.cal-daychip-name {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.cal-daychip-num {
  font-size: 0.9375rem;
  color: var(--text-body);
  font-weight: 600;
}

.cal-daychip.active {
  background: var(--copper-muted);
  border-color: var(--copper-border);
}

.cal-daychip.active .cal-daychip-num { color: var(--copper); }
.cal-daychip.today .cal-daychip-name { color: var(--copper); }

/* -- chat pane -- */

.cal-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-body);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cal-sheet-close { display: none; font-size: 1rem; line-height: 1; }

.cal-chat-messages { padding: var(--space-4); }

.cal-chat-empty { margin-top: 6vh; }
.cal-chat-empty p { font-size: 0.8125rem; line-height: 1.7; }

.cal-chat .chat-input { margin: 0 var(--space-4) var(--space-4); }

/* -- ask pill + bottom sheet (mobile) -- */

.cal-ask-pill { display: none; }
.cal-sheet-backdrop { display: none; }

/* Squashed: chat drops below the calendar and the page scrolls normally. */
@media (max-width: 1100px) {
  .cal-page { overflow-y: auto; }

  .cal-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: auto;
  }

  .cal-main { height: 72dvh; min-height: 440px; }
  .cal-chat { height: 62dvh; min-height: 380px; }
}

/* Skinny: chat becomes the ask-pill bottom sheet. */
@media (max-width: 640px) {
  .cal-page { padding: 0 var(--space-3); }

  .cal-layout {
    padding: var(--space-3) 0 calc(var(--space-10) + var(--space-6));
  }

  .cal-main {
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  .cal-grid-scroll {
    flex: none;
    overflow: visible;
  }

  .cal-chat {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    height: 78dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-overlay);
    transform: translateY(105%);
    transition: transform 280ms var(--ease-default);
    z-index: 60;
  }

  .cal-chat.open { transform: translateY(0); }

  .cal-sheet-close { display: inline-flex; }

  .cal-ask-pill {
    display: block;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    background: var(--copper);
    color: #1A1A1A;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-full);
    padding: 12px 22px;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    z-index: 50;
  }

  .cal-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 55;
  }

  .cal-sheet-backdrop[hidden] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .cal-chat { transition: none; }
}

/* --- Today bar (horizontal day strip, shared by Mission Control + /calendar) */

.daybar {
  display: block;
  color: inherit;
  margin: var(--space-2) 0 var(--space-1);
}

.daybar-track {
  position: relative;
  height: 38px;
  background: var(--bg-recessed);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.daybar-ev {
  position: absolute;
  top: 5px;
  bottom: 5px;
  min-width: 5px;
  background: var(--copper-strong);
  border: 1px solid var(--copper-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-default),
              background var(--duration-fast) var(--ease-default);
}

.daybar-ev:hover {
  background: var(--copper);
  transform: scaleY(1.15);
  z-index: 6;
}

.daybar-ev.past { opacity: 0.45; }
.daybar-ev.conflict { border-color: var(--status-amber); }
.daybar-ev.conflict.lane-0 { bottom: 52%; }
.daybar-ev.conflict.lane-1 { top: 52%; }

.daybar-now {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  background: var(--status-red);
  z-index: 5;
  pointer-events: none;
}

.daybar-now::before {
  content: '';
  position: absolute;
  top: -3px;
  left: -3px;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--status-red);
}

/* Hover popover with the event details. */
.daybar-tip {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-overlay);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 6px 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--ease-default);
  z-index: 30;
}

.daybar-tip strong {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-primary);
  font-weight: 600;
}

.daybar-tip span {
  font-size: 0.75rem;
  color: var(--text-body);
}

@media (hover: hover) {
  .daybar-ev:hover .daybar-tip { opacity: 1; }
}

/* Keep edge tooltips inside the panel. */
.daybar-ev:first-child .daybar-tip { left: 0; transform: none; }
.daybar-ev:nth-last-child(2) .daybar-tip { left: auto; right: 0; transform: none; }

.daybar-ticks {
  position: relative;
  height: 16px;
  margin-top: 5px;
}

.daybar-ticks span {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.daybar-ticks span:first-child { transform: none; }
.daybar-ticks span:last-child { transform: translateX(-100%); }

/* -- availability chips -- */

.free-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: var(--space-3) 0 var(--space-2);
}

.free-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.free-chip {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.75rem;
  color: var(--status-green);
  background: var(--status-green-bg);
  border: 1px solid var(--status-green-border);
  border-radius: var(--radius-sm);
  padding: 3px 10px;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default);
}

.free-chip:hover { background: rgba(92,138,92,0.22); }

/* -- today strip on /calendar -- */

.cal-today-strip {
  padding: var(--space-2) var(--space-5) var(--space-3);
  border-bottom: 1px solid var(--border);
}

.cal-today-strip .free-chips { margin-top: var(--space-2); }
.cal-today-strip .free-label { display: none; } /* chips speak for themselves here */

.cal-today-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* --- Search ------------------------------------------------------------ */

.search-bar {
  margin-bottom: var(--space-5);
}

.search-bar .input {
  width: 100%;
  font-size: 1rem;
}

.search-hit {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}

.search-type {
  flex-shrink: 0;
  font-size: 1.1rem;
  width: 1.6em;
  text-align: center;
}

.search-hit-body { flex: 1; min-width: 0; }

.search-path {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--copper);
  word-break: break-all;
}

.search-line {
  color: var(--text-muted);
  font-weight: 400;
}

.search-text {
  font-size: 0.875rem;
  color: var(--text-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.search-text mark {
  background: var(--copper-muted);
  border: 1px solid var(--copper-border);
  border-radius: 2px;
  color: var(--copper);
  padding: 0 2px;
}

/* --- Activity log ------------------------------------------------------ */

.activity-date {
  font-family: var(--font-serif);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: var(--space-3) 0 var(--space-1);
  margin-top: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.activity-date:first-child { margin-top: 0; }

.activity-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.activity-action {
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
}

.activity-detail {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-body);
}

.activity-time {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* --- Undo toast -------------------------------------------------------- */

.undo-toast {
  position: fixed;
  bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-5);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  color: var(--text-primary);
  z-index: 200;
  animation: rise-in 240ms var(--ease-default);
}

.undo-toast .btn { flex-shrink: 0; }

/* --- Standalone PWA safe areas ------------------------------------------ */
/* With viewport-fit=cover + a translucent status bar, content renders under
   the notch and home indicator when launched from the home screen. env()
   evaluates to 0 in a normal browser tab, so these are no-ops there. */

.topnav {
  padding-top: calc(var(--space-2) + env(safe-area-inset-top, 0px));
  padding-left: calc(var(--space-5) + env(safe-area-inset-left, 0px));
  padding-right: calc(var(--space-5) + env(safe-area-inset-right, 0px));
}

/* Composers and sheets must clear the home indicator. */
.chat-page .chat-input {
  margin-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 900px) {
  .mail-chat .chat-input,
  .cal-chat .chat-input {
    margin-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  }
}

/* --- Admin ------------------------------------------------------------ */

.impersonation-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-4);
  padding-top: calc(var(--space-2) + env(safe-area-inset-top, 0px));
  background: var(--status-amber-bg);
  border-bottom: 1px solid var(--status-amber-border);
  color: var(--status-amber);
  font-size: 0.875rem;
  flex-shrink: 0;
}
.impersonation-banner strong { color: var(--text-primary); }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.admin-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.admin-table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table a { color: var(--text-primary); text-decoration: none; }
.admin-table a:hover { color: var(--copper); }
.admin-actions { white-space: nowrap; }
.admin-actions .btn + .btn { margin-left: var(--space-2); }

.admin-kv { display: grid; gap: var(--space-2); }
.admin-kv > div { display: flex; gap: var(--space-3); align-items: baseline; flex-wrap: wrap; }
.admin-kv .muted { min-width: 130px; flex-shrink: 0; }

.admin-action-row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.admin-password-form {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
  flex-wrap: wrap;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}
.admin-password-form label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.admin-conn-row {
  display: flex;
  gap: var(--space-3);
  align-items: baseline;
  flex-wrap: wrap;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.admin-conn-row:last-child { border-bottom: none; }

/* ===================================================================== */
/* Mail composer: new email / reply with in-flow AI drafting             */
/* ===================================================================== */

.mail-compose-view {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.mail-compose-view[hidden] { display: none; }

.mail-compose-view .mail-read-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.mail-read-spacer { flex: 1; }
.mail-read-head { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

.compose-title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.compose-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: var(--space-4) var(--space-5) var(--space-5);
}

.compose-replying {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-size: 0.8125rem;
  color: var(--text-body);
  background: var(--bg-recessed);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  margin-bottom: var(--space-4);
  overflow: hidden;
}
.compose-replying[hidden] { display: none; }
.compose-replying-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  flex-shrink: 0;
}
.compose-replying-subject {
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compose-replying .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 1;
}

.compose-form { display: flex; flex-direction: column; gap: var(--space-3); }

.compose-field {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.compose-field > span {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 52px;
  flex-shrink: 0;
}
.compose-field input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 0;
  font-size: 0.875rem;
}
.compose-field input:focus { box-shadow: none; outline: none; }

/* -- the assistant strip: brief it, it drafts into the body below -- */
.compose-assist {
  background: var(--bg-recessed);
  border: 1px solid var(--copper-border, var(--border));
  border-radius: var(--radius-md);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.assist-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.assist-chips:empty { display: none; }

.assist-chip {
  font-size: 0.75rem;
  color: var(--text-body);
  background: var(--surface-raised, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 3px 12px;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default);
}
.assist-chip:hover { border-color: var(--copper); color: var(--copper); }

.assist-row { display: flex; gap: var(--space-2); }
.assist-row input {
  flex: 1;
  font-size: 0.875rem;
  padding: 8px 12px;
}
.assist-row input:disabled { opacity: 0.6; }

.assist-error,
.compose-error {
  padding: 8px 12px;
  border: 1px solid var(--status-red-border);
  border-radius: var(--radius-md);
  background: var(--status-red-bg);
  color: var(--status-red);
  font-size: 0.8125rem;
  font-weight: 500;
}
.assist-error[hidden],
.compose-error[hidden] { display: none; }

.compose-body {
  min-height: 240px;
  font-size: 0.875rem;
}

@keyframes assist-glow {
  0% { border-color: var(--copper); box-shadow: 0 0 0 3px var(--copper-border, rgba(199,140,92,0.25)); }
  100% { border-color: var(--border); box-shadow: none; }
}
.compose-body.assist-filled { animation: assist-glow 1.6s var(--ease-default) 1; }

.compose-extras {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  font-size: 0.8125rem;
  color: var(--text-body);
}
.compose-extras label {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  cursor: pointer;
}
.compose-extras label[hidden] { display: none; }

.compose-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-top: var(--space-2);
}

/* -- original message under the composer -- */

.compose-original {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.compose-original[hidden] { display: none; }

.compose-original-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}

.compose-original-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.compose-original-meta {
  font-size: 0.8125rem;
  color: var(--text-body);
  margin-bottom: var(--space-3);
}

.compose-original-body {
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.mail-sent-banner {
  margin: var(--space-3) var(--space-5) 0;
  padding: 8px 12px;
  border: 1px solid var(--status-green-border);
  border-radius: var(--radius-md);
  background: var(--status-green-bg);
  color: var(--status-green);
  font-size: 0.8125rem;
  font-weight: 500;
}
.mail-sent-banner[hidden] { display: none; }

/* -- settings: signature + writing-rules editors -- */
.signature-input,
.rules-input {
  font-family: var(--font-mono, monospace);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.signature-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: #1a1a1a;
  padding: var(--space-4);
  font-size: 0.875rem;
  overflow-x: auto;
}
.signature-preview a { color: #0b57d0; }

/* -- mail client round 2: search, actions, threads, autocomplete, atts -- */

.mail-search {
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--input);
  color: var(--text-primary);
  font-size: 0.75rem;
  padding: 3px 12px;
  width: 150px;
  transition: border-color var(--duration-fast) var(--ease-default),
              width var(--duration-fast) var(--ease-default);
}
.mail-search:focus { outline: none; border-color: var(--copper); width: 200px; }
.mail-search::placeholder { color: var(--text-muted); }

/* -- server-side search: snippets, term highlights, status badges -- */

.mail-row-snippet {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.mail-row-subject mark,
.mail-row-snippet mark {
  background: var(--copper-muted);
  color: var(--copper);
  border-radius: 2px;
  padding: 0 1px;
}

.mail-badge {
  display: inline-block;
  font-size: 0.625rem;
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0 6px;
  margin-left: var(--space-2);
  vertical-align: 1px;
}

/* -- labels: filter pill menu + reading-view chips -- */

.label-filter-wrap { position: relative; display: inline-flex; }

.mail-label-filter { white-space: nowrap; }

/* The filter menu is placed by JS (position:fixed, viewport-clamped) so it
   can never clip against the pane edge or run off a phone screen. */

.label-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  min-width: 200px;
  max-width: min(280px, calc(100vw - 24px));
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface-raised, var(--bg));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: var(--space-2) 0;
}
.label-menu[hidden] { display: none; }

.label-menu-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  width: 100%;
  padding: 7px 14px;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--text-primary);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
}
.label-menu-item:hover { background: var(--bg-recessed); }
.label-menu-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.label-menu-count { color: var(--text-muted); font-size: 0.75rem; }

.label-menu-empty {
  padding: 8px 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.mail-read-labels {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-2) 0;
}
.mail-read-labels:empty { display: none; }

.label-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--copper);
  background: var(--copper-muted);
  border: 1px solid var(--copper-border);
  border-radius: var(--radius-full);
  padding: 2px 8px;
}

.label-add-wrap { position: relative; display: inline-flex; }

.label-add-btn {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: none;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-full);
  padding: 2px 10px;
  cursor: pointer;
}
.label-add-btn:hover { color: var(--copper); border-color: var(--copper-border); }

/* -- snooze: deferred-attention picker -- */

.snooze-wrap { position: relative; display: inline-flex; }

.snooze-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 30;
  min-width: 240px;
  background: var(--surface-raised, var(--bg));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  overflow: hidden;
  padding: var(--space-2) 0;
}
.snooze-menu[hidden] { display: none; }

.snooze-option {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  width: 100%;
  padding: 8px 14px;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--text-primary);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
}
.snooze-option:hover { background: var(--bg-recessed); }
.snooze-option[hidden] { display: none; }
.snooze-option .snooze-when { color: var(--text-muted); font-size: 0.75rem; }
.snooze-option.snooze-clear { color: var(--copper); border-top: 1px solid var(--border); margin-top: var(--space-2); }

.snooze-pick {
  display: flex;
  gap: var(--space-2);
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  margin-top: var(--space-2);
  align-items: center;
}
.snooze-pick input[type="datetime-local"] {
  flex: 1;
  min-width: 0;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  background: var(--input);
  color: var(--text-primary);
  padding: 4px 6px;
}

#mail-snooze.snoozed { color: var(--copper); border-color: var(--copper-border); }

.mail-danger { color: var(--status-red); }
.mail-danger:hover { color: var(--status-red); border-color: var(--status-red-border); }

.mail-action-error { margin: var(--space-3) var(--space-4) 0; }
.mail-action-error[hidden] { display: none; }

/* thread strip: the rest of the conversation, one line per message */
.mail-thread { display: flex; flex-direction: column; gap: 2px; }
.mail-thread:not(:empty) { margin-bottom: var(--space-3); }

.thread-item {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: 0.75rem;
  color: var(--text-body);
  background: var(--bg-recessed);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 5px 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color var(--duration-fast) var(--ease-default);
}
.thread-item:hover { border-color: var(--copper-border, var(--copper)); }
.thread-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-when { color: var(--text-muted); flex-shrink: 0; }

/* recipient autocomplete */
.compose-field { position: relative; }
.compose-field[hidden] { display: none; }  /* display:flex would defeat [hidden] */

.recipient-menu {
  position: absolute;
  top: 100%;
  left: 52px;
  right: 0;
  z-index: 30;
  background: var(--surface-raised, var(--bg));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  overflow: hidden;
}
.recipient-menu[hidden] { display: none; }

.recipient-item {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: 8px 12px;
  font-size: 0.8125rem;
  cursor: pointer;
}
.recipient-item.active,
.recipient-item:hover { background: var(--bg-recessed); }
.recipient-name { color: var(--text-primary); font-weight: 500; }
.recipient-addr {
  color: var(--text-muted);
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* bcc reveal + from picker */
.compose-bcc-toggle {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 6px;
  flex-shrink: 0;
}
.compose-bcc-toggle:hover { color: var(--copper); }

#compose-from {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.875rem;
  padding: 8px 0;
}
#compose-from:focus { outline: none; }

/* composer attachments */
.compose-attachments {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.compose-att-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.compose-att-chips:empty { display: none; }
.compose-att .sel-chip-x { margin-left: 2px; }
.compose-att-add { cursor: pointer; }

/* -- settings: sidebar + panel layout ---------------------------------- */

.settings-layout {
  display: flex;
  gap: var(--space-6);
  min-height: 60vh;
}

.settings-sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: var(--space-1);
}

.settings-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-left: 3px solid transparent;
  background: none;
  color: var(--text-body);
  font-size: 0.9375rem;
  font-family: var(--font-sans);
  text-align: left;
  cursor: pointer;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  transition: color var(--duration-fast) var(--ease-default),
              background var(--duration-fast) var(--ease-default),
              border-color var(--duration-fast) var(--ease-default);
}
.settings-nav-item:hover {
  color: var(--copper);
  background: var(--bg-recessed);
}
.settings-nav-item.active {
  color: var(--copper);
  border-left-color: var(--copper);
  background: var(--bg-recessed);
  font-weight: 600;
}

.settings-nav-label { flex: 1; }
.settings-nav-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}
.settings-nav-chevron { display: none; }

.settings-main {
  flex: 1;
  min-width: 0;
}

.settings-back {
  display: none;
  border: none;
  background: none;
  color: var(--copper);
  font-size: 1rem;
  font-family: var(--font-sans);
  padding: 8px 0;
  margin-bottom: var(--space-3);
  cursor: pointer;
}

.settings-panel[hidden] { display: none; }
.settings-panel { animation: fadeIn var(--duration-default) var(--ease-default); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.settings-panel .card { margin-bottom: var(--space-4); }

/* -- settings: mobile drill-down --------------------------------------- */
@media (max-width: 767px) {
  .settings-layout {
    display: block;
  }
  .settings-sidebar {
    width: 100%;
    gap: 0;
  }
  .settings-nav-item {
    border-left: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 14px 4px;
  }
  .settings-nav-item.active {
    border-left: none;
    border-bottom-color: var(--border);
  }
  .settings-nav-chevron {
    display: block;
    color: var(--text-muted);
    font-size: 1.25rem;
    font-weight: 300;
  }
  .settings-nav-hint { display: inline; }

  .settings-main { display: none; }
  .settings-layout.drilled .settings-sidebar { display: none; }
  .settings-layout.drilled .settings-main { display: block; }
  .settings-back { display: block; }

  .page-head.settings-drilled { display: none; }
}

/* ── Security & account settings ─────────────────────────────────── */

.settings-block { margin-bottom: 2rem; }
.settings-block h2 { margin-bottom: 0.35rem; }

.stacked-form { display: flex; flex-direction: column; gap: 0.6rem; max-width: 24rem; margin-top: 0.6rem; }
.stacked-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.stacked-form .check-label { flex-direction: row; align-items: center; gap: 0.5rem; }
/* [hidden] pairing — flex would defeat the attribute otherwise. */
.stacked-form[hidden] { display: none !important; }
.settings-panel[data-section="security"] [hidden] { display: none !important; }

.danger-zone { border-top: 1px solid var(--border, rgba(128,128,128,0.3)); padding-top: 1.2rem; }

.session-row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; padding: 0.55rem 0; border-bottom: 1px solid var(--border, rgba(128,128,128,0.2)); }
.session-row:last-child { border-bottom: 0; }

.backup-codes { font-family: var(--font-mono, monospace); background: var(--bg-inset, rgba(128,128,128,0.1)); padding: 0.8rem 1rem; border-radius: 8px; line-height: 1.7; user-select: all; max-width: 24rem; }

.qr-box { margin: 0.6rem 0; background: #fff; padding: 12px; border-radius: 8px; width: fit-content; }
.qr-box img, .qr-box canvas { display: block; }

.verify-nag .flash { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.verify-nag .inline-form { display: inline-flex; margin: 0; }
