/* utilizebot portal v2 — unified warm theme (single mood for all pages) */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  color-scheme: light;

  /* Backgrounds (warm cream) — mapped onto the EXISTING token names so
     every downstream rule recolours with no selector changes. */
  --bg:        #faf9f6;   /* page base                     */
  --bg-elev:   #ffffff;   /* cards / panels / topbar bg     */
  --bg-elev-2: #fbfaf7;   /* subtle raised / hover surface  */
  --card:      #ffffff;   /* alias for Aini components       */
  --surface-raised: #fbfaf7;

  /* Borders */
  --border:        #e8e6e0;
  --border-soft:   #efece5;
  --border-strong: #d6d3cc;

  /* Text */
  --text:      #1f1d1b;
  --text-mute: #6b655e;
  --text-dim:  #9a938b;

  /* Accent (burnt orange) */
  --accent:      #ea580c;
  --accent-soft: rgba(234,88,12,0.12);
  --accent-tint: #fff7ed;
  --accent-glow: #f97316;
  --accent-ring: rgba(234,88,12,0.40);

  /* Functional colours (kept — used by feed/usage/sessions).
     Re-expressed as warm-light hex; roles preserved. */
  --user:     #2563eb;                    /* sober blue — user msgs   */
  --user-bg:  #eff4ff;
  --agent:    #7c5cd6;                    /* violet — agent msgs      */
  --agent-bg: #f5f1fc;
  --tool:     #d97706;                    /* amber — tool calls       */
  --tool-bg:  #fef3c7;
  --error:    #dc2626;
  --ok:       #059669;
  --warn:     #d97706;

  /* Status + tints (Aini) */
  --success: #059669; --success-tint: #d1fae5;
  --warn-tint: #fef3c7;
  --danger:  #dc2626; --danger-tint:  #fee2e2;
  --info:    #2563eb; --info-tint:    #dbeafe;

  /* Texture + shadows */
  --grid: rgba(28,25,23,0.035);
  --shadow-card: 0 1px 2px rgba(28,25,23,0.04), 0 2px 8px rgba(28,25,23,0.03);
  --shadow-soft: 0 1px 2px rgba(28,25,23,0.04), 0 4px 16px rgba(28,25,23,0.04);
  --shadow-lift: 0 2px 4px rgba(28,25,23,0.06), 0 12px 32px rgba(28,25,23,0.08);

  /* Type — Fraunces (display/serif), Geist (sans), JetBrains Mono (mono) */
  --serif: 'Fraunces', ui-serif, Georgia, serif;
  --sans:  'Geist', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono:  'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Radii (kept) */
  --r-sm: 4px;
  --r:    6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-full: 9999px;
  --caps: 0.06em;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "ss01", "cv11", "cv02";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Warm cream + subtle 22px dotted grid + gentle vertical gradient.
   Applied to body so it sits behind the sticky topbar and all panes. */
