/* =====================================================================
   Woobul — Modern Card Shop
   Warm cream + coral + teal + sun yellow. Soft cards, rounded edges,
   generous spacing, bento-style stat tiles. Modern, fun, confident.

   Type:
     - Instrument Serif (display, italic ligatures)
     - Geist (UI/body, modern grotesque)
     - Geist Mono (data, tabular)
   ===================================================================== */

:root {
  /* CANVAS */
  --cream:        #fef9ed;
  --cream-deep:   #fbeed5;
  --ivory:        #ffffff;
  --peach:        #fcdcc1;

  /* INK */
  --ink:          #0a1f24;
  --ink-soft:     #243a40;
  --ink-muted:    #5d7a82;
  --ink-hint:     #92acb3;

  /* ACCENTS */
  --coral:        #ff5a3c;
  --coral-deep:   #e0421f;
  --coral-soft:   #ffe4dc;
  --teal:         #0a3535;
  --teal-soft:    #d6e8e7;
  --sun:          #ffc845;
  --sun-soft:     #fff1c4;

  /* SEMANTIC */
  --gain:         #1a8754;
  --gain-soft:    #d4f1de;
  --loss:         #dc3545;
  --loss-soft:    #fde2e4;

  /* RULES */
  --rule:         #e8dec2;     /* default soft border */
  --rule-strong:  #d4c69e;
  --divider:      #f0e6cf;     /* near-invisible cell divider */

  /* SHADOWS */
  --shadow-xs:    0 1px 2px rgba(10, 31, 36, 0.04);
  --shadow-sm:    0 2px 6px rgba(10, 31, 36, 0.06), 0 1px 2px rgba(10, 31, 36, 0.04);
  --shadow-md:    0 6px 18px -4px rgba(10, 31, 36, 0.10), 0 2px 6px rgba(10, 31, 36, 0.06);
  --shadow-lg:    0 16px 40px -8px rgba(10, 31, 36, 0.18), 0 4px 12px rgba(10, 31, 36, 0.08);
  --shadow-coral: 0 8px 24px -6px rgba(255, 90, 60, 0.4);

  /* RADII */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-full: 999px;

  /* TYPE */
  --font-display: "Instrument Serif", "Times New Roman", Georgia, serif;
  --font-sans:    "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  --font-mono:    "Geist Mono", "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* =====================================================================
   Base
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  padding: 0 1.5rem calc(5rem + var(--safe-bottom));
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--cream);
  /* Subtle dot-pattern wash for warmth */
  background-image:
    radial-gradient(circle at 12% 8%, rgba(255, 90, 60, 0.06), transparent 38%),
    radial-gradient(circle at 92% 100%, rgba(255, 200, 69, 0.10), transparent 42%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main, header.topbar, footer.colophon { max-width: 1200px; margin: 0 auto; }
main { padding: 1rem 0 2rem; }

/* =====================================================================
   Top bar
   Modern app header. Brand left, nav center, hamburger right (mobile).
   ===================================================================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0 0.75rem;
  margin-bottom: 1.25rem;
  position: relative;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  border-bottom: none;
  padding-bottom: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.7rem;
  letter-spacing: -0.01em;
  line-height: 1;
}
/* Three small coral dots stacked vertically — binder rings */
.brand-mark {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  padding: 2px 0;
}
.brand-mark .ring {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--coral);
  display: block;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease;
}
.brand:hover .brand-mark .ring:nth-child(1) { transform: translateX(-2px); background: var(--coral-deep); }
.brand:hover .brand-mark .ring:nth-child(2) { transform: translateX(2px); background: var(--coral); }
.brand:hover .brand-mark .ring:nth-child(3) { transform: translateX(-2px); background: var(--coral-deep); }
.brand-word { font-style: italic; }

