/* ═══════════════════════════════════════════════════════════════════════════
   VERDÌA · Design System
   Editorial Cream · Serif-first · Mobile-perfect · Chat-centric
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Newsreader:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Inter:wght@400;500;600;700&display=swap');

/* ─── Design Tokens ───────────────────────────────────────────────────────── */
:root {
  /* Editorial Cream palette */
  --paper:        #FAF6EB;   /* page background */
  --paper-soft:   #F5F1E8;   /* hero / soft sections */
  --paper-deep:   #EDE7D6;   /* press / depressed surfaces */
  --bg-card:      #FFFCF4;   /* cards, panels */
  --bg-elevated:  #FFFFFF;   /* modals, popovers */

  --ink:          #1F2419;   /* primary text */
  --ink-soft:     #3D4334;   /* heading variant */
  --ink-mute:     #595D4F;   /* secondary text */
  --ink-faint:    #8C9082;   /* tertiary text, captions */

  --olive:        #5C6B3A;   /* primary accent (links, brand) */
  --olive-deep:   #4A5630;
  --olive-soft:   #94A57F;   /* sage, decorative */
  --olive-tint:   #E8ECDC;   /* hover bg */

  --terracotta:   #B8553F;   /* CTA / alert / "live" */
  --terracotta-deep: #9C4A37;
  --terracotta-tint: #F5E2DA;

  --gold:         #B89B5E;   /* premium accent */
  --gold-soft:    #D8C597;

  --line:         #D8D3C5;   /* dividers */
  --line-soft:    #E5E1D5;
  --line-strong:  #B7B0A0;

  --ok:   var(--olive);
  --warn: var(--gold);
  --err:  var(--terracotta);

  --shadow-xs: 0 1px 1px rgba(31,36,25,.04);
  --shadow-sm: 0 1px 2px rgba(31,36,25,.05), 0 2px 6px rgba(31,36,25,.04);
  --shadow-md: 0 2px 4px rgba(31,36,25,.06), 0 12px 28px rgba(31,36,25,.08);
  --shadow-lg: 0 4px 8px rgba(31,36,25,.08), 0 24px 56px rgba(31,36,25,.10);

  /* Typography */
  --font-display: 'Newsreader', 'Times New Roman', Georgia, serif;
  --font-body:    'Newsreader', 'Times New Roman', Georgia, serif;
  --font-ui:      'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono:    'SFMono-Regular', 'Menlo', 'Monaco', monospace;

  /* Type scale (mobile-first, scaled up at md) */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-md: 17px;
  --text-lg: 19px;
  --text-xl: 22px;
  --text-2xl: 27px;
  --text-3xl: 34px;
  --text-4xl: 42px;
  --text-5xl: 56px;

  /* Spacing */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 40px;
  --s-10: 56px;
  --s-12: 72px;
  --s-16: 96px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-2xl: 28px;
  --r-full: 9999px;

  /* Transitions */
  --t-fast: 120ms cubic-bezier(.2,.7,.3,1);
  --t-base: 220ms cubic-bezier(.2,.7,.3,1);
  --t-slow: 360ms cubic-bezier(.2,.7,.3,1);

  /* Layout */
  --max-content: 720px;
  --max-wide: 1100px;
  --max-narrow: 580px;

  --header-h: 64px;
  --bnav-h:   64px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Legacy compat (existing JS may still reference these) */
  --bg-primary: var(--paper);
  --bg-secondary: var(--bg-card);
  --bg-input: var(--paper-soft);
  --bg-hover: var(--olive-tint);
  --border: var(--line);
  --border-focus: var(--olive);
  --border-accent: var(--olive);
  --text-primary: var(--ink);
  --text-secondary: var(--ink-mute);
  --text-muted: var(--ink-faint);
  --accent: var(--olive);
  --accent-light: var(--olive-soft);
  --accent-bg: var(--olive-tint);
  --danger: var(--terracotta);
  --warning: var(--gold);
  --bio: var(--olive);
  --conv: var(--ink-mute);
  --shadow: var(--shadow-sm);
  --radius: var(--r-md);
  --transition: var(--t-base);
  --font-sans: var(--font-ui);
}

/* ─── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
  font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(31,36,25,.018) 1px, transparent 0);
  background-size: 24px 24px;
}
img, svg, video { max-width: 100%; display: block; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--ink); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--olive); }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-6) 0; }
::selection { background: var(--olive-tint); color: var(--ink); }

/* Headings */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.012em;
  color: var(--ink);
  margin: 0;
}
h1 { font-size: var(--text-3xl); letter-spacing: -0.02em; }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); font-weight: 600; }
@media (min-width: 768px) {
  h1 { font-size: var(--text-5xl); }
  h2 { font-size: var(--text-3xl); }
  h3 { font-size: var(--text-2xl); }
}

p { margin: 0 0 var(--s-4) 0; }
.lede { font-size: var(--text-lg); color: var(--ink-mute); line-height: 1.55; }
.kicker {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--olive);
}

/* Layout container */
.container {
  width: 100%;
  max-width: var(--max-content);
  margin: 0 auto;
  padding: 0 var(--s-5);
}
.container-wide { max-width: var(--max-wide); }
.container-narrow { max-width: var(--max-narrow); }
@media (min-width: 768px) { .container { padding: 0 var(--s-8); } }

.stack > * + * { margin-top: var(--s-4); }
.stack-lg > * + * { margin-top: var(--s-8); }
.stack-xl > * + * { margin-top: var(--s-12); }

