:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1e293b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --info: #0284c7;
  --info-bg: #f0f9ff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; overflow-x: clip; -webkit-text-size-adjust: 100%; }
body.nav-open { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
button, a, input, select, textarea, summary { touch-action: manipulation; }

/* App Shell */
.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar-backdrop { display: none; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sidebar-brand { padding: 20px 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-brand-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sidebar-brand h1 { margin: 0; font-size: 20px; font-weight: 700; color: #fff; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.sidebar-brand span.sub { display: block; font-size: 11px; color: #94a3b8; margin-top: 2px; }
.sidebar-close { display: none; background: transparent; border: 1px solid rgba(255,255,255,0.18); color: #cbd5e1; width: 34px; height: 34px; border-radius: 7px; font-size: 22px; line-height: 1; cursor: pointer; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-close:hover { color: #fff; border-color: rgba(255,255,255,0.4); }
.nav-section { padding: 14px 12px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #64748b; font-weight: 600; }
.nav-list { list-style: none; margin: 0; padding: 0 8px; }
.nav-list a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 7px; color: var(--sidebar-text); font-weight: 500; font-size: 13.5px; transition: background 0.12s, color 0.12s; }
.nav-list a:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.nav-list a.active { background: var(--primary); color: #fff; }
.sidebar-footer { margin-top: auto; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 12.5px; }
.sidebar-footer .user-name { color: #fff; font-weight: 600; display: block; }
.sidebar-footer .user-role { color: #94a3b8; font-size: 11px; text-transform: uppercase; }
.sidebar-footer-actions { display: flex; gap: 10px; margin-top: 10px; align-items: center; }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 28px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.topbar h2 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-toggle { display: none; background: #fff; border: 1px solid #cbd5e1; color: var(--text); width: 38px; height: 38px; border-radius: 8px; cursor: pointer; align-items: center; justify-content: center; flex-shrink: 0; padding: 0; }
.menu-toggle:hover { background: #f8fafc; }
.show-xs { display: none; }
.content { padding: 24px 28px 40px; max-width: 1440px; width: 100%; }

/* Auth Layout */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); }
.auth-card { background: var(--surface); width: 100%; max-width: 440px; border-radius: 14px; padding: 32px; box-shadow: 0 20px 45px rgba(0,0,0,0.3); }
.auth-card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 700; }
.auth-card .muted { color: var(--muted); margin-bottom: 22px; }

/* Cards & Grids */
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 20px; }
.grid-4 > *, .grid-3 > *, .grid-2 > *, .form-grid > * { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  background:
    linear-gradient(to right, #fff 30%, rgba(255, 255, 255, 0)),
    linear-gradient(to right, rgba(255, 255, 255, 0), #fff 70%) 0 100%,
    radial-gradient(farthest-side at 0 50%, rgba(15, 23, 42, 0.11), rgba(15, 23, 42, 0)),
    radial-gradient(farthest-side at 100% 50%, rgba(15, 23, 42, 0.11), rgba(15, 23, 42, 0)) 0 100%;
  background-repeat: no-repeat;
  background-color: #fff;
  background-size: 32px 100%, 32px 100%, 10px 100%, 10px 100%;
  background-position: 0 0, 100% 0, 0 0, 100% 0;
  background-attachment: local, local, scroll, scroll;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv-table th { white-space: normal; width: 150px; }
.kv-table td { overflow-wrap: anywhere; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--border); background: var(--surface-alt); white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; transition: color 0.12s, background 0.12s; }
th.sortable:hover { color: var(--text); background: #f1f5f9; }
th.sortable::after { content: ' ⇅'; font-size: 10px; opacity: 0.35; margin-left: 3px; }
th.sortable:hover::after { opacity: 0.7; }
th.sortable.sort-asc, th.sortable.sort-desc { color: var(--primary); }
th.sortable.sort-asc::after { content: ' ▲'; opacity: 1; }
th.sortable.sort-desc::after { content: ' ▼'; opacity: 1; }
td { padding: 9px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tr:hover td { background: #f8fafc; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--success); font-weight: 600; }
.neg { color: var(--danger); font-weight: 600; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 12px; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #e2e8f0; color: #334155; white-space: nowrap; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-slate { background: #f1f5f9; color: #475569; }

/* Forms & Buttons */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; font-weight: 600; color: #334155; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="file"], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 7px; font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; border: 1px solid transparent; cursor: pointer; transition: background 0.12s; text-decoration: none; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #fff; color: var(--text); border-color: #cbd5e1; }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-ghost { background: transparent; color: #94a3b8; border: 1px solid rgba(255,255,255,0.18); padding: 5px 10px; font-size: 12px; }
.btn-ghost:hover { color: #fff; border-color: rgba(255,255,255,0.4); }

/* Filter Bar & Tabs */
.filter-bar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.scope-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.scope-pill { padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; border: 1px solid var(--border); background: #fff; color: #334155; }
.scope-pill:hover { background: #f1f5f9; text-decoration: none; }
.scope-pill.active { background: var(--sidebar-bg); color: #fff; border-color: var(--sidebar-bg); }

/* Flashes */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; font-weight: 500; border: 1px solid transparent; }
.flash-success { background: var(--success-bg); color: #065f46; border-color: #a7f3d0; }
.flash-error { background: var(--danger-bg); color: #991b1b; border-color: #fecaca; }
.flash-warning { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }
.flash-info { background: var(--info-bg); color: #075985; border-color: #bae6fd; }

/* Charts (Zero-dep crisp SVG/CSS) */
.bar-row { margin-bottom: 10px; }
.bar-meta { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 3px; }
.bar-track { height: 9px; background: #f1f5f9; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut-legend { flex: 1; min-width: 180px; }
.legend-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; padding: 3px 0; }
.legend-left { display: flex; align-items: center; gap: 8px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* Collapsible Form Panels */
details.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 18px; box-shadow: var(--shadow); }
details.panel summary { padding: 13px 18px; cursor: pointer; font-weight: 600; font-size: 14px; list-style: none; display: flex; align-items: center; justify-content: space-between; }
details.panel summary::-webkit-details-marker { display: none; }
details.panel[open] summary { border-bottom: 1px solid var(--border); }
details.panel .panel-body { padding: 16px 18px; }

.recovery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 16px 0; }
.recovery-code { font-family: ui-monospace, monospace; font-size: 15px; font-weight: 700; text-align: center; padding: 10px; background: #f8fafc; border: 1px dashed #94a3b8; border-radius: 6px; letter-spacing: 0.08em; }

/* External Research Links */
.ext-links { display: flex; flex-wrap: wrap; gap: 6px; }
.ext-pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f8fafc; color: #1e40af; border: 1px solid #cbd5e1; text-decoration: none; transition: background 0.12s, border-color 0.12s, color 0.12s; }
.ext-pill:hover { background: #eff6ff; border-color: #93c5fd; color: #1d4ed8; text-decoration: none; }
.ext-mini-wrap { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; font-family: inherit; }
.ext-mini { display: inline-block; padding: 1px 5px; border-radius: 4px; font-size: 10.5px; font-weight: 600; background: #f1f5f9; color: #334155; border: 1px solid #e2e8f0; text-decoration: none; line-height: 1.35; transition: background 0.12s, border-color 0.12s, color 0.12s; }
.ext-mini:hover { background: #dbeafe; border-color: #93c5fd; color: #1d4ed8; text-decoration: none; }

/* Staging Banner */
.staging-banner {
  background: #b45309;
  color: #fff;
  text-align: center;
  padding: 6px 14px;
  font-size: 12px;
  line-height: 1.4;
  position: sticky;
  top: 0;
  z-index: 1100;
}
.staging-banner code { background: rgba(255,255,255,0.18); padding: 1px 5px; border-radius: 4px; color: #fff; font-size: 11.5px; }

/* Lolly AI Chat & Audit */
.lolly-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.lolly-sidebar { padding: 14px; margin-bottom: 0; position: sticky; top: 16px; max-height: calc(100vh - 110px); display: flex; flex-direction: column; }
.lolly-sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.lolly-conv-list { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.lolly-conv-item { display: flex; align-items: center; gap: 4px; border-radius: 7px; border: 1px solid transparent; transition: background 0.12s, border-color 0.12s; }
.lolly-conv-item:hover { background: #f8fafc; }
.lolly-conv-item.active { background: #eff6ff; border-color: #bfdbfe; }
.lolly-conv-link { flex: 1; min-width: 0; padding: 8px 9px; color: var(--text); text-decoration: none; display: block; }
.lolly-conv-link:hover { text-decoration: none; }
.lolly-conv-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lolly-conv-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.lolly-conv-del { background: transparent; border: none; color: #94a3b8; cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 5px; line-height: 1; }
.lolly-conv-del:hover { color: var(--danger); background: #fee2e2; }

.lolly-main { padding: 0; margin-bottom: 0; display: flex; flex-direction: column; min-height: 68vh; }
.lolly-chat-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.lolly-mobile-new, .lolly-mobile-picker { display: none; }
.lolly-mobile-picker { padding: 10px 14px 0; }
.lolly-messages { flex: 1; padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; max-height: 62vh; background: #fafbfc; }
.lolly-welcome { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
.lolly-welcome-title { font-size: 16px; font-weight: 700; color: var(--text); }
.lolly-starters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.lolly-starter-chip { text-align: left; background: #f8fafc; border: 1px solid #cbd5e1; border-radius: 8px; padding: 9px 11px; font-size: 12.5px; color: #1e293b; cursor: pointer; font-family: inherit; line-height: 1.4; transition: background 0.12s, border-color 0.12s; }
.lolly-starter-chip:hover { background: #eff6ff; border-color: #93c5fd; color: #1d4ed8; }

.lolly-msg { border-radius: 10px; padding: 12px 15px; border: 1px solid var(--border); max-width: 100%; }
.lolly-msg-user { background: #eff6ff; border-color: #bfdbfe; align-self: flex-end; width: min(86%, 720px); }
.lolly-msg-assistant { background: #fff; align-self: flex-start; width: 100%; }
.lolly-msg-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; margin-bottom: 6px; }
.lolly-msg-body { font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.lolly-msg-body p { margin: 0 0 8px; }
.lolly-msg-body p:last-child { margin-bottom: 0; }
.lolly-msg-body h2, .lolly-msg-body h3, .lolly-msg-body h4 { margin: 12px 0 6px; font-size: 14.5px; }
.lolly-msg-body ul, .lolly-msg-body ol { margin: 4px 0 8px; padding-left: 20px; }
.lolly-msg-body li { margin-bottom: 3px; }
.lolly-msg-body blockquote { margin: 6px 0; padding: 6px 12px; border-left: 3px solid #cbd5e1; background: #f8fafc; color: #475569; border-radius: 0 6px 6px 0; }
.lolly-msg-body code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.lolly-code { background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: 7px; overflow-x: auto; font-size: 12px; line-height: 1.45; }
.lolly-code code { background: transparent; color: inherit; padding: 0; }
.lolly-md-table { margin: 8px 0; }

.lolly-att-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.lolly-att-chip { display: inline-flex; align-items: center; gap: 5px; background: #fff; border: 1px solid #cbd5e1; border-radius: 6px; padding: 3px 8px; font-size: 12px; font-weight: 500; }

.lolly-tools-box { margin-top: 8px; font-size: 12px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 7px; padding: 6px 10px; }
.lolly-tools-box summary { cursor: pointer; font-weight: 600; color: #475569; }
.lolly-tools-list { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.lolly-tool-row { font-size: 11.5px; display: flex; gap: 6px; flex-wrap: wrap; align-items: baseline; }

.lolly-proposal { margin-top: 12px; border-radius: 9px; padding: 12px 14px; border: 1px solid #cbd5e1; background: #f8fafc; }
.lolly-proposal-pending { border-color: #93c5fd; background: #f0f7ff; }
.lolly-proposal-applied { border-color: #a7f3d0; background: #ecfdf5; }
.lolly-proposal-rejected { border-color: #e2e8f0; background: #f8fafc; opacity: 0.8; }
.lolly-proposal-failed { border-color: #fecaca; background: #fef2f2; }
.lolly-proposal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.lolly-proposal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.lolly-csv-stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; padding: 7px 10px; background: #fff; border: 1px solid #e2e8f0; border-radius: 6px; margin-bottom: 8px; }

.lolly-composer { padding: 12px 16px; border-top: 1px solid var(--border); background: #fff; border-radius: 0 0 var(--radius) var(--radius); }
.lolly-dropzone { border: 1px solid #cbd5e1; border-radius: 8px; padding: 6px; background: #fff; transition: border-color 0.12s, background 0.12s; }
.lolly-dropzone.dragover { border-color: var(--primary); background: #eff6ff; border-style: dashed; }
.lolly-dropzone textarea { border: none; box-shadow: none !important; resize: vertical; min-height: 54px; padding: 4px 6px; }
.lolly-file-preview { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 6px 4px; }
.lolly-file-preview:empty { display: none; }
.lolly-composer-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.lolly-composer-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lolly-model-select { width: auto; min-width: 190px; padding: 5px 9px; font-size: 12.5px; }

.lolly-audit-turn { border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; margin-bottom: 12px; }
.lolly-audit-user { background: #f8fafc; }
.lolly-audit-assistant { background: #fff; }

/* Responsive: Compact desktop & landscape tablet */
@media (max-width: 1200px) {
  .sidebar { width: 216px; }
  .topbar { padding: 12px 20px; }
  .content { padding: 20px 20px 36px; }
}

@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Responsive: Portrait tablet & mobile off-canvas navigation drawer */
@media (max-width: 1023px) {
  .menu-toggle { display: inline-flex; }
  .sidebar-close { display: inline-flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 84vw);
    height: 100vh;
    height: 100dvh;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.45);
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .nav-list a { padding: 11px 12px; font-size: 14.5px; }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  }
  .content { padding: 18px 16px calc(32px + env(safe-area-inset-bottom)); }
}

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .lolly-shell { grid-template-columns: 1fr; }
  .lolly-sidebar { display: none; }
  .lolly-mobile-new, .lolly-mobile-picker { display: block; }
  .lolly-messages { max-height: none; min-height: 260px; }
}

/* Responsive: Small tablet & phone */
@media (max-width: 767px) {
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4, .grid-3, .grid-2 { gap: 12px; margin-bottom: 16px; }
  .content { padding: 14px 12px calc(28px + env(safe-area-inset-bottom)); }
  .card { padding: 14px; margin-bottom: 14px; }
  .card-header { margin-bottom: 12px; gap: 8px; }
  .kpi-card { padding: 13px 14px; }
  .kpi-value { font-size: 21px; }
  details.panel summary { padding: 12px 14px; font-size: 13.5px; }
  details.panel .panel-body { padding: 14px; }

  /* Prevent iOS Safari auto-zoom on form focus & improve touch targets */
  input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="file"], select, textarea {
    font-size: 16px;
    min-height: 40px;
    padding: 8px 10px;
  }
  .btn { min-height: 38px; padding: 8px 13px; }
  .btn-sm { min-height: 34px; padding: 5px 10px; font-size: 12.5px; }
  .scope-pill { padding: 6px 11px; font-size: 12px; }
  .ext-pill { padding: 5px 10px; font-size: 12.5px; }
  .ext-mini { padding: 3px 7px; font-size: 11px; }

  /* Tidy filter bars on mobile */
  .filter-bar { gap: 8px; align-items: stretch; }
  .filter-bar .field { flex: 1 1 calc(50% - 4px); min-width: 135px !important; }
  .filter-bar .field input[type="text"] { width: 100%; }
  .filter-bar .btn { flex: 1 1 auto; }

  /* Compact readable tables */
  table { font-size: 12.5px; }
  th { padding: 8px; font-size: 11px; }
  td { padding: 8px; }
  .kv-table th { width: 112px; font-size: 11px; }
}

/* Responsive: Phone portrait */
@media (max-width: 520px) {
  .topbar { padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); gap: 8px; }
  .topbar h2 { font-size: 16px; }
  .hide-xs { display: none !important; }
  .show-xs { display: inline !important; }
  .grid-4 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; gap: 10px; }
  .donut-wrap { flex-direction: column; align-items: stretch; gap: 14px; }
  .donut-wrap svg { margin: 0 auto; }
  .donut-legend { min-width: 0; }
  .legend-item { gap: 6px; font-size: 12px; }
  .auth-shell { padding: 14px; }
  .auth-card { padding: 22px 18px; border-radius: 12px; }
  .auth-card h1 { font-size: 21px; }
  .lolly-starters { grid-template-columns: 1fr; }
  .lolly-msg-user { width: 100%; }
  .lolly-messages { padding: 12px; }
  .lolly-composer { padding: 10px 12px; }
  .lolly-model-select { width: 100%; min-width: 0; }
  .lolly-composer-bar .btn-primary { width: 100%; }
}

@media (max-width: 380px) {
  .recovery-grid { grid-template-columns: 1fr; }
}
