/* ---------- App frame ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); height: 100vh; height: 100dvh; overflow: hidden; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.workspace { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
.page { max-width: 1320px; margin: 0 auto; padding: 26px 34px 56px; display: grid; gap: 18px; }
.page.full { max-width: none; padding: 0; height: 100%; display: block; }

/* ---------- Sidebar ---------- */
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--bg-2); border-right: 1px solid var(--line); padding: 14px 10px 10px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; }
.brand strong { display: block; font-size: 15px; letter-spacing: 0.06em; line-height: 1.15; }
.brand small { display: block; color: var(--muted); font-size: 11px; }
.brand-mark { position: relative; width: 30px; height: 30px; border-radius: 9px; background: var(--ink); overflow: hidden; flex: none; }
.brand-mark i { position: absolute; border-radius: 50%; }
.brand-mark i:nth-child(1) { inset: 7px; border: 1.6px solid var(--bg); }
.brand-mark i:nth-child(2) { inset: 11px 4px; border: 1.6px solid color-mix(in srgb, var(--bg) 55%, transparent); }
.brand-mark i:nth-child(3) { inset: 12.5px; background: var(--accent); }
.app.busy .brand-mark i:nth-child(2) { animation: orbit 2.4s linear infinite; }
.side-actions { display: flex; gap: 6px; margin: 0 2px 12px; }
.side-search { flex: 1; display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; border-radius: 9px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); font-size: 13px; transition: border-color 0.15s; }
.side-search:hover { border-color: var(--line-2); }
.side-search kbd { margin-left: auto; }
.side-new { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; color: var(--bg); background: var(--ink); transition: transform 0.2s var(--spring), opacity 0.15s; }
.side-new:hover { opacity: 0.88; }
.side-new:active { transform: scale(0.94); }
.side-nav { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.side-group { margin-bottom: 12px; }
.side-label { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; color: var(--faint); padding: 6px 10px 4px; }
.side-nav a { position: relative; display: flex; align-items: center; gap: 9px; height: 33px; padding: 0 9px; border-radius: 8px; color: var(--ink-2); font-size: 13.5px; transition: background 0.15s, color 0.15s; }
.side-nav a:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--ink); }
.side-nav a.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--line), var(--shadow-sm); }
.nav-icon { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 7px; flex: none; color: hsl(var(--nh, 152) 45% 38%); background: hsl(var(--nh, 152) 50% 94%); transition: transform 0.2s var(--spring); }
.side-nav a:hover .nav-icon { transform: scale(1.06); }
.side-nav a.active .nav-icon { color: #fff; background: hsl(var(--nh, 152) 50% 42%); }
.nav-badge { margin-left: auto; min-width: 19px; height: 19px; padding: 0 6px; border-radius: 99px; display: inline-grid; place-items: center; font-size: 11px; font-weight: 650; color: var(--on-accent); background: var(--accent); animation: pop 0.35s var(--spring); }
.nav-badge.warn { background: var(--warn); color: #fff; }
.nav-live { margin-left: auto; }
.side-foot { display: grid; gap: 8px; padding: 10px 4px 2px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }
.side-status { display: grid; grid-template-columns: auto 1fr; gap: 3px 9px; align-items: center; padding: 10px 11px; border-radius: 11px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.side-status b { font-size: 13px; font-weight: 650; }
.side-status small { grid-column: 2; font-size: 11px; color: var(--muted); }
.side-foot .row { justify-content: space-between; padding: 0 4px; }
.side-foot button { color: var(--muted); font-size: 11.5px; }
.side-foot button:hover { color: var(--ink); }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; height: var(--topbar); padding: 0 18px 0 28px; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); flex: none; }
.topbar .menu-btn { display: none; }
.crumb { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 650; font-size: 14px; }
.crumb .nav-icon { width: 26px; height: 26px; color: #fff; background: hsl(var(--nh, 152) 50% 42%); }
.crumb small { font-weight: 450; color: var(--muted); font-size: 12.5px; }
.top-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.conn { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 11px; border-radius: 99px; font-size: 12px; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); white-space: nowrap; }
.conn.err { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); background: var(--bad-soft); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-card { width: min(420px, 100%); padding: 34px 30px 28px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); display: grid; gap: 18px; animation: scale-in 0.5s var(--ease) both; }
.login-card .brand { padding: 0; }
.login-card h1 { font-size: 22px; letter-spacing: -0.02em; }
.login-card p { color: var(--muted); font-size: 13px; }
.login-card .btn { height: 40px; }
.login-foot { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 11.5px; }

/* ---------- Banner, toasts ---------- */
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 11px; font-size: 13px; background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 22%, transparent); animation: rise 0.3s var(--ease) both; }
.banner.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.banner.info { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--accent-line); }
.banner .grow { color: var(--ink-2); }
.toasts { position: fixed; z-index: 90; right: 20px; bottom: 20px; display: grid; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 420px; padding: 11px 14px; border-radius: 12px; font-size: 13px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); animation: toast-in 0.32s var(--spring) both; }
.toast svg { color: var(--accent); }
.toast.bad svg { color: var(--c8); }
.toast.leaving { animation: fade 0.25s reverse both; }

/* ---------- Drawer & scrim ---------- */
.scrim { position: fixed; inset: 0; z-index: 60; background: var(--scrim); animation: fade 0.25s var(--ease) both; }
.drawer { position: fixed; z-index: 61; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); display: flex; flex-direction: column; background: var(--bg); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg); animation: drawer-in 0.36s var(--ease) both; }
.drawer.wide { width: min(720px, 100vw); }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.drawer-head h2 { font-size: 17px; letter-spacing: -0.01em; line-height: 1.35; }
.drawer-head p { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 28px; display: grid; gap: 16px; align-content: start; }
.drawer-foot { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--surface); }
.drawer-foot .grow { color: var(--muted); font-size: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .page { padding: 22px 22px 48px; } }
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 70; top: 0; bottom: 0; left: 0; width: 260px; transform: translateX(-100%); transition: transform 0.28s var(--ease); box-shadow: var(--shadow-lg); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .nav-scrim { display: block; position: fixed; inset: 0; z-index: 65; background: var(--scrim); }
  .topbar { padding: 0 12px; }
  .topbar .menu-btn { display: inline-grid; }
  .conn { display: none; }
  .page { padding: 16px 16px 40px; gap: 14px; }
}
.nav-scrim { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .side-nav a:not(.active) .nav-icon { background: hsl(var(--nh, 152) 20% 19%); color: hsl(var(--nh, 152) 55% 68%); } }
:root[data-theme="dark"] .side-nav a:not(.active) .nav-icon { background: hsl(var(--nh, 152) 20% 19%); color: hsl(var(--nh, 152) 55% 68%); }