/* ─── Site header ─────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(250,246,235,0.85);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line-soft);
  padding-top: var(--safe-top);
}
.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  max-width: var(--max-wide);
  margin: 0 auto;
  padding: 0 var(--s-5);
}
@media (min-width: 768px) { .site-header-inner { padding: 0 var(--s-8); } }

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.022em;
  color: var(--ink);
  user-select: none;
}
.brand-accent { color: var(--olive); font-style: italic; }
.brand:hover { color: var(--ink); }

.nav-links {
  display: none;
  align-items: center;
  gap: var(--s-6);
}
.nav-link {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-mute);
  letter-spacing: 0.01em;
}
.nav-link:hover, .nav-link.active { color: var(--ink); }
@media (min-width: 768px) { .nav-links { display: inline-flex; } }

.nav-actions { display: inline-flex; align-items: center; gap: var(--s-3); }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0.005em;
  padding: 11px 20px;
  min-height: 44px;
  border-radius: var(--r-full);
  border: 1px solid transparent;
  transition: all var(--t-fast);
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: translateY(0.5px); }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--olive-deep); }
.btn-secondary { background: var(--olive); color: var(--paper); }
.btn-secondary:hover { background: var(--olive-deep); }
.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn-ghost:hover { background: var(--bg-card); border-color: var(--ink); }
.btn-cta { background: var(--terracotta); color: white; }
.btn-cta:hover { background: var(--terracotta-deep); }
.btn-icon {
  width: 40px; height: 40px;
  min-height: 0;
  padding: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--ink-mute);
  border-color: transparent;
}
.btn-icon:hover { background: var(--paper-soft); color: var(--ink); }
.btn-sm { padding: 7px 14px; min-height: 36px; font-size: var(--text-xs); }
.btn-lg { padding: 14px 28px; min-height: 52px; font-size: var(--text-base); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

/* ─── Inputs ──────────────────────────────────────────────────────────────── */
.input, .textarea, .select {
  width: 100%;
  padding: 13px 18px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.4;
  color: var(--ink);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  min-height: 48px;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-faint); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--olive);
  box-shadow: 0 0 0 3px var(--olive-tint);
}
.textarea { min-height: 120px; resize: vertical; }
.field-label {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: var(--s-2);
}

/* ─── Chips & Badges ─────────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 6px 12px;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  color: var(--ink-mute);
  cursor: pointer;
  transition: all var(--t-fast);
}
.chip:hover { border-color: var(--ink); color: var(--ink); }
.chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: var(--r-sm);
  background: var(--paper-deep);
  color: var(--ink-mute);
}
.badge-olive    { background: var(--olive-tint);      color: var(--olive-deep); }
.badge-terra    { background: var(--terracotta-tint); color: var(--terracotta-deep); }
.badge-gold     { background: #f5edd2;                color: #7a6433; }
.badge-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ─── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-xl);
  padding: var(--s-6);
  transition: border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.card:hover { border-color: var(--line-strong); }
.card-link { display: block; cursor: pointer; text-decoration: none; color: inherit; }
.card-link:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* ─── Health banner ──────────────────────────────────────────────────────── */
.health-banner {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 4px 12px;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-mute);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: all var(--t-fast);
}
.health-banner:hover { border-color: var(--ink); color: var(--ink); }
.health-banner-dot {
  width: 7px; height: 7px; border-radius: 50%; display: inline-block;
  background: var(--olive);
  animation: pulse 2.4s infinite;
}
.health-banner.fresh    .health-banner-dot { background: var(--olive);     animation-name: pulse; }
.health-banner.stale    .health-banner-dot { background: var(--gold);      animation: none; }
.health-banner.outdated .health-banner-dot { background: var(--terracotta); animation: pulse-warn 1.6s infinite; }
.health-banner.unknown  .health-banner-dot { background: var(--ink-faint); animation: none; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(92,107,58,.6); }
  70%  { box-shadow: 0 0 0 6px rgba(92,107,58,0); }
  100% { box-shadow: 0 0 0 0 rgba(92,107,58,0); }
}
@keyframes pulse-warn {
  0%   { box-shadow: 0 0 0 0 rgba(184,85,63,.6); }
  70%  { box-shadow: 0 0 0 7px rgba(184,85,63,0); }
  100% { box-shadow: 0 0 0 0 rgba(184,85,63,0); }
}

.health-popover {
  position: absolute;
  margin-top: var(--s-2);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--shadow-md);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-mute);
  min-width: 240px;
  display: none;
  z-index: 60;
}
.health-popover.open { display: block; }
.health-popover strong { color: var(--ink); }

/* ─── Mobile bottom nav ──────────────────────────────────────────────────── */
.bnav { display: none; }
@media (max-width: 767px) {
  .bnav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(255,252,244,0.92);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--line);
    padding-bottom: var(--safe-bottom);
    height: calc(var(--bnav-h) + var(--safe-bottom));
    z-index: 90;
  }
  .bnav-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px;
    color: var(--ink-faint);
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.01em;
    text-decoration: none;
    transition: color var(--t-fast);
    -webkit-tap-highlight-color: transparent;
  }
  .bnav-item svg { width: 22px; height: 22px; stroke-width: 1.6; }
  .bnav-item.active { color: var(--ink); }
  .bnav-item.active svg { color: var(--olive); }
  body { padding-bottom: calc(var(--bnav-h) + var(--safe-bottom)); }
}

.mobile-only { display: none; }
.desktop-only { display: inline-flex; }
@media (max-width: 767px) {
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none; }
}

/* ─── Hero (chat-first) ──────────────────────────────────────────────────── */
.hero { text-align: center; padding: var(--s-10) 0 var(--s-7); position: relative; }
@media (min-width: 768px) { .hero { padding: var(--s-16) 0 var(--s-10); } }

.hero-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--text-3xl);
  line-height: 1.08;
  letter-spacing: -0.024em;
  margin-bottom: var(--s-3);
}
.hero-title em { font-style: italic; color: var(--olive); }
@media (min-width: 768px) { .hero-title { font-size: var(--text-5xl); } }
.hero-sub {
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--ink-mute);
  max-width: 540px;
  margin: 0 auto var(--s-7);
  line-height: 1.55;
  font-style: italic;
}
@media (min-width: 768px) { .hero-sub { font-size: var(--text-lg); } }

/* Main chat-input on hero */
.chat-launcher { position: relative; max-width: 640px; margin: 0 auto; }
.chat-launcher-input {
  width: 100%;
  padding: 12px 14px 4px 14px;
  background: transparent;
  border: none;
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.4;
  color: var(--ink);
  resize: none;
  min-height: 48px;
  max-height: 200px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.chat-launcher-input::-webkit-scrollbar {
  display: none;
}
.chat-launcher-input:focus {
  outline: none;
}
#launcherForm {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--t-base), border-color var(--t-fast);
  padding: 8px;
}
#launcherForm:focus-within {
  border-color: var(--olive);
  box-shadow: var(--shadow-md), 0 0 0 4px var(--olive-tint);
}
.chat-send {
  width: 40px; height: 40px;
  border-radius: var(--r-full);
  background: var(--ink);
  color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--t-fast);
}
.chat-send:hover { background: var(--olive-deep); transform: scale(1.04); }
.chat-send:disabled { background: var(--line-strong); cursor: not-allowed; }