.primary-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem;
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-xs);
}
.primary-nav a {
  text-decoration: none;
  color: var(--ink-muted);
  font-weight: 500;
  font-size: 0.88rem;
  padding: 0.35rem 0.9rem;
  border-radius: var(--r-full);
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.primary-nav a:hover {
  color: var(--ink);
  background: var(--cream-deep);
}
.primary-nav a.active {
  background: var(--ink);
  color: var(--cream);
}

/* Hamburger */
.nav-toggle {
  display: none;
  width: 42px; height: 42px;
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  cursor: pointer;
  padding: 0;
  position: relative;
  box-shadow: var(--shadow-xs);
  transition: background 0.15s ease;
}
.nav-toggle:hover { background: var(--cream-deep); }
.nav-toggle .bars,
.nav-toggle .bars::before,
.nav-toggle .bars::after {
  display: block; position: absolute;
  left: 50%; transform: translateX(-50%);
  width: 18px; height: 2px;
  background: var(--ink);
  border-radius: 2px;
  transition: transform 0.2s ease;
}
.nav-toggle .bars { top: 50%; transform: translate(-50%, -50%); }
.nav-toggle .bars::before { content: ""; top: -6px; }
.nav-toggle .bars::after  { content: ""; top:  6px; }
.nav-toggle[aria-expanded="true"] .bars { background: transparent; }
.nav-toggle[aria-expanded="true"] .bars::before { transform: translateX(-50%) translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] .bars::after  { transform: translateX(-50%) translateY(-6px) rotate(-45deg); }

/* =====================================================================
   Headings
   ===================================================================== */

h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2rem, 4.5vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0.25rem 0 0.4rem;
  color: var(--ink);
}
h1 em {
  font-style: italic;
  color: var(--coral);
}

h2 {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: -0.005em;
  margin: 2rem 0 0.85rem;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
}
h2 .hint {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--ink-muted);
  letter-spacing: 0;
}

p { margin: 0 0 1rem; }
p.muted, .muted { color: var(--ink-muted); font-size: 0.92rem; }
.hint { color: var(--ink-hint); }

a {
  color: var(--coral);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: 1px;
  transition: color 0.15s ease;
}
a:hover { color: var(--coral-deep); }

strong { font-weight: 600; }
em { font-style: italic; }

/* =====================================================================
   Stat tiles — bento card grid
   ===================================================================== */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.75rem;
}
.stat {
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 1.1rem 1.2rem 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}
.stat::before {
  /* Top-left mini shape so cards have a hint of personality */
  content: "";
  position: absolute;
  top: -20px; left: -20px;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--cream-deep);
  opacity: 0.6;
  z-index: 0;
}
.stat > * { position: relative; z-index: 1; }
.stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.stat .label {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  background: var(--cream-deep);
  padding: 0.2rem 0.55rem;
  border-radius: var(--r-full);
  margin-bottom: 0.85rem;
}
.stat .value {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.9rem, 3.2vw, 2.5rem);
  line-height: 1.05;
  letter-spacing: -0.025em;
  color: var(--ink);
  font-feature-settings: "tnum", "lnum";
}
.stat .sub {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink-hint);
  margin-top: 0.5rem;
  letter-spacing: 0.02em;
}
.stat.gain { background: linear-gradient(135deg, var(--ivory), var(--gain-soft) 220%); }
.stat.gain::before { background: var(--gain-soft); }
.stat.gain .value { color: var(--gain); }
.stat.loss { background: linear-gradient(135deg, var(--ivory), var(--loss-soft) 220%); }
.stat.loss::before { background: var(--loss-soft); }
.stat.loss .value { color: var(--loss); }

.gain-text { color: var(--gain); font-weight: 600; }
.loss-text { color: var(--loss); font-weight: 600; }

/* =====================================================================
   Tables
   ===================================================================== */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: var(--ivory);
  box-shadow: var(--shadow-xs);
}
.table-wrap > table { min-width: 100%; }

table {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 0.9rem;
}
thead tr { background: var(--cream-deep); }
th {
  text-align: left;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--rule);
}
tbody tr {
  border-bottom: 1px solid var(--divider);
  transition: background 0.12s ease;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--cream); }
td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
}
td.num, th.num {
  text-align: right;
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.compact td, .compact th { padding: 0.55rem 0.85rem; font-size: 0.85rem; }

table.inventory .card-name {
  font-weight: 500;
  color: var(--ink);
}
table.inventory .card-meta {
  font-size: 0.74rem;
  color: var(--ink-hint);
  margin-top: 0.15rem;
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
}

/* Sortable headers */
th.sortable a {
  color: inherit;
  border-bottom: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  padding: 0;
}
th.sortable a:hover { color: var(--coral); }
.sort-arrow { font-family: var(--font-display); font-size: 0.85rem; color: var(--coral); }

.refund {
  font-family: var(--font-mono);
  color: var(--loss);
  font-weight: 500;
}

/* =====================================================================
   Forms / filters
   ===================================================================== */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  padding: 0.85rem;
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}