body {
  background-color: var(--bg);
  background-image:
    radial-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(180deg, #faf9f6 0%, #f5f3ed 100%);
  background-size: 22px 22px, auto;
  background-attachment: fixed;
}
body.ops, body.reflection {
  background-color: var(--bg);
  background-image:
    radial-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(180deg, #faf9f6 0%, #f5f3ed 100%);
  background-size: 22px 22px, auto;
  background-attachment: fixed;
}

::selection { background: rgba(234,88,12,0.20); color: var(--text); }

button { font: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* Fraunces optical/variable niceties for all serif display type */
.slide-head h3, .pane-head h2, h1, h2, h3, h4 {
  font-variation-settings: "SOFT" 0, "WONK" 0, "opsz" 40;
}

/* ── topbar with mobile hamburger ──── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky; top: 0;
  z-index: 50;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.brand-mark {
  width: 9px; height: 9px;
  background: var(--accent);
  transform: rotate(45deg);
  flex-shrink: 0;
}
.brand-text {
  font-weight: 600;
  letter-spacing: -0.005em;
  font-size: 15px;
}
.brand-divider { color: var(--text-dim); }
.brand-section { color: var(--text-mute); font-weight: 500; font-size: 13px; }

.topnav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.topnav a {
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text-mute);
  border-radius: var(--r);
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.12s;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}
.topnav a.active {
  color: var(--text);
  background: var(--accent-soft);
  font-weight: 600;
}
.topnav a:hover:not([data-disabled]):not(.active) {
  color: var(--text);
  background: var(--bg-elev-2);
}
.topnav a[data-disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
.topnav-divider {
  width: 1px; height: 18px;
  background: var(--border);
  margin: 0 6px;
}

.connection { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-mute); flex-shrink: 0; }
.connection .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.2s;
}
.connection.live .dot {
  background: var(--ok);
  animation: pulse 2s infinite;
}
.connection.error .dot { background: var(--error); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(92, 201, 127, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(92, 201, 127, 0); }
  100% { box-shadow: 0 0 0 0 rgba(92, 201, 127, 0); }
}

/* Mobile hamburger */
.menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r);
  width: 36px; height: 36px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text);
}
.menu-btn:hover { background: var(--bg-elev-2); }

@media (max-width: 760px) {
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  .menu-btn { display: inline-flex; }
  .topnav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    order: 99;
    gap: 2px;
    padding-top: 8px;
    border-top: 1px solid var(--border-soft);
    margin-top: 8px;
  }
  .topnav.open { display: flex; }
  .topnav a { padding: 12px 10px; min-height: 44px; }
  .topnav-divider { display: none; }
  .brand-section { display: none; }
  .connection { font-size: 11px; }
}

/* ── usage bar ───────────────────────────── */