/* Starter cards */
.starter-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-3);
  margin-top: var(--s-7);
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}
@media (min-width: 768px) { .starter-row { grid-template-columns: repeat(4, 1fr); } }
.starter-card {
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-5);
  text-align: left;
  cursor: pointer;
  transition: all var(--t-fast);
  min-height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.starter-card:hover {
  border-color: var(--ink);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.starter-card .kicker { font-size: 10px; }
.starter-card-text {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink);
  line-height: 1.4;
  margin-top: var(--s-2);
}

.section-rule {
  display: flex; align-items: center; gap: var(--s-4);
  margin: var(--s-12) 0 var(--s-6);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.section-rule::before, .section-rule::after { content: ''; flex: 1; border-top: 1px solid var(--line); }

.section-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  letter-spacing: -0.01em;
  margin: var(--s-7) 0 var(--s-4);
}

/* ─── Chat surface ───────────────────────────────────────────────────────── */
.chat-shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-h));
  min-height: calc(100dvh - var(--header-h));
}
@media (max-width: 767px) {
  .chat-shell { min-height: calc(100dvh - var(--header-h) - var(--bnav-h) - var(--safe-bottom)); }
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-6) var(--s-5) var(--s-8);
  width: 100%;
  max-width: var(--max-content);
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
@media (min-width: 768px) { .chat-thread { padding: var(--s-8); } }

.msg {
  display: flex;
  gap: var(--s-3);
  margin-bottom: var(--s-6);
  animation: msg-in var(--t-slow) both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg-avatar {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  user-select: none;
}
.msg.user .msg-avatar { background: var(--ink); color: var(--paper); }
.msg.assistant .msg-avatar {
  background: var(--olive-tint);
  color: var(--olive-deep);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 16px;
}
.msg-body {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.65;
  color: var(--ink);
  padding-top: 4px;
  overflow-wrap: anywhere;
}
.msg-body p { margin: 0 0 var(--s-3); }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body strong { color: var(--ink); font-weight: 600; }
.msg-body em { color: var(--ink-soft); }
.msg-body ul, .msg-body ol { margin: 0 0 var(--s-3); padding-left: 1.2em; }
.msg-body li { margin-bottom: var(--s-1); }
.msg-body code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--paper-deep);
  padding: 1px 5px;
  border-radius: 4px;
}
.msg-body pre {
  background: var(--paper-deep);
  border-radius: var(--r-md);
  padding: var(--s-4);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  margin: var(--s-3) 0;
}
.msg-body table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--s-4) 0;
  font-size: var(--text-sm);
}
.msg-body th, .msg-body td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.msg-body th {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-mute);
  border-bottom: 1px solid var(--ink);
}
.msg-body blockquote {
  border-left: 3px solid var(--olive);
  padding-left: var(--s-4);
  margin: var(--s-4) 0;
  font-style: italic;
  color: var(--ink-mute);
}

/* Thinking pills (tool calls) */
.thinking-trail {
  display: flex; flex-wrap: wrap; gap: var(--s-2);
  margin: var(--s-3) 0;
}
.trail-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  background: var(--paper-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-full);
  color: var(--ink-mute);
}
.trail-chip.running {
  background: var(--olive-tint);
  border-color: var(--olive-soft);
  color: var(--olive-deep);
}
.trail-chip.running::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--olive); animation: chip-pulse 1s infinite;
}
.trail-chip.done { color: var(--ink); }
.trail-chip.error { background: var(--terracotta-tint); color: var(--terracotta-deep); border-color: var(--terracotta-deep); }
@keyframes chip-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(0.7); }
}

/* Follow-up suggestion chips */
.followup-row { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-4); }
.followup-chip {
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink);
  cursor: pointer;
  transition: all var(--t-fast);
}
.followup-chip:hover { background: var(--bg-card); border-color: var(--ink); transform: translateY(-1px); }

/* Chat input bar (sticky bottom) */
.chat-bar {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--paper) 70%, transparent);
  padding: var(--s-4) var(--s-5) var(--s-5);
  margin-top: auto;
  z-index: 30;
}
@media (max-width: 767px) {
  .chat-bar {
    position: fixed;
    bottom: calc(var(--bnav-h) + var(--safe-bottom));
    left: 0; right: 0;
    background: linear-gradient(to top, var(--paper) 80%, transparent);
    padding: var(--s-3) var(--s-4) var(--s-3);
  }
}
.chat-bar-inner {
  position: relative;
  max-width: var(--max-content);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-2xl);
  padding: 8px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.chat-bar-inner:focus-within {
  border-color: var(--olive);
  box-shadow: var(--shadow-md), 0 0 0 4px var(--olive-tint);
}
.chat-input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.4;
  color: var(--ink);
  resize: none;
  padding: 12px 14px 4px 14px;
  max-height: 160px;
  min-height: 48px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.chat-input::-webkit-scrollbar {
  display: none;
}
.chat-bar-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  padding: 0 4px;
}
.btn-plus {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1.5px solid #236df5; /* Blue border */
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  transition: all var(--t-fast);
  cursor: pointer;
}
.btn-plus:hover { background: var(--paper-soft); }

.attach-popover {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-2);
  box-shadow: var(--shadow-md);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 220px;
}
.attach-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--ink);
  border-radius: var(--r-md);
  text-align: left;
  transition: background var(--t-fast);
  width: 100%;
  white-space: nowrap;
}
.attach-item:hover { background: var(--paper-soft); }

.chat-tools { display: flex; align-items: center; gap: 4px; }
.chat-tool {
  width: 40px; height: 40px;
  border-radius: var(--r-full);
  color: var(--ink-mute);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--t-fast);
}
.chat-tool:hover { background: var(--paper-soft); color: var(--ink); }
.chat-send:hover { background: var(--olive-deep); }
.chat-send:disabled, .chat-send[aria-disabled="true"] { background: var(--line-strong); cursor: not-allowed; }