.filters input[type="search"],
.filters input[type="date"],
.filters input[type="text"],
.filters select {
  font-family: var(--font-sans);
  font-size: 0.92rem;
  padding: 0.55rem 0.85rem;
  background: var(--cream);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  color: var(--ink);
  min-height: 40px;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.filters input[type="search"] { flex: 1; min-width: 220px; }
.filters select { min-width: 140px; cursor: pointer; }

.filters input:focus, .filters select:focus {
  outline: none;
  border-color: var(--coral);
  background: var(--ivory);
  box-shadow: 0 0 0 3px var(--coral-soft);
}

/* Buttons — pill-shaped, friendly */
.filters button[type="submit"],
.btn-primary {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.6rem 1.3rem;
  background: var(--coral);
  color: var(--ivory);
  border: 1px solid var(--coral);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.2s ease;
  min-height: 40px;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-xs);
}
.filters button[type="submit"]:hover,
.btn-primary:hover {
  background: var(--coral-deep);
  border-color: var(--coral-deep);
  box-shadow: var(--shadow-coral);
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: progress; box-shadow: none; }

.filters .btn-clear, .btn-clear {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 0.88rem;
  padding: 0.6rem 1rem;
  background: var(--ivory);
  color: var(--ink-muted);
  border: 1px solid var(--rule);
  border-radius: var(--r-full);
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.filters .btn-clear:hover, .btn-clear:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--cream);
}

.meta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-bottom: 0.6rem;
  letter-spacing: 0.02em;
}
.meta strong { color: var(--ink); font-weight: 600; }

/* =====================================================================
   Empty states
   ===================================================================== */

.empty, .empty-mini {
  text-align: center;
  background: var(--ivory);
  border: 1px dashed var(--rule-strong);
  border-radius: var(--r-lg);
  color: var(--ink-muted);
}
.empty {
  padding: 3rem 1.5rem;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.1rem;
}
.empty::before {
  content: "✦";
  display: block;
  font-size: 1.8rem;
  color: var(--coral);
  margin-bottom: 0.6rem;
  font-style: normal;
  animation: gentle-bounce 3s ease-in-out infinite;
}
@keyframes gentle-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.empty-mini {
  padding: 1.5rem 1rem;
  font-size: 0.92rem;
  font-style: italic;
  font-family: var(--font-display);
}

/* =====================================================================
   Pagination
   ===================================================================== */

.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 0.6rem;
  margin: 1.5rem 0;
  font-family: var(--font-sans);
  font-size: 0.88rem;
}
.pagination a, .pagination .disabled {
  padding: 0.5rem 1rem;
  background: var(--ivory);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: var(--r-full);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  min-height: 40px;
  display: inline-flex; align-items: center;
  box-shadow: var(--shadow-xs);
}
.pagination a:hover {
  background: var(--coral); color: var(--ivory); border-color: var(--coral);
}
.pagination .disabled {
  color: var(--ink-hint); background: var(--cream); cursor: default; box-shadow: none;
}
.pagination .page-num {
  font-family: var(--font-mono);
  color: var(--ink-muted);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

/* =====================================================================
   Dashboard
   ===================================================================== */

.dashboard-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
}
.dashboard-header h1 { margin: 0; }
.dashboard-header p { margin: 0.4rem 0 0; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 1.5rem 0;
}