.usage-bar {
  display: grid;
  grid-template-columns: 1.5fr 1.5fr 1fr 1fr;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
@media (max-width: 880px) {
  .usage-bar { grid-template-columns: 1fr 1fr; padding: 14px; gap: 10px; }
}
@media (max-width: 480px) {
  .usage-bar { grid-template-columns: 1fr; }
}

.usage-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
}
.usage-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 500;
}
.usage-meter {
  height: 8px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 6px;
}
.usage-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--ok));
  border-radius: 99px;
  transition: width 0.5s ease-out;
}
.usage-fill.warn { background: linear-gradient(90deg, var(--warn), var(--tool)); }
.usage-fill.danger { background: linear-gradient(90deg, var(--tool), var(--error)); }
.usage-stats {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
}
.usage-stats .big {
  font-family: var(--sans);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.usage-meta { color: var(--text-mute); font-size: 12px; }

/* ── grid layout ─────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
  padding: 16px 20px 20px;
  min-height: calc(100vh - 152px);
}
@media (max-width: 880px) {
  .grid { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
}

.feed-pane, .side-pane {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
  gap: 8px;
}
.pane-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text);
}
.pane-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--text-mute); font-size: 12px; }

.filter {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--text-mute);
  user-select: none;
  cursor: pointer;
  min-height: 28px;
}
.filter input { accent-color: var(--accent); width: 16px; height: 16px; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 6px 11px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  min-height: 32px;
}
.ghost-btn:hover { background: var(--bg-elev-2); border-color: var(--accent); color: var(--accent); }

/* ── feed ───────────────────────────────── */

.feed {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.feed-empty, .sessions-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.feed-meta-banner {
  padding: 12px 16px;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border-soft);
  font-size: 12px;
  color: var(--text-mute);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.feed-meta-banner strong { color: var(--text); font-weight: 600; }

.event {
  padding: 12px 16px 14px;
  border-bottom: 1px solid var(--border-soft);
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  cursor: pointer;
  transition: background 0.1s;
}
.event:hover { background: var(--bg-elev-2); }

/* Strong visual difference between user and agent */
.event-inbound {
  background: var(--user-bg);
  border-left: 3px solid var(--user);
}
.event-inbound:hover { background: #e4ecff; }

.event-outbound {
  background: var(--bg-elev);
  border-left: 3px solid var(--agent);
}

.event-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-mute);
}
.event-inbound .event-icon { background: var(--user); color: white; }
.event-outbound .event-icon { background: var(--agent); color: white; }

.event-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  color: var(--text-mute);
  flex-wrap: wrap;
}
.event-meta .who { color: var(--text); font-weight: 600; }
.event-meta .where { color: var(--text-mute); }
.event-meta .when {
  color: var(--text-dim);
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

.event-body {
  margin-top: 5px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.event-tools {
  margin-top: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.tool-badge {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--tool-bg);
  border: 1px solid #fcd9a3;
  color: #b45309;
  padding: 2px 7px;
  border-radius: var(--r-sm);
}

.event-files {
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

/* ── sessions ───────────────────────────── */

.sessions { padding: 4px 0; flex: 1; overflow-y: auto; }
.session-row {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.1s;
}
.session-row:hover { background: var(--bg-elev-2); }
.session-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.session-who { font-weight: 600; font-size: 13px; }
.session-where { font-size: 12px; color: var(--text-mute); margin-top: 2px; }
.session-time { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.session-tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.session-tag {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-mute);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: var(--r-sm);
}
.session-row.live .session-tag { color: var(--ok); border-color: var(--ok); }

/* ── slide-over (conversation viewer) ────── */

.slide-over[aria-hidden="true"] { display: none; }
.slide-over[aria-hidden="false"] { display: flex; }
.slide-over {
  position: fixed; inset: 0; z-index: 60;
  align-items: stretch; justify-content: flex-end;
}
.slide-backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 18, 14, 0.45);
  backdrop-filter: blur(2px);
}
.slide-panel {
  position: relative;
  width: min(640px, 92vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  animation: slidein 0.18s ease-out;
}
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.slide-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px;
}
.slide-head h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.slide-body {
  padding: 14px 18px;
  overflow-y: auto;
  flex: 1;
}

.msg-row { padding: 14px 0; border-bottom: 1px solid var(--border-soft); }
.msg-row:last-child { border-bottom: 0; }
.msg-meta {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 6px;
  display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
}
.msg-meta .role-user { color: var(--user); font-weight: 600; }
.msg-meta .role-assistant { color: var(--agent); font-weight: 600; }
.msg-content {
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.msg-tools { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 5px; }

/* ═══════════════════════════════════════════════════════════════════
   EDITORIAL POLISH (2026-07-28) — lift the v2 portal to the sign-in
   page's quality: serif display type, editorial micro-labels, serif
   data figures, softer surfaces, more generous rhythm.
   Additive; wins via cascade. Tokens (cream/coral/Crimson Pro) already
   defined in :root above.
   ═══════════════════════════════════════════════════════════════════ */

/* Serif display for section/panel headings — the single biggest lift */
.pane-head h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* Editorial micro-labels — uppercase, tracked, quiet */
.usage-label {
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-dim);
}

/* Headline figures set in the serif — data that reads like editorial numbers */
.usage-card .big,
#usage-5h-pct, #usage-week-pct, #active-count {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -0.015em;
}

/* Softer, calmer surfaces + a touch more air */
.usage-card, .feed-pane, .side-pane { border-radius: 12px; }
.pane-head { padding-bottom: 14px; margin-bottom: 4px; }
.brand-text { letter-spacing: 0.01em; }
.topbar { border-bottom-color: var(--border-soft); }

/* ─────────────────────────────────────────────────────────────────────
   SECTION B  —  Aini generic component library (append).
   Additive; nothing above references these, so no conflicts. Gives every
   page ready .card/.btn/.pill/.table/.input in the Aini aesthetic.
   ───────────────────────────────────────────────────────────────────── */