/* Image preview attached */
.image-attached {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 12px 6px 6px;
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  margin: var(--s-2) auto;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-mute);
}
.image-attached img { width: 28px; height: 28px; border-radius: var(--r-full); object-fit: cover; }
.image-attached-x {
  width: 22px; height: 22px;
  border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-mute);
}
.image-attached-x:hover { background: var(--paper-deep); color: var(--ink); }

.chat-tool.recording {
  background: var(--terracotta);
  color: white;
  animation: chip-pulse 1s infinite;
}
/* Spinner mentre Whisper trascrive l'audio registrato */
.chat-tool.transcribing { position: relative; pointer-events: none; }
.chat-tool.transcribing svg { opacity: 0; }
.chat-tool.transcribing::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--olive);
  border-radius: var(--r-full);
  animation: spin .7s linear infinite;
}

/* ─── DPI (Disciplinari SQNPI) — pagina /disciplinari ─────────────────────── */
.dpi-empty {
  text-align: center;
  padding: var(--s-12) var(--s-4);
  color: var(--ink-mute);
  font-family: var(--font-ui);
}
.dpi-chip-sep {
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  color: var(--ink-mute);
  opacity: 0.4;
}
.chip-disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}
.dpi-doc-card {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  margin-bottom: var(--s-6);
}
.dpi-doc-title {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  color: var(--ink);
  margin-bottom: 4px;
}
.dpi-doc-subtitle {
  font-family: var(--font-ui);
  color: var(--ink-mute);
  margin-bottom: var(--s-4);
  font-size: var(--text-sm);
}
.dpi-doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  font-size: var(--text-sm);
  color: var(--ink);
  margin-bottom: var(--s-4);
  font-family: var(--font-ui);
}
.dpi-doc-meta span { white-space: nowrap; }
.dpi-doc-actions {
  display: flex;
  gap: var(--s-3);
  flex-wrap: wrap;
}
.dpi-section-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: var(--ink);
  margin: var(--s-6) 0 var(--s-3);
}
.dpi-search {
  width: 100%;
  max-width: 480px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  background: var(--paper-soft);
  margin-bottom: var(--s-4);
}
.dpi-search:focus { outline: 2px solid var(--olive-deep, #5a7a3a); border-color: var(--olive-deep, #5a7a3a); }
.dpi-colture-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--s-3);
}
.dpi-coltura-card {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-elevated);
  text-decoration: none;
  color: var(--ink);
  transition: all var(--t-fast);
}
.dpi-coltura-card:hover {
  border-color: var(--olive-deep, #5a7a3a);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.dpi-coltura-name {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: var(--text-md);
  margin-bottom: 2px;
}
.dpi-coltura-meta {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-mute);
}
.dpi-back-btn { margin-bottom: var(--s-4); }
.dpi-coltura-header {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  margin-bottom: var(--s-4);
}
.dpi-coltura-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  color: var(--ink);
  margin-bottom: 4px;
}
.dpi-coltura-sub {
  font-family: var(--font-ui);
  color: var(--ink-mute);
  font-size: var(--text-sm);
}
.dpi-coltura-sub a { color: var(--olive-deep, #5a7a3a); text-decoration: underline; }
.dpi-norme-controls { margin-bottom: var(--s-3); }
.dpi-norme-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-elevated);
}
.dpi-norme-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}
.dpi-norme-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--paper-soft);
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-mute);
  position: sticky;
  top: 0;
}
.dpi-norme-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  vertical-align: top;
}
.dpi-norme-table tr:hover td { background: var(--paper-soft); }
.dpi-norme-note { max-width: 360px; }
.dpi-norme-cat-row td {
  background: var(--olive-soft, #eef3e8);
  color: var(--olive-deep, #5a7a3a);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.dpi-sa-ok { color: var(--olive-deep, #5a7a3a); margin-right: 4px; }
.dpi-sa-warn { color: var(--ink-mute); margin-right: 4px; }
.dpi-skeleton {
  padding: var(--s-6);
  color: var(--ink-mute);
  text-align: center;
  font-family: var(--font-ui);
}

/* ─── Region selector (SQNPI) ─────────────────────────────────────────────── */
.region-selector { position: relative; }
.region-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--r-full);
  border: 1px solid var(--line);
  background: transparent;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-mute);
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  max-width: 220px;
}
.region-pill:hover { background: var(--paper-soft); color: var(--ink); }
.region-pill.is-active {
  background: var(--olive-soft, #eef3e8);
  border-color: var(--olive-deep, #5a7a3a);
  color: var(--olive-deep, #5a7a3a);
}
.region-pill-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}
.region-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 4px;
  box-shadow: var(--shadow-md);
  z-index: 60;
  min-width: 260px;
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.region-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--ink);
  border-radius: var(--r-md);
  cursor: pointer;
  background: transparent;
  text-align: left;
  width: 100%;
  border: 0;
  transition: background var(--t-fast);
}
.region-item:hover { background: var(--paper-soft); }
.region-item.is-current { background: var(--olive-soft, #eef3e8); }
.region-item-name { flex: 1; }
.region-item-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: var(--r-full);
  background: var(--paper-soft);
  color: var(--ink-mute);
  border: 1px solid var(--line);
}
.region-item-badge.is-available {
  background: var(--olive-soft, #eef3e8);
  color: var(--olive-deep, #5a7a3a);
  border-color: var(--olive-deep, #5a7a3a);
}
.region-item.is-disabled { opacity: 0.55; cursor: default; }
.region-item-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}
.region-item-header {
  padding: 6px 12px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-mute);
}

/* ─── News page ──────────────────────────────────────────────────────────── */
.news-page { padding: var(--s-8) 0 var(--s-12); }
.news-header { text-align: center; margin-bottom: var(--s-8); }
.news-header-title {
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  font-weight: 500;
  letter-spacing: -0.02em;
}
.news-header-sub {
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--ink-mute);
  font-style: italic;
  margin-top: var(--s-2);
}
.news-filter-row {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-bottom: var(--s-8);
  justify-content: center;
}
.news-grid { display: grid; grid-template-columns: 1fr; gap: var(--s-6); }
.news-card {
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--s-7);
  cursor: pointer;
  transition: opacity var(--t-fast);
}
.news-card:hover { opacity: .85; }
.news-card-meta {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-mute);
}
.news-card-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.012em;
  margin-bottom: var(--s-2);
  color: var(--ink);
}
@media (min-width: 768px) { .news-card-title { font-size: var(--text-3xl); } }
.news-card-sub {
  font-family: var(--font-body);
  font-style: italic;
  font-size: var(--text-md);
  color: var(--ink-mute);
  line-height: 1.5;
  margin-bottom: var(--s-3);
}
.news-card-excerpt {
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.65;
  color: var(--ink-soft);
}
.news-card-readmore {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-4);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--olive);
  letter-spacing: 0.02em;
}