dl.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1.5rem;
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 1.1rem 1.3rem;
  margin: 0;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  box-shadow: var(--shadow-xs);
}
dl.kv dt {
  color: var(--ink-muted);
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
dl.kv dd { margin: 0; color: var(--ink); }

/* =====================================================================
   Reprice modal
   ===================================================================== */

#reprice-dialog {
  border: 1px solid var(--rule);
  border-radius: var(--r-xl);
  padding: 0;
  width: min(680px, 92vw);
  max-height: 80vh;
  background: var(--ivory);
  color: var(--ink);
  font-family: var(--font-sans);
  box-shadow: var(--shadow-lg);
}
#reprice-dialog::backdrop {
  background: rgba(10, 31, 36, 0.45);
  backdrop-filter: blur(4px);
}
.dlg-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, var(--cream-deep) 0%, var(--ivory) 100%);
}
.dlg-header strong {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.2rem;
  color: var(--ink);
}
.dlg-header button {
  background: var(--ivory); border: 1px solid var(--rule);
  border-radius: var(--r-full);
  cursor: pointer;
  width: 32px; height: 32px;
  font-size: 1.2rem; line-height: 1;
  color: var(--ink-muted);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.dlg-header button:hover { color: var(--coral); background: var(--coral-soft); border-color: var(--coral-soft); }

.reprice-status { padding: 1.1rem 1.3rem; }
.reprice-status p { margin: 0.4rem 0; }
.progress-bar {
  height: 8px; margin-top: 0.7rem;
  background: var(--cream-deep);
  border-radius: var(--r-full);
  overflow: hidden;
  position: relative;
}
.progress-bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--coral) 0%, var(--sun) 100%);
  border-radius: var(--r-full);
  transition: width 0.3s ease;
}
.reprice-log {
  margin: 0; padding: 0 1.3rem 1.3rem;
  list-style: none;
  max-height: 40vh; overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.reprice-log li {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--divider);
  color: var(--ink-muted);
}
.reprice-log li.ok { color: var(--ink); }
.reprice-log li.ok strong { color: var(--gain); }
.reprice-log li:last-child { border-bottom: none; }
.reprice-log em { color: var(--ink-hint); font-style: italic; }

/* =====================================================================
   Footer / colophon
   ===================================================================== */

.colophon {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-hint);
  letter-spacing: 0.04em;
}
.colophon .dot { color: var(--coral); }

/* =====================================================================
   Banner / warning
   ===================================================================== */

.banner-warning {
  background: var(--sun-soft);
  border: 1px solid var(--sun);
  border-left-width: 4px;
  border-radius: var(--r-md);
  padding: 0.75rem 1rem;
  font-size: 0.92rem;
  color: var(--ink);
  margin: 1rem 0;
  font-family: var(--font-sans);
}
.banner-warning.compact {
  margin: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.82rem;
}
.banner-warning strong { color: var(--ink); font-weight: 600; }

/* =====================================================================
   Chat
   ===================================================================== */

.chat-fab {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-bottom));
  right: 1.5rem;
  background: var(--coral);
  color: var(--ivory);
  border: 1px solid var(--coral);
  border-radius: var(--r-full);
  padding: 0.85rem 1.4rem;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  display: flex; align-items: center; gap: 0.55rem;
  box-shadow: var(--shadow-md), 0 0 0 0 rgba(255, 90, 60, 0.5);
  transition: transform 0.2s ease, box-shadow 0.3s ease, background 0.15s ease;
  z-index: 100;
}
.chat-fab:hover {
  background: var(--coral-deep);
  border-color: var(--coral-deep);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg), var(--shadow-coral);
}
.chat-fab:active { transform: translateY(0); }
.fab-icon {
  font-size: 1rem;
  line-height: 1;
  display: inline-block;
  animation: spin-slow 12s linear infinite;
}
@keyframes spin-slow { to { transform: rotate(360deg); } }
.chat-fab-label { white-space: nowrap; letter-spacing: 0.01em; }

.chat-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 31, 36, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 200;
}
.chat-backdrop.open { opacity: 1; pointer-events: auto; }

.chat-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(460px, 94vw);
  background: var(--cream);
  border-left: 1px solid var(--rule);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0.16, 1);
  z-index: 300;
  display: flex; flex-direction: column;
}
.chat-drawer.open { transform: translateX(0); }
#chat-drawer-content { display: flex; flex-direction: column; height: 100%; }
.chat-drawer-loading {
  padding: 2rem; text-align: center;
  font-family: var(--font-display);
  font-style: italic;
  color: var(--ink-muted);
}

