/* Design tokens synced 1:1 with scriba-next (app/globals.css) */
:root {
  --background: hsl(0 0% 100%);
  --foreground: hsl(240 10% 3.9%);
  --card: hsl(0 0% 100%);
  --card-foreground: hsl(240 10% 3.9%);
  --popover: hsl(0 0% 100%);
  --popover-foreground: hsl(240 10% 3.9%);
  --primary: hsl(240 5.9% 10%);
  --primary-foreground: hsl(0 0% 98%);
  --secondary: hsl(240 4.8% 95.9%);
  --secondary-foreground: hsl(240 5.9% 10%);
  --muted: hsl(240 4.8% 95.9%);
  --muted-foreground: hsl(240 3.8% 46.1%);
  --accent: hsl(240 4.8% 95.9%);
  --accent-foreground: hsl(240 5.9% 10%);
  --destructive: hsl(0 84.2% 60.2%);
  --destructive-foreground: hsl(0 0% 98%);
  --border: hsl(240 5.9% 90%);
  --input: hsl(240 5.9% 90%);
  --ring: hsl(240 10% 3.9%);
  --radius: 0.5rem;
  --sidebar: hsl(0 0% 98%);
  --sidebar-foreground: hsl(240 5.3% 26.1%);
  --sidebar-accent: hsl(240 4.8% 95.9%);
  --sidebar-accent-foreground: hsl(240 5.9% 10%);
  --sidebar-border: hsl(220 13% 91%);
  --brand: hsl(215 100% 50%);
  --brand-foreground: hsl(0 0% 100%);
  --success: hsl(142 71% 45%);
  --warning: hsl(38 92% 50%);
  --orange: hsl(24 92% 50%);

  --low-bg: hsla(142, 71%, 45%, 0.12);
  --low-fg: hsl(142 71% 32%);
  --mod-bg: hsla(38, 92%, 50%, 0.14);
  --mod-fg: hsl(34 92% 34%);
  --high-bg: hsla(20, 90%, 50%, 0.14);
  --high-fg: hsl(16 82% 40%);
  --vhigh-bg: hsla(0, 84%, 60%, 0.14);
  --vhigh-fg: hsl(0 74% 42%);
  --brand-soft: hsla(215, 100%, 50%, 0.1);
}

.dark {
  --background: hsl(240 10% 3.9%);
  --foreground: hsl(0 0% 98%);
  --card: hsl(240 10% 5.4%);
  --card-foreground: hsl(0 0% 98%);
  --popover: hsl(240 10% 5.4%);
  --popover-foreground: hsl(0 0% 98%);
  --primary: hsl(0 0% 98%);
  --primary-foreground: hsl(240 5.9% 10%);
  --secondary: hsl(240 3.7% 15.9%);
  --secondary-foreground: hsl(0 0% 98%);
  --muted: hsl(240 3.7% 15.9%);
  --muted-foreground: hsl(240 5% 64.9%);
  --accent: hsl(240 3.7% 15.9%);
  --accent-foreground: hsl(0 0% 98%);
  --destructive: hsl(0 72% 51%);
  --destructive-foreground: hsl(0 0% 98%);
  --border: hsl(240 3.7% 15.9%);
  --input: hsl(240 3.7% 15.9%);
  --ring: hsl(240 4.9% 83.9%);
  --sidebar: hsl(240 5.9% 10%);
  --sidebar-foreground: hsl(240 4.8% 95.9%);
  --sidebar-accent: hsl(240 3.7% 15.9%);
  --sidebar-accent-foreground: hsl(240 4.8% 95.9%);
  --sidebar-border: hsl(240 3.7% 15.9%);
  --brand: hsl(215 100% 55%);
  --brand-foreground: hsl(0 0% 100%);
  --success: hsl(142 69% 58%);
  --warning: hsl(38 95% 60%);
  --orange: hsl(24 95% 60%);

  --low-bg: hsla(142, 69%, 58%, 0.14);
  --low-fg: hsl(142 69% 65%);
  --mod-bg: hsla(38, 95%, 60%, 0.14);
  --mod-fg: hsl(38 95% 66%);
  --high-bg: hsla(20, 95%, 60%, 0.16);
  --high-fg: hsl(20 95% 68%);
  --vhigh-bg: hsla(0, 84%, 60%, 0.16);
  --vhigh-fg: hsl(0 88% 72%);
  --brand-soft: hsla(215, 100%, 55%, 0.14);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border-color: var(--border);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--background);
  color: var(--foreground);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

code, pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

/* macOS overlay scrollbar from scriba-next */
::-webkit-scrollbar { width: 8px; height: 8px; background: transparent; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background-color: transparent;
  background-clip: padding-box;
  border: 2px solid transparent;
  border-radius: 9999px;
  transition: background-color 0.25s ease;
}
*:hover::-webkit-scrollbar-thumb { background-color: rgba(0, 0, 0, 0.22); }
.dark *:hover::-webkit-scrollbar-thumb { background-color: rgba(255, 255, 255, 0.2); }
*:hover::-webkit-scrollbar-thumb:hover { background-color: rgba(0, 0, 0, 0.42); }
.dark *:hover::-webkit-scrollbar-thumb:hover { background-color: rgba(255, 255, 255, 0.38); }

/* ==================== APP SHELL (Sidebar + Main) ==================== */
.app-shell {
  display: flex;
  height: 100svh;
  width: 100vw;
  overflow: hidden;
  background: var(--background);
}

.sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  transition: width 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s ease;
  overflow: hidden;
}
.app-shell.sidebar-collapsed .sidebar {
  width: 0;
  border-right-color: transparent;
}

.sidebar-header {
  padding: 12px 12px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--foreground);
  font-size: 1.06rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.brand-btn:hover { background: var(--sidebar-accent); }
.brand-tier {
  color: var(--brand);
  font-weight: 600;
  font-size: 1.02rem;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--brand-soft);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-foreground);
  padding: 0 8px 6px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--sidebar-foreground);
  font-size: 0.86rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.nav-item:hover {
  background: var(--sidebar-accent);
  color: var(--sidebar-accent-foreground);
}
.nav-item.active {
  background: var(--sidebar-accent);
  color: var(--foreground);
  font-weight: 600;
  border-color: var(--border);
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }
.nav-item.active svg { opacity: 1; color: var(--brand); }
.nav-pill {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--muted);
  color: var(--muted-foreground);
}

.preset-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.preset-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 7px 9px;
  cursor: pointer;
  color: var(--sidebar-foreground);
  transition: all 0.14s ease;
}
.preset-item:hover { background: var(--sidebar-accent); }
.preset-item.active {
  background: var(--sidebar-accent);
  border-color: var(--border);
  color: var(--foreground);
}
.preset-item .pt { font-size: 0.81rem; font-weight: 500; line-height: 1.3; }
.preset-item .ps { font-size: 0.71rem; color: var(--muted-foreground); margin-top: 2px; line-height: 1.25; }

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.llm-status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  background: var(--background);
  border: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--muted-foreground);
  cursor: pointer;
}
.llm-status-pill:hover { border-color: var(--brand); color: var(--foreground); }
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted-foreground);
  flex-shrink: 0;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 0 3px hsla(142, 69%, 58%, 0.2); }
.status-dot.offline { background: var(--warning); }

.footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

/* ==================== MAIN AREA ==================== */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100svh;
  overflow: hidden;
  background: var(--background);
}

.main-header {
  height: 52px;
  flex-shrink: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--background);
}
.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.header-title {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--secondary);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted-foreground);
  white-space: nowrap;
}
.header-meta-pill b { color: var(--foreground); font-weight: 600; }

.main-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.tab-panel { display: none; height: 100%; }
.tab-panel.active { display: block; }

.view-wrap {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 20px 64px;
}

/* ==================== SHADCN BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--foreground);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}
.btn:hover { background: var(--accent); color: var(--accent-foreground); }
.btn svg { width: 15px; height: 15px; }
.btn.icon-only { width: 32px; height: 32px; padding: 0; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--accent); }
.btn.primary {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
  font-weight: 600;
}
.btn.primary:hover { opacity: 0.9; background: var(--primary); color: var(--primary-foreground); }
.btn.brand {
  background: var(--brand);
  color: var(--brand-foreground);
  border-color: var(--brand);
  font-weight: 600;
}
.btn.brand:hover { opacity: 0.92; background: var(--brand); color: var(--brand-foreground); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 0.76rem; }

/* ==================== CALCULATOR GRID ==================== */
.calc-grid {
  display: grid;
  grid-template-columns: minmax(400px, 1.08fr) minmax(400px, 1fr);
  gap: 18px;
  align-items: start;
}
@media (max-width: 1120px) {
  .calc-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  margin-bottom: 14px;
  overflow: hidden;
}
.card-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-head h2 {
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.card-head .sub {
  font-size: 0.75rem;
  color: var(--muted-foreground);
}
.card-body { padding: 14px 16px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px 12px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 0.77rem;
  font-weight: 500;
  color: var(--muted-foreground);
}
.field input[type="number"],
.field input[type="text"],
.field select,
textarea {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--foreground);
  background: var(--background);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
textarea { height: auto; padding: 10px 12px; }
.field input:focus, .field select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-soft);
}
.hint { font-size: 0.76rem; color: var(--muted-foreground); margin-top: 8px; line-height: 1.4; }