/* Single-post view */
.post-view {
  max-width: var(--max-narrow);
  margin: 0 auto;
  padding: var(--s-10) var(--s-5) var(--s-16);
}
.post-meta {
  display: flex;
  gap: var(--s-3);
  align-items: center;
  margin-bottom: var(--s-5);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-mute);
}
.post-title {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin-bottom: var(--s-3);
}
@media (min-width: 768px) { .post-title { font-size: var(--text-5xl); } }
.post-sub {
  font-family: var(--font-body);
  font-style: italic;
  font-size: var(--text-lg);
  color: var(--ink-mute);
  line-height: 1.5;
  margin-bottom: var(--s-8);
}
.post-body {
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.75;
  color: var(--ink);
}
.post-body h2, .post-body h3 { margin-top: var(--s-8); margin-bottom: var(--s-3); }
.post-body p { margin-bottom: var(--s-4); }
.post-body strong { font-weight: 600; }
.post-body a { color: var(--olive); border-bottom: 1px solid var(--olive-soft); }
.post-body a:hover { color: var(--olive-deep); border-bottom-color: var(--olive-deep); }
.post-body ul, .post-body ol { margin: 0 0 var(--s-4) 0; padding-left: 1.4em; }
.post-body blockquote {
  border-left: 3px solid var(--olive);
  padding-left: var(--s-5);
  margin: var(--s-6) 0;
  font-style: italic;
  color: var(--ink-mute);
}
.sources {
  margin-top: var(--s-12);
  padding-top: var(--s-6);
  border-top: 1px solid var(--line);
}
.sources-title {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: var(--s-4);
}
.sources-list { list-style: none; padding: 0; margin: 0; }
.sources-list li {
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.5;
}
.sources-list a { color: var(--olive); word-break: break-word; }

/* ─── News: "Cosa è cambiato" sezione diff ──────────────────────────────── */
.changes-section {
  margin-top: var(--s-8);
  padding-top: var(--s-6);
  border-top: 1px solid var(--line);
}
.change-group {
  margin-top: var(--s-4);
  padding: var(--s-4);
  background: var(--paper-soft);
  border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
}
.change-group-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  padding-bottom: var(--s-3);
  margin-bottom: var(--s-3);
  border-bottom: 1px dashed var(--line-soft);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}
.change-event {
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px dotted var(--line-soft);
}
.change-event:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.diff-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  margin-top: var(--s-2);
}
.diff-table th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-mute);
  padding: var(--s-1) var(--s-2);
  border-bottom: 1px solid var(--line-soft);
}
.diff-table td {
  padding: var(--s-1) var(--s-2);
  vertical-align: top;
  border-bottom: 1px solid var(--line-soft);
}
.diff-table td:first-child { color: var(--ink-mute); white-space: nowrap; }
.diff-json {
  background: var(--paper);
  padding: var(--s-2);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  overflow-x: auto;
  margin: 0;
}

/* ─── Admin page ─────────────────────────────────────────────────────────── */
.admin-page { padding: var(--s-8) 0 var(--s-12); }
.admin-tabs {
  display: inline-flex;
  gap: 2px;
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  padding: 4px;
  margin-bottom: var(--s-6);
}
.admin-tab {
  padding: 8px 18px;
  border-radius: var(--r-full);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-mute);
  cursor: pointer;
  transition: all var(--t-fast);
}
.admin-tab.active { background: var(--bg-card); color: var(--ink); box-shadow: var(--shadow-xs); }
.admin-toolbar {
  display: flex; flex-wrap: wrap;
  gap: var(--s-3);
  align-items: center;
  margin-bottom: var(--s-5);
}
.admin-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-xl);
  overflow: hidden;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}
.admin-table th {
  background: var(--paper-soft);
  text-align: left;
  padding: var(--s-3) var(--s-4);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-mute);
  border-bottom: 1px solid var(--line);
}
.admin-table td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
.admin-table tr:hover td { background: var(--paper-soft); }
.admin-table tr:last-child td { border-bottom: none; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(31,36,25,0.4);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--s-5);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--s-6);
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  margin-bottom: var(--s-3);
}

/* ─── Case files (lista) ─────────────────────────────────────────────────── */
.cases-panel {
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-xl);
  padding: var(--s-5);
}
.case-item {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: opacity var(--t-fast);
}
.case-item:last-child { border-bottom: none; }
.case-item:hover { opacity: .85; }
.case-item-icon {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 18px;
  color: var(--olive);
  flex: 0 0 20px;
}
.case-item-body { flex: 1; min-width: 0; }
.case-item-title {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.case-item-meta {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

/* ─── Login & register page ──────────────────────────────────────────────── */
.auth-page {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: var(--s-6);
}
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: var(--s-8);
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-md);
}
.auth-card .brand { display: flex; justify-content: center; margin-bottom: var(--s-6); }