.chat-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--rule);
  background: var(--ivory);
}
.chat-drawer-header strong {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.3rem;
  font-style: italic;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.chat-thread-meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-muted);
  margin-left: 0.5rem;
  letter-spacing: 0.02em;
}
.chat-drawer-actions { display: flex; gap: 0.4rem; align-items: center; }
.btn-link {
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--coral);
  padding: 0.35rem 0.65rem;
  border-radius: var(--r-full);
  transition: background 0.15s ease;
}
.btn-link:hover {
  background: var(--coral-soft);
}
#chat-close {
  width: 32px; height: 32px; padding: 0;
  font-size: 1.3rem; line-height: 1;
  color: var(--ink-muted);
  border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
}
#chat-close:hover { background: var(--cream-deep); color: var(--ink); }

.chat-messages {
  display: flex; flex-direction: column; gap: 0.65rem;
  margin: 0; padding: 1rem;
  flex: 1; overflow-y: auto;
  background: var(--cream);
  min-height: 0;
}
.chat-messages.drawer-mode { padding: 0.85rem; }

.msg {
  font-family: var(--font-sans);
  font-size: 0.92rem;
  line-height: 1.5;
  padding: 0.75rem 0.95rem;
  border-radius: var(--r-md);
}
.msg-role {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.25rem;
}
.msg-text { white-space: pre-wrap; color: var(--ink); }

.msg-user {
  background: var(--ink);
  color: var(--cream);
  border-radius: var(--r-md) var(--r-md) 4px var(--r-md);
  align-self: flex-end;
  max-width: 88%;
}
.msg-user .msg-role { color: rgba(254, 249, 237, 0.7); }
.msg-user .msg-text { color: var(--cream); }

.msg-assistant {
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: var(--r-md) var(--r-md) var(--r-md) 4px;
  align-self: flex-start;
  max-width: 88%;
  box-shadow: var(--shadow-xs);
}
.msg-assistant.streaming .msg-text::after {
  content: "▍";
  margin-left: 2px;
  color: var(--coral);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* "Agent is thinking" placeholder bubble — same shape as msg-assistant
 * so the eventual answer feels like it lands in the same spot. */
.msg-thinking {
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: var(--r-md) var(--r-md) var(--r-md) 4px;
  align-self: flex-start;
  max-width: 88%;
  box-shadow: var(--shadow-xs);
}
.thinking-dots {
  display: inline-flex;
  gap: 5px;
  padding: 2px 0 4px;
}
.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-muted);
  animation: thinking-pulse 1.2s infinite ease-in-out;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes thinking-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

.msg-tool-use, .msg-tool-result {
  align-self: flex-start;
  max-width: 88%;
  background: var(--cream-deep);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  font-size: 0.8rem;
  font-family: var(--font-mono);
}
.msg-tool-use summary,
.msg-tool-result summary {
  cursor: pointer;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
  padding: 0.35rem 0.55rem;
}
.msg-tool-use summary code { color: var(--ink); font-weight: 500; }
.msg-tool-error { background: var(--loss-soft); border-color: var(--loss); }
.msg-tool-error summary { color: var(--loss); }

.msg pre {
  margin: 0.4rem 0.55rem 0.55rem;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-soft);
  background: var(--ivory);
  padding: 0.5rem 0.7rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--rule);
}

.msg-system {
  align-self: stretch;
  background: transparent;
  color: var(--ink-hint);
  font-size: 0.82rem;
  font-style: italic;
  font-family: var(--font-display);
  text-align: center;
  padding: 0.4rem;
}