/* Generic headings (Fraunces) for any page that uses bare h1–h4 */
h1, h2, h3, h4 {
  font-family: var(--serif);
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.011em;
  margin: 0 0 0.5em;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
}
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow-soft);
  transition: box-shadow .2s, transform .2s;
}
.kpi-card:hover { box-shadow: 0 1px 2px rgba(28,25,23,0.06), 0 8px 24px rgba(28,25,23,0.06); }
.kpi-card .kpi-value { font-family: var(--serif); font-size: 2rem; line-height: 1; color: var(--text); }
.kpi-card .kpi-label {
  font-size: 0.6875rem; text-transform: uppercase;
  letter-spacing: var(--caps); color: var(--text-mute); margin-top: .5rem;
}
.divider { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  border-radius: var(--r); padding: 0.5rem 1rem;
  font-family: var(--sans); font-size: 0.875rem; font-weight: 500; line-height: 1.2;
  border: 1px solid transparent; cursor: pointer; transition: all .2s; text-decoration: none;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(234,88,12,0.50); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 1px 2px rgba(234,88,12,0.25), 0 0 0 1px rgba(234,88,12,0.35) inset;
}
.btn-primary:hover  { background: var(--accent-glow); }
.btn-primary:active { transform: scale(0.98); }
.btn-ghost { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-elev-2); border-color: var(--border-strong); }
.btn-danger { background: var(--danger-tint); color: var(--danger); border: 1px solid rgba(220,38,38,0.20); }
.btn-danger:hover { background: rgba(220,38,38,0.20); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8125rem; }

/* Inputs */
.input, input[type="text"], input[type="email"], input[type="password"],
input[type="search"], input[type="number"], textarea, select {
  width: 100%; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r); padding: 0.5rem 0.75rem;
  font-family: var(--sans); font-size: 0.875rem; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder, input::placeholder, textarea::placeholder { color: var(--text-dim); }
.input:focus, input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px rgba(234,88,12,0.40);
}
textarea { min-height: 6rem; resize: vertical; line-height: 1.6; }

/* Pills / badges */
.pill, .badge {
  display: inline-flex; align-items: center; gap: 0.375rem;
  border-radius: var(--r-full); padding: 0.25rem 0.625rem;
  font-size: 0.6875rem; line-height: 1; text-transform: uppercase;
  letter-spacing: var(--caps); font-weight: 600; border: 1px solid transparent;
}
.pill-accent  { background: var(--accent-tint);  color: var(--accent);  border-color: #fed7aa; }
.pill-success { background: var(--success-tint);  color: var(--success); }
.pill-warn    { background: var(--warn-tint);     color: var(--warn); }
.pill-danger  { background: var(--danger-tint);   color: var(--danger); }
.pill-info    { background: var(--info-tint);     color: var(--info); }
.pill-neutral { background: var(--bg-elev-2);     color: var(--text-mute); border-color: var(--border); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--card); box-shadow: var(--shadow-card); }
table.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.table thead th {
  text-align: left; font-size: 0.6875rem; text-transform: uppercase;
  letter-spacing: var(--caps); font-weight: 600; color: var(--text-mute);
  background: #f5f3ed; padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.table tbody td { padding: 0.7rem 1rem; color: var(--text); border-bottom: 1px solid var(--border-soft); }
table.table tbody tr:last-child td { border-bottom: 0; }
table.table tbody tr { transition: background .12s; }
table.table tbody tr:hover { background: #f5f3ed; }
table.table td .mono, table.table td code { font-family: var(--mono); font-size: 0.8125rem; }

/* Inline code / pre (JetBrains Mono) */
code, .code {
  font-family: var(--mono); font-size: 0.6875rem;
  background: #f0eee8; border: 1px solid var(--border-soft);
  padding: 0.1rem 0.35rem; border-radius: 4px; color: var(--text);
}
pre {
  font-family: var(--mono); font-size: 0.75rem; line-height: 1.6;
  background: #f0eee8; border: 1px solid var(--border-soft);
  border-radius: var(--r-md); padding: 0.85rem 1rem; margin: 1rem 0; overflow-x: auto;
}
pre code { background: transparent; border: 0; padding: 0; color: var(--text); }