/* ─── Utility ────────────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }
.gap-6 { gap: var(--s-6); }
.hidden, [hidden] { display: none !important; }
.visually-hidden {
  opacity: 0;
  position: absolute;
  z-index: -1;
  width: 1px;
  height: 1px;
}
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-mute { color: var(--ink-mute); }
.text-faint { color: var(--ink-faint); }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center;
  padding: var(--s-12) var(--s-5);
  font-family: var(--font-body);
  color: var(--ink-faint);
  font-style: italic;
}

.disclaimer {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink-faint);
  text-align: center;
  margin-top: var(--s-2);
  letter-spacing: 0.01em;
}
@media (max-width: 767px) { .disclaimer { display: none; } }

@media print {
  .site-header, .bnav, .chat-bar, .nav-actions, .followup-row, .thinking-trail { display: none !important; }
  body { background: white; padding: 0; }
  .container { max-width: 100%; padding: 0; }
}

/* ─── Save-case modal (themed, agronomic editorial) ───────────────────────── */
.modal-case { max-width: 560px; padding: 0; overflow: hidden; }
.case-modal-head {
  padding: var(--s-6) var(--s-6) var(--s-5);
  background: var(--paper-soft);
  border-bottom: 1px solid var(--line-soft);
  position: relative;
}
.case-modal-head::after {
  content: '';
  position: absolute;
  left: var(--s-6); bottom: -1px;
  width: 40px; height: 2px;
  background: var(--olive);
}
.case-modal-head .kicker { display: block; margin-bottom: var(--s-2); color: var(--olive); }
.case-modal-head .modal-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 500;
  letter-spacing: -0.014em;
  margin: 0;
}
.case-modal-head .modal-tagline {
  font-family: var(--font-body);
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--ink-mute);
  margin: var(--s-2) 0 0;
  line-height: 1.5;
  max-width: 92%;
}
.case-modal-body { padding: var(--s-5) var(--s-6); }
.case-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-6);
  background: var(--paper-soft);
  border-top: 1px solid var(--line-soft);
}
.case-modal-footer-msg {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink-faint);
  min-height: 16px;
  flex: 1;
}
.case-modal-footer-actions { display: flex; gap: var(--s-2); }

.case-preview {
  background: var(--bg-card);
  border-left: 3px solid var(--olive);
  padding: var(--s-4) var(--s-5);
  margin: 0 0 var(--s-5);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  font-family: var(--font-body);
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--ink-mute);
  line-height: 1.55;
}
.case-preview-label {
  display: block;
  font-family: var(--font-ui);
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--olive);
  margin-bottom: var(--s-2);
}
.case-preview-text { display: block; }
.case-preview-text::before { content: '«'; color: var(--olive-soft); margin-right: 2px; }
.case-preview-text::after  { content: '»'; color: var(--olive-soft); margin-left: 2px; }

.case-tag-suggestions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: var(--s-2);
  min-height: 0;
}
.case-tag-suggestions:empty { display: none; }
.case-tag-suggestions-label {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink-faint);
  margin-right: 4px;
  letter-spacing: 0.02em;
}
.case-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  background: var(--olive-tint);
  border: 1px solid transparent;
  border-radius: var(--r-full);
  color: var(--olive-deep);
  cursor: pointer;
  transition: all var(--t-fast);
}
.case-tag-chip::before {
  content: '+';
  font-weight: 600;
  font-size: 12px;
  opacity: .7;
}
.case-tag-chip:hover { background: var(--olive); color: white; }
.case-tag-chip:hover::before { opacity: 1; }
.case-tag-chip.added { background: var(--olive); color: white; pointer-events: none; }
.case-tag-chip.added::before { content: '✓'; }

/* ─── Search / Catalogo page ─────────────────────────────────────────────── */
.search-page { padding: var(--s-8) 0 var(--s-12); }
.search-header { margin-bottom: var(--s-7); max-width: 720px; }
.search-title {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: var(--s-2) 0 var(--s-3);
}
@media (min-width: 768px) { .search-title { font-size: var(--text-4xl); } }
.search-sub {
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--ink-mute);
  line-height: 1.55;
  font-style: italic;
}

.search-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-3);
  align-items: end;
  margin: var(--s-6) 0 var(--s-5);
  padding: var(--s-5);
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-xl);
}
@media (min-width: 768px) {
  .search-filters { grid-template-columns: 1fr 1fr 1fr auto; gap: var(--s-4); }
}
.filter-col { min-width: 0; }
.filter-col .field-label { margin-bottom: 6px; }
.search-go-btn {
  width: 100%;
  height: 48px;
  min-height: 48px;
}
@media (min-width: 768px) { .search-go-btn { width: auto; min-width: 120px; } }

.cat-chips { display: flex; gap: 6px; flex-wrap: wrap; min-height: 48px; align-items: center; }

.search-meta {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-faint);
  letter-spacing: 0.02em;
  margin: var(--s-2) 0 var(--s-4);
}

.search-results {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-4);
}
@media (min-width: 768px) {
  .search-results { grid-template-columns: 1fr 1fr; gap: var(--s-5); }
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  cursor: pointer;
  transition: all var(--t-fast);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.result-card:hover {
  border-color: var(--ink);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.result-card:focus-visible {
  outline: 2px solid var(--olive);
  outline-offset: 2px;
}
.result-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--s-3);
}
.result-card-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.012em;
  margin: 0 0 4px;
  color: var(--ink);
}
.result-card-meta {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-mute);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.result-card-meta .dot { color: var(--line-strong); }
.result-card-body {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink-soft);
  line-height: 1.45;
}
.result-card-body .kicker {
  display: block;
  margin-bottom: 2px;
  color: var(--ink-faint);
  font-size: 10px;
}
.result-card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-mute);
  border-top: 1px solid var(--line-soft);
  padding-top: var(--s-3);
}
.result-card-arrow { color: var(--olive); font-weight: 500; }

/* Detail modal */
.modal-detail { max-width: 720px; padding: 0; overflow: hidden; max-height: 88vh; display: flex; flex-direction: column; }
.detail-modal-head {
  position: relative;
  padding: var(--s-6) var(--s-6) var(--s-5);
  background: var(--paper-soft);
  border-bottom: 1px solid var(--line-soft);
}
.detail-modal-head::after {
  content: '';
  position: absolute;
  left: var(--s-6); bottom: -1px;
  width: 40px; height: 2px;
  background: var(--olive);
}
.detail-modal-head .modal-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 500;
  letter-spacing: -0.014em;
  margin: var(--s-2) 0 0;
  padding-right: var(--s-7);
}
.detail-modal-sub {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-mute);
  letter-spacing: 0.02em;
  margin: var(--s-2) 0 0;
  padding-right: var(--s-7);
}
.detail-close {
  position: absolute;
  top: var(--s-4); right: var(--s-4);
}
.detail-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-5) var(--s-6);
}
.detail-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-6);
  background: var(--paper-soft);
  border-top: 1px solid var(--line-soft);
}

.detail-section { margin-bottom: var(--s-6); }
.detail-section:last-child { margin-bottom: 0; }
.detail-section .kicker { display: block; margin-bottom: var(--s-3); }