/* Approval gate */
.msg-pending {
  background: linear-gradient(135deg, var(--ivory) 0%, var(--sun-soft) 200%);
  border: 1px solid var(--sun);
  border-left: 4px solid var(--coral);
  border-radius: var(--r-md);
  padding: 0.95rem 1.1rem;
  align-self: stretch;
  max-width: 100%;
  position: relative;
  box-shadow: var(--shadow-sm);
}
.msg-pending::before {
  content: "✦";
  position: absolute;
  top: 0.85rem;
  right: 1rem;
  font-size: 1.1rem;
  color: var(--coral);
  animation: gentle-spin 6s ease-in-out infinite;
}
@keyframes gentle-spin {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(72deg); }
}
.msg-pending .msg-role {
  color: var(--coral-deep);
  font-weight: 600;
  margin-bottom: 0.55rem;
}
.pending-tools {
  list-style: none; padding: 0; margin: 0 0 0.85rem;
  display: flex; flex-direction: column; gap: 0.45rem;
}
.pending-tools li {
  background: var(--ivory);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 0.55rem 0.75rem;
  font-size: 0.86rem;
}
.pending-tools li > strong {
  font-family: var(--font-mono);
  color: var(--ink);
  font-weight: 600;
}
.pending-tools li details { margin-top: 0.4rem; }
.pending-tools li summary {
  cursor: pointer; color: var(--ink-muted); font-size: 0.74rem;
  font-family: var(--font-mono);
}
.pending-tools li pre {
  margin: 0.4rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  background: var(--cream);
  padding: 0.5rem 0.6rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  white-space: pre-wrap;
}
.badge-write {
  display: inline-block;
  background: var(--coral);
  color: var(--ivory);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  padding: 0.12rem 0.5rem;
  border-radius: var(--r-full);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-left: 0.5rem;
  font-weight: 500;
  vertical-align: middle;
}
.pending-actions {
  display: flex; gap: 0.55rem;
}
.pending-actions button {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.86rem;
  padding: 0.55rem 1.2rem;
  border-radius: var(--r-full);
  cursor: pointer;
  border: 1px solid;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.2s ease;
}
.pending-actions button[data-action=approve],
.pending-actions button[data-action=approve-server] {
  background: var(--gain);
  color: var(--ivory);
  border-color: var(--gain);
}
.pending-actions button[data-action=approve]:hover,
.pending-actions button[data-action=approve-server]:hover {
  background: #166e44; border-color: #166e44;
  box-shadow: 0 4px 12px -4px rgba(26, 135, 84, 0.4);
  transform: translateY(-1px);
}
.pending-actions button[data-action=approve-all] {
  background: var(--ivory);
  color: var(--gain);
  border-color: var(--gain);
}
.pending-actions button[data-action=approve-all]:hover {
  background: var(--gain-soft, rgba(26, 135, 84, 0.08));
  box-shadow: 0 2px 8px -3px rgba(26, 135, 84, 0.25);
  transform: translateY(-1px);
}
.pending-actions button[data-action=reject],
.pending-actions button[data-action=reject-server] {
  background: var(--ivory);
  color: var(--loss);
  border-color: var(--loss);
}
.pending-actions button[data-action=reject]:hover,
.pending-actions button[data-action=reject-server]:hover {
  background: var(--loss-soft);
}
.pending-actions button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.pending-decision {
  margin-top: 0.55rem;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}
.pending-decision.approved { color: var(--gain); }
.pending-decision.rejected { color: var(--loss); }
.msg-pending.pending-decided { opacity: 0.78; }

/* Chat form */
.chat-drawer #chat-form {
  padding: 0.85rem;
  background: var(--ivory);
  border-top: 1px solid var(--rule);
}
#chat-form textarea {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 0.65rem 0.85rem;
  background: var(--cream);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  color: var(--ink);
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#chat-form textarea:focus {
  outline: none;
  border-color: var(--coral);
  box-shadow: 0 0 0 3px var(--coral-soft);
  background: var(--ivory);
}
.chat-form-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 0.5rem;
}
.chat-hint {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-hint);
  letter-spacing: 0.02em;
}
#chat-form button[type=submit] {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.55rem 1.4rem;
  background: var(--coral);
  color: var(--ivory);
  border: 1px solid var(--coral);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.2s ease;
  min-height: 38px;
}
#chat-form button[type=submit]:hover {
  background: var(--coral-deep); border-color: var(--coral-deep);
  box-shadow: var(--shadow-coral);
}
#chat-form button[type=submit]:disabled { opacity: 0.55; cursor: progress; }