.checks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--secondary);
  border: 1px solid var(--border);
  color: var(--foreground);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: all 0.14s ease;
}
.chip:hover { border-color: var(--muted-foreground); }
.chip:has(input:checked) {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--foreground);
}
.chip input { accent-color: var(--brand); width: 14px; height: 14px; }

.divider { border: none; border-top: 1px solid var(--border); margin: 13px 0; }

details.sub-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  margin-top: 10px;
  background: var(--background);
}
details.sub-panel summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 0.84rem;
  color: var(--foreground);
}
.compact-rows {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 8px 12px;
  margin-top: 10px;
}

/* ==================== RESULTS DASHBOARD ==================== */
.sticky-col { position: sticky; top: 14px; }
@media (max-width: 1120px) { .sticky-col { position: static; } }

.warnings-box { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.warn {
  border-radius: var(--radius);
  padding: 10px 13px;
  font-size: 0.82rem;
  border: 1px solid;
  line-height: 1.45;
}
.warn.critical { background: var(--vhigh-bg); border-color: hsla(0, 84%, 60%, 0.45); color: var(--vhigh-fg); }
.warn.warning { background: var(--mod-bg); border-color: hsla(38, 92%, 50%, 0.45); color: var(--mod-fg); }
.warn.info { background: var(--brand-soft); border-color: hsla(215, 100%, 55%, 0.35); color: var(--foreground); }
.warn b { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 3px; font-weight: 600; }

.subindex-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
@media (max-width: 640px) { .subindex-grid { grid-template-columns: 1fr; } }

.si-card {
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  padding: 12px 14px;
  background: var(--card);
  position: relative;
  overflow: hidden;
}
.si-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--border);
}
.si-card.low::before { background: var(--success); }
.si-card.moderate::before { background: var(--warning); }
.si-card.high::before { background: var(--orange); }
.si-card.very_high::before { background: var(--destructive); }