.detail-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-md);
}
.detail-list li { padding: 4px 0; }

.detail-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
}
.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}
.detail-table th, .detail-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.detail-table th {
  background: var(--paper-soft);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
}
.detail-table tr:last-child td { border-bottom: none; }
.detail-table tr:hover td { background: var(--paper-soft); }

.detail-safety {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.55;
}
.detail-safety strong {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--olive);
  display: inline-block;
  margin-right: 4px;
}

.detail-dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--s-3) var(--s-5);
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-md);
}
.detail-dl dt {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--olive);
  align-self: baseline;
}
.detail-dl dd { margin: 0; color: var(--ink); }

.detail-disclaimer {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-faint);
  font-style: italic;
  margin-top: var(--s-6);
  padding-top: var(--s-4);
  border-top: 1px solid var(--line-soft);
}



/* ─── Detail modal — rich phyto/fert components ───────────────────────────── */
.detail-meta-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-2);
  margin: 0 0 var(--s-6);
  padding: var(--s-4);
  background: var(--paper-soft);
  border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
}
@media (min-width: 640px) {
  .detail-meta-row { grid-template-columns: repeat(4, 1fr); }
}
.detail-meta-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.detail-meta-item.warn .detail-meta-value { color: var(--terracotta); }
.detail-meta-label {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.detail-meta-value {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.label-card {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-4);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--olive);
  border-radius: var(--r-md);
}
.label-card-icon {
  flex: 0 0 48px;
  width: 48px; height: 48px;
  border-radius: var(--r-md);
  background: var(--olive-tint);
  color: var(--olive-deep);
  display: flex;
  align-items: center;
  justify-content: center;
}
.label-card-body { flex: 1; min-width: 0; }
.label-card-title {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 2px;
}
.label-card-sub {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-style: italic;
  color: var(--ink-mute);
  line-height: 1.4;
}
.label-card-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }
@media (max-width: 640px) {
  .label-card { flex-wrap: wrap; }
  .label-card-actions { width: 100%; }
  .label-card-actions .btn { flex: 1; justify-content: center; }
}

.label-preview-wrap {
  margin-top: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--paper-soft);
  overflow: hidden;
  position: relative;
}
.label-preview-iframe {
  width: 100%;
  height: 520px;
  border: 0;
  display: block;
  background: white;
}
@media (max-width: 640px) { .label-preview-iframe { height: 360px; } }
.label-preview-fallback {
  position: absolute;
  bottom: var(--s-3);
  right: var(--s-3);
  background: var(--bg-card);
}

.sostanze-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}
.sostanze-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s-4);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--font-body);
}
.sostanze-list li:last-child { border-bottom: none; }
.sostanza-nome {
  font-size: var(--text-md);
  color: var(--ink);
  font-weight: 500;
}
.sostanza-conc {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
}

.impieghi-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.impiego-item {
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: var(--s-4);
}
.impiego-head {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--line-soft);
}
@media (min-width: 640px) {
  .impiego-head { grid-template-columns: 1fr 1.6fr; }
}
.impiego-col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.impiego-col-wide { min-width: 0; }
.impiego-label-tiny {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: block;
  margin-bottom: 2px;
}
.impiego-value {
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--ink);
  line-height: 1.4;
}
.impiego-value-strong { font-weight: 500; font-variant-numeric: tabular-nums; }
.impiego-value-mono { font-family: var(--font-mono); font-size: var(--text-sm); }
.impiego-value-prose {
  font-size: var(--text-sm);
  color: var(--ink-soft);
  line-height: 1.55;
  font-style: italic;
}
.impiego-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-3);
}
@media (min-width: 640px) {
  .impiego-grid { grid-template-columns: repeat(4, 1fr); }
}
.impiego-extra {
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px dashed var(--line-soft);
}

.safety-row {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--font-body);
}
.safety-row:last-child { border-bottom: none; }
.safety-row > strong {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--olive);
}
.safety-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink);
  line-height: 1.55;
}
.safety-list li {
  padding: 4px 0 4px 14px;
  position: relative;
}
.safety-list li::before {
  content: '·';
  position: absolute;
  left: 4px;
  color: var(--olive);
  font-weight: 700;
}
.safety-list-collapsible li:nth-child(n+7) { display: none; }
.safety-list-collapsible.expanded li:nth-child(n+7) { display: list-item; }
.safety-toggle {
  margin-top: var(--s-2);
  padding: 4px 10px !important;
  min-height: 28px !important;
  font-size: 11px !important;
}

/* ─── Product links in chat ─────────────────────────────────────────────── */
a.product-link {
  display: inline;
  color: var(--olive);
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px dashed var(--olive-soft);
  cursor: pointer;
  transition: all var(--t-fast);
  padding: 0 1px;
  border-radius: 2px;
}
a.product-link:hover {
  color: var(--olive-deep);
  background: var(--olive-tint);
  border-bottom-style: solid;
  border-bottom-color: var(--olive-deep);
}
a.product-link:focus-visible {
  outline: 2px solid var(--olive);
  outline-offset: 2px;
}
a.product-link::after {
  content: '↗';
  font-size: 0.8em;
  margin-left: 2px;
  opacity: 0.6;
  vertical-align: super;
}