.chat-drawer-footer {
  display: flex; align-items: center; justify-content: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem calc(0.55rem + var(--safe-bottom));
  background: var(--cream-deep);
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  cursor: help;
}
.chat-drawer-footer .dot {
  width: 7px; height: 7px;
  background: var(--gain);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 3px var(--gain-soft);
}
.chat-drawer-footer strong {
  color: var(--ink);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* =====================================================================
   Sections / focus
   ===================================================================== */

section { margin-bottom: 2.25rem; }

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

button { transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.2s ease; }

/* =====================================================================
   Responsive
   ===================================================================== */

@media (max-width: 900px) {
  body { padding: 0 1rem calc(5rem + var(--safe-bottom)); }
  .grid { grid-template-columns: 1fr; gap: 1.25rem; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

@media (max-width: 720px) {
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }

  .topbar { padding: 0.85rem 0 0.6rem; }
  .brand { font-size: 1.4rem; }

  .primary-nav {
    position: absolute;
    top: 100%; left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.2rem;
    padding: 0.5rem;
    background: var(--ivory);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
    transform: translateY(-12px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.18s ease, opacity 0.18s ease;
    z-index: 50;
  }
  .primary-nav.open {
    transform: translateY(8px);
    opacity: 1;
    pointer-events: auto;
  }
  .primary-nav a {
    padding: 0.85rem 1rem;
    border-radius: var(--r-md);
    font-size: 0.95rem;
    min-height: 44px;
    display: flex; align-items: center;
  }

  /* Stats: 2-up */
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat .value { font-size: 1.55rem; }

  /* Filters stack */
  .filters {
    flex-direction: column;
    align-items: stretch;
  }
  .filters input[type="search"],
  .filters input[type="date"],
  .filters input[type="text"],
  .filters select,
  .filters button[type="submit"],
  .filters .btn-clear {
    width: 100%;
    font-size: 16px;
    min-height: 44px;
  }

  .pagination { flex-wrap: wrap; }
  .pagination a, .pagination .disabled { min-height: 44px; }

  /* Tighter tables */
  th, td { padding: 0.55rem 0.65rem; font-size: 0.85rem; }
  .compact td, .compact th { padding: 0.45rem 0.55rem; font-size: 0.8rem; }

  /* Dashboard header stacks */
  .dashboard-header {
    flex-direction: column;
    align-items: stretch;
  }

  /* Chat full screen */
  .chat-drawer { width: 100vw; }
  .chat-fab-label { display: none; }
  .chat-fab { padding: 0.95rem 1.05rem; }
  .fab-icon { font-size: 1.4rem; }

  #reprice-dialog {
    width: 100vw; max-width: none;
    max-height: 100vh;
    border-radius: 0;
  }
  .reprice-log { max-height: 50vh; }

  h1 { font-size: 1.75rem; }
  h2 { font-size: 1rem; margin-top: 1.5rem; }
}

@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr; }
  body { padding: 0 0.85rem calc(5rem + var(--safe-bottom)); }
  .brand { font-size: 1.25rem; }
}

/* Print */
@media print {
  body { background: white; padding: 0; }
  .chat-fab, .chat-drawer, .chat-backdrop, .nav-toggle, #reprice-dialog, .colophon { display: none !important; }
}

/* =====================================================================
   Auth pages — sign-in, sign-up, onboarding
   ===================================================================== */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.auth-shell {
  width: min(100%, 460px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.auth-brand {
  font-size: 1.5rem;
  text-decoration: none;
}

.auth-card {
  width: 100%;
  display: flex;
  justify-content: center;
}

.auth-tagline {
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  color: var(--ink-muted);
  font-size: 1.05rem;
  text-align: center;
}

.auth-error {
  background: var(--loss-soft);
  color: var(--loss);
  padding: 1rem 1.25rem;
  border-radius: var(--r-md);
  font-size: 0.95rem;
}

.onboarding-header {
  text-align: center;
  margin-bottom: 1.5rem;
}
.onboarding-header h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  margin: 0 0 0.5rem 0;
  font-weight: 400;
}
.onboarding-header p {
  color: var(--ink-muted);
  margin: 0;
}

/* Slot for Clerk's UserButton in the topbar.
 * Reserve a fixed footprint so the topbar layout (which uses
 * space-between) doesn't shift the centered nav left when Clerk's JS
 * finishes mounting and the avatar grows from 0 → ~28px. ID selector is
 * kept because Clerk replaces the .user-button-slot class on mount. */
#user-button,
.user-button-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
}

/* Quota indicator in the chat drawer footer */
.chat-drawer-footer .chat-quota.low {
  color: var(--coral-deep);
  font-weight: 500;
}
.chat-drawer-footer > span + span {
  margin-left: 0.75rem;
}