.si-title {
  font-size: 0.71rem;
  color: var(--muted-foreground);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.si-val {
  font-size: 0.98rem;
  font-weight: 600;
  margin: 5px 0 4px;
  letter-spacing: -0.01em;
}
.si-rec { font-size: 0.78rem; color: var(--muted-foreground); line-height: 1.4; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.low { background: var(--low-bg); color: var(--low-fg); }
.badge.moderate { background: var(--mod-bg); color: var(--mod-fg); }
.badge.high { background: var(--high-bg); color: var(--high-fg); }
.badge.very_high { background: var(--vhigh-bg); color: var(--vhigh-fg); }
.badge.kb {
  background: var(--secondary);
  color: var(--foreground);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.14s ease;
}
.badge.kb:hover { background: var(--brand); color: #fff; border-color: var(--brand); }

table.scales-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
table.scales-table th, table.scales-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}
table.scales-table tr:last-child td { border-bottom: none; }
table.scales-table th {
  font-size: 0.72rem;
  color: var(--muted-foreground);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-box {
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.84rem;
  line-height: 1.55;
}
.rec-list { margin: 8px 0 0 18px; font-size: 0.82rem; color: var(--foreground); }
.rec-list li { margin-bottom: 5px; line-height: 1.45; }
.mod-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.mod-tag {
  background: var(--high-bg);
  color: var(--high-fg);
  border: 1px solid hsla(20, 90%, 50%, 0.3);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ==================== SCRIBA-STYLE RAG CHAT ==================== */
.rag-shell {
  display: flex;
  flex-direction: column;
  height: calc(100svh - 52px);
  max-width: 920px;
  margin: 0 auto;
  padding: 0 16px;
}

.rag-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.rag-toolbar select, .rag-toolbar input[type="text"] {
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: var(--background);
  color: var(--foreground);
  font-size: 0.8rem;
}

.chat-feed {
  flex: 1;
  overflow-y: auto;
  padding: 20px 2px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.greeting-box {
  margin: 28px 0 10px;
}
.greeting-box h2 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.greeting-box p {
  font-size: 1.08rem;
  color: var(--muted-foreground);
  margin-top: 2px;
}

.suggested-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}
@media (max-width: 720px) { .suggested-grid { grid-template-columns: 1fr; } }
.suggested-card {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 0.82rem;
  color: var(--foreground);
  cursor: pointer;
  line-height: 1.38;
  transition: background 0.14s ease, border-color 0.14s ease;
}
.suggested-card:hover { background: var(--accent); border-color: var(--muted-foreground); }

.msg-row { display: flex; gap: 12px; align-items: flex-start; }
.msg-row.user { justify-content: flex-end; }
.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--foreground);
}
.msg-bubble {
  font-size: 0.9rem;
  line-height: 1.6;
  max-width: 100%;
}
.msg-row.user .msg-bubble {
  background: var(--primary);
  color: var(--primary-foreground);
  padding: 10px 15px;
  border-radius: 18px;
  max-width: 80%;
}
.msg-row.bot .msg-bubble {
  flex: 1;
  min-width: 0;
}
.msg-answer p { margin-bottom: 8px; }
.msg-answer ul, .msg-answer ol { margin: 6px 0 8px 20px; }
.msg-answer li { margin-bottom: 4px; }

.inline-cite {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  margin: 0 2px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--secondary);
  border: 1px solid var(--border);
  color: var(--brand);
  cursor: pointer;
  vertical-align: baseline;
}
.inline-cite:hover { background: var(--brand); color: #fff; border-color: var(--brand); }

.sources-collapse {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  padding: 8px 12px;
}
.sources-collapse summary {
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted-foreground);
}
.cite-cards { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.cite-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.79rem;
  background: var(--background);
}

.composer-wrap {
  padding: 10px 0 18px;
}
.composer {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.14s ease;
}
.composer:focus-within { border-color: var(--brand); }
.composer textarea {
  border: none;
  background: transparent;
  padding: 2px 4px;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  font-size: 0.9rem;
  box-shadow: none !important;
}
.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ==================== KB & PRINT TAB ==================== */
.forms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 10px;
}
.form-tile {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}
.form-tile h4 { font-size: 0.86rem; font-weight: 600; line-height: 1.35; }
.form-tile .dom { font-size: 0.73rem; color: var(--muted-foreground); margin-bottom: 3px; }

.kb-grid {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 14px;
  align-items: start;
}
@media (max-width: 960px) { .kb-grid { grid-template-columns: 1fr; } }
.kb-list { display: flex; flex-direction: column; gap: 5px; }
.kb-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 11px;
  background: var(--background);
  cursor: pointer;
  transition: all 0.14s ease;
}
.kb-item:hover, .kb-item.active { background: var(--accent); border-color: var(--brand); }
.kb-item .id { font-size: 0.71rem; font-weight: 600; color: var(--brand); }
.kb-item .t { font-size: 0.84rem; font-weight: 500; margin-top: 2px; }
.md-body { font-size: 0.87rem; line-height: 1.62; white-space: pre-wrap; color: var(--foreground); }

/* Sonner-style toast */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--primary);
  color: var(--primary-foreground);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 0.83rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 90;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 860px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; }
  .app-shell.sidebar-collapsed .sidebar { transform: translateX(-100%); width: 268px; }
  .header-meta-pill { display: none; }
}

@media print {
  html, body, .app-shell, .main-area, .main-scroll {
    height: auto !important;
    overflow: visible !important;
    background: #ffffff !important;
    color: #111111 !important;
  }
  .sidebar, .main-header, .no-print, .input-col, #tab-kb, #tab-rag, #toast { display: none !important; }
  .view-wrap { padding: 0; max-width: none; }
  .calc-grid { display: block; }
  .sticky-col { position: static; }
  .card, .si-card, .summary-box {
    background: #ffffff !important;
    color: #111111 !important;
    border-color: #d4d4d8 !important;
    break-inside: avoid;
  }
}