/* ─── Sidebar (cronologia "I tuoi casi") ──────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 280px;
  background: var(--bg-card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 80;
  transition: transform var(--t-base);
  padding-top: var(--safe-top);
  overflow: hidden;
}
.sidebar.collapsed {
  transform: translateX(-280px);
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-4) var(--s-5);
  height: var(--header-h);
  border-bottom: 1px solid var(--line-soft);
}
.sidebar-head .brand {
  font-size: 22px;
  letter-spacing: -0.022em;
}
.sidebar-close {
  display: none;
  width: 32px; height: 32px;
  border-radius: var(--r-full);
  color: var(--ink-mute);
  align-items: center;
  justify-content: center;
}
.sidebar-close:hover { background: var(--paper-soft); color: var(--ink); }

.sidebar-new {
  margin: var(--s-4) var(--s-5);
  padding: 11px 14px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: transparent;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  transition: all var(--t-fast);
}
.sidebar-new:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.sidebar-new svg { flex-shrink: 0; }

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--s-2) var(--s-6);
  -webkit-overflow-scrolling: touch;
}
.sidebar-section-title {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: var(--s-3) var(--s-4) var(--s-2);
  margin: 0;
}
.sidebar-group-label {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  padding: var(--s-3) var(--s-4) var(--s-1);
  margin: 0;
  font-weight: 500;
}

.sidebar-case-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px var(--s-4);
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.35;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--t-fast);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-case-item:hover {
  background: var(--paper-soft);
}
.sidebar-case-item.active {
  background: var(--olive-tint);
  color: var(--olive-deep);
  font-weight: 500;
}
.sidebar-case-item.pinned::before {
  content: '★';
  color: var(--gold);
  margin-right: 4px;
}
.sidebar-cases-empty {
  padding: var(--s-6) var(--s-4);
  text-align: center;
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink-faint);
  font-size: var(--text-sm);
}

.sidebar-foot {
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-mute);
}
.sidebar-foot-avatar {
  width: 32px; height: 32px;
  border-radius: var(--r-full);
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}
.sidebar-foot-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-weight: 500; }

/* Sidebar toggle button (desktop edge) */
.sidebar-toggle-edge {
  position: fixed;
  top: 14px;
  left: 12px;
  z-index: 85;
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  background: rgba(255,252,244,0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  color: var(--ink-mute);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: left var(--t-base), background var(--t-fast);
  box-shadow: var(--shadow-xs);
}
.sidebar-toggle-edge:hover { background: var(--bg-card); color: var(--ink); }

/* When sidebar open on desktop, push the toggle to the sidebar edge.
   Confinato a desktop: su mobile body non ha mai `.sidebar-collapsed`
   (il JS la gestisce solo >=768px), quindi senza la media il toggle
   resterebbe sempre a left:232px anche su smartphone. */
@media (min-width: 768px) {
  body:not(.sidebar-collapsed) .sidebar-toggle-edge { left: 232px; }
}

/* Sidebar backdrop (mobile) */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31,36,25,0.4);
  backdrop-filter: blur(4px);
  z-index: 79;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.sidebar-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* Main content offset when sidebar visible (desktop)
   Strategy: SHIFT the visual center via transform — content keeps its
   natural width (max-content = 720px). Only on viewports wide enough
   to host both sidebar (280) + content (720) + breathing room. */
@media (min-width: 1080px) {
  /* .chat-bar lives inside #chatView and inherits its translate — do not
     transform it separately or it shifts 280px (double). */
  .site-header, #heroView, #chatView {
    transition: transform var(--t-base);
  }
  body:not(.sidebar-collapsed) .site-header,
  body:not(.sidebar-collapsed) #heroView,
  body:not(.sidebar-collapsed) #chatView {
    transform: translateX(140px);
  }
}
@media (min-width: 768px) {
  body.sidebar-collapsed .sidebar-toggle-edge { left: 12px; }
}
/* Below 1080px on desktop the sidebar overlays without shifting content */
@media (min-width: 768px) and (max-width: 1079px) {
  .sidebar { box-shadow: var(--shadow-md); }
}

/* Mobile: sidebar is overlay slide-in */
@media (max-width: 767px) {
  .sidebar {
    width: 84%;
    max-width: 320px;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.collapsed { transform: translateX(-100%); }
  .sidebar-close { display: flex; }
  .sidebar-toggle-edge {
    top: 12px;
    left: 12px;
    width: 40px; height: 40px;
  }
  /* Mobile: quando la sidebar è aperta nascondi l'hamburger (la X dentro la
     sidebar gestisce la chiusura) — evita sovrapposizione visiva. */
  body:has(.sidebar.open) .sidebar-toggle-edge { display: none; }
  /* No padding-left on mobile main */
  body .site-header, body #heroView, body #chatView, body .chat-bar { padding-left: 0; }
}

/* Sidebar case row with hover-revealed delete button */
.sidebar-case-row {
  display: flex;
  align-items: center;
  gap: 2px;
  margin: 0 var(--s-2);
  border-radius: var(--r-md);
  position: relative;
}
.sidebar-case-row .sidebar-case-item {
  margin: 0;
  flex: 1;
  min-width: 0;
  border-radius: var(--r-md) 0 0 var(--r-md);
}
.sidebar-case-del {
  flex-shrink: 0;
  width: 28px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  background: transparent;
  border-radius: 0 var(--r-md) var(--r-md) 0;
  opacity: 0;
  transition: opacity var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.sidebar-case-row:hover .sidebar-case-del,
.sidebar-case-del:focus-visible { opacity: 1; }
.sidebar-case-del:hover { background: var(--terracotta-tint); color: var(--terracotta); }
@media (max-width: 767px) {
  /* Always visible on mobile (no hover) */
  .sidebar-case-del { opacity: 0.6; }
}

/* ─── Confirm modal (delete case, themed) ────────────────────────────────── */
.modal-confirm { max-width: 480px; padding: 0; overflow: hidden; }
.confirm-modal-head {
  padding: var(--s-6) var(--s-6) var(--s-5);
  background: var(--terracotta-tint);
  border-bottom: 1px solid var(--line-soft);
  position: relative;
}
.confirm-modal-head::after {
  content: '';
  position: absolute;
  left: var(--s-6); bottom: -1px;
  width: 40px; height: 2px;
  background: var(--terracotta);
}
.confirm-modal-head .kicker { display: block; margin-bottom: var(--s-2); }
.confirm-modal-head .modal-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 500;
  letter-spacing: -0.014em;
  color: var(--ink);
  margin: 0;
}
.confirm-modal-tagline {
  font-family: var(--font-body);
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--ink-mute);
  margin: var(--s-2) 0 0;
  line-height: 1.5;
}
.confirm-modal-body { padding: var(--s-5) var(--s-6); }
.confirm-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-6);
  background: var(--paper-soft);
  border-top: 1px solid var(--line-soft);
}
.confirm-case-preview {
  background: var(--bg-card);
  border-left: 3px solid var(--terracotta);
  padding: var(--s-3) var(--s-4);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink);
}
.confirm-case-preview .case-preview-label {
  display: block;
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--terracotta-deep);
  margin-bottom: 4px;
}
.confirm-case-preview .case-preview-text {
  font-style: italic;
  display: block;
}
