/* ============================================================
   Shell chrome: app layout, sidebar, topbar, command palette, assistant
   ============================================================ */

.app { display: flex; height: 100vh; width: 100vw; overflow: hidden; }
.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
/* overflow-x:hidden is REQUIRED: with only overflow-y set, the spec computes
   overflow-x to `auto`, making .main horizontally pan-draggable on touch even
   when .app clips the desktop scrollbar. Wide data tables keep their own nested
   scroll wrappers, so they are unaffected. */
.main { flex: 1; overflow-y: auto; overflow-x: hidden; background: var(--paper); }
.screen { padding: 24px 28px 48px; max-width: 1500px; margin: 0 auto; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.sb-brand { display: flex; align-items: center; gap: 11px; padding: 16px 18px; border-bottom: 1px solid var(--line); height: var(--topbar-h); }
.sb-crest {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  border: 1.5px solid var(--accent-line); display: grid; place-items: center; position: relative;
}
.sb-crest::after { content: ""; width: 11px; height: 11px; background: var(--accent); transform: rotate(45deg); }
.sb-word .n { font-size: 16px; font-weight: 500; line-height: 1; letter-spacing: -0.01em; }
.sb-word .s { font-size: 9px; letter-spacing: 0.16em; color: var(--muted); margin-top: 3px; }

.sb-nav { flex: 1; padding: 12px 12px 20px; overflow-y: auto; }
.sb-group { margin-bottom: 16px; }
.sb-glabel { font-family: var(--font-mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.13em; color: var(--faint); padding: 0 10px 7px; }
.sb-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 0 10px; height: 36px; border: 0; background: transparent; color: var(--ink-2);
  border-radius: var(--r); font-size: var(--fs-sm); font-weight: 500; text-align: left;
  transition: background .12s, color .12s; position: relative;
}
.sb-item:hover { background: var(--surface-2); color: var(--ink); }
.sb-item.on { background: var(--accent-soft); color: var(--accent-ink); }
.sb-item.on::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.sb-item svg { flex: none; opacity: 0.9; }
.sb-item span:nth-child(2) { flex: 1; }
.sb-count { font-size: 10px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; }
.sb-item.on .sb-count { background: var(--surface); color: var(--accent-ink); border-color: var(--accent-line); }

.sb-foot { padding: 12px 16px; border-top: 1px solid var(--line); }
.sb-term { display: flex; flex-direction: column; gap: 3px; }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h); min-height: var(--topbar-h);
  border-bottom: 1px solid var(--line); background: var(--surface);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
}
.tb-title { min-width: 0; }
.tb-title h1 { font-size: 16px; font-weight: 600; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-title .eyebrow { display: block; margin-bottom: 2px; font-size: 9.5px; }
.tb-search {
  display: flex; align-items: center; gap: 9px; height: 36px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--r); background: var(--surface-2);
  color: var(--muted); font-size: var(--fs-sm); width: 320px; max-width: 34vw; margin-left: auto;
  transition: border-color .12s, background .12s;
}
.tb-search:hover { border-color: var(--faint); }
.tb-search span { flex: 1; text-align: left; }
.tb-search kbd, .cmd-foot kbd, .asst kbd { font-size: 10px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 4px; padding: 1px 5px; color: var(--muted); }
.tb-right { display: flex; align-items: center; gap: 8px; }
.tb-menu { position: relative; }
.tb-chip { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 8px 0 6px; border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--r); color: var(--ink); }
.tb-chip:hover { background: var(--surface-2); }
.tb-role { font-size: var(--fs-sm); font-weight: 500; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-bell-dot { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--critical); border: 1.5px solid var(--surface); }

.tb-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  background: var(--raised); border: 1px solid var(--line-2); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); min-width: 260px; padding: 6px;
}
.tb-pop.sm { min-width: 180px; }
.tb-pop-h { font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--faint); padding: 8px 10px 6px; }
.tb-pop-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: transparent; color: var(--ink); border-radius: var(--r); font-size: var(--fs-sm); text-align: left; }
.tb-pop-item:hover { background: var(--surface-2); }
.tb-pop-item.on { background: var(--accent-soft); color: var(--accent-ink); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- Command palette ---------- */
.cmd-overlay { position: fixed; inset: 0; z-index: 200; background: oklch(0.2 0.02 260 / 0.4); backdrop-filter: blur(2px); display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh; }
.cmd { width: 600px; max-width: 92vw; background: var(--raised); border: 1px solid var(--line-2); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); overflow: hidden; }
.cmd-input { display: flex; align-items: center; gap: 11px; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--muted); }
.cmd-input input { flex: 1; border: 0; background: transparent; font-family: var(--font-sans); font-size: 15px; color: var(--ink); outline: none; }
.cmd-input input::placeholder { color: var(--faint); }
.cmd-body { max-height: 52vh; padding: 8px; }
.cmd-grp { margin-bottom: 8px; }
.cmd-glabel { font-family: var(--font-mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--faint); padding: 6px 10px; }
.cmd-item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 10px; border: 0; background: transparent; color: var(--ink); border-radius: var(--r); font-size: var(--fs-sm); text-align: left; }
.cmd-item:hover { background: var(--surface-2); }
.cmd-ic { width: 26px; height: 26px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; color: var(--ink-2); flex: none; }
.cmd-ic.ai { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); }
.cmd-go { margin-left: auto; opacity: 0; color: var(--faint); }
.cmd-item:hover .cmd-go { opacity: 1; }
.cmd-empty { padding: 28px; text-align: center; font-size: var(--fs-sm); }
.cmd-foot { display: flex; align-items: center; gap: 16px; padding: 9px 14px; border-top: 1px solid var(--line); font-size: 11px; color: var(--faint); }
.cmd-foot .ml-auto { margin-left: auto; font-family: var(--font-mono); }

/* ---------- Assistant drawer ---------- */
.asst { position: fixed; inset: 0; z-index: 180; display: none; }
.asst.open { display: block; }
.asst-scrim { position: absolute; inset: 0; background: oklch(0.2 0.02 260 / 0.32); }
.asst-panel { position: absolute; top: 0; right: 0; height: 100%; width: 420px; max-width: 94vw; background: var(--surface); border-left: 1px solid var(--line-2); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.asst-h { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.asst-mark { width: 30px; height: 30px; border-radius: var(--r); background: var(--accent-soft); border: 1px solid var(--accent-line); color: var(--accent-ink); display: grid; place-items: center; }
.asst-body { flex: 1; padding: 16px 14px; display: flex; flex-direction: column; gap: 14px; }
.asst-msg { display: flex; gap: 8px; max-width: 100%; }
.asst-msg.me { justify-content: flex-end; }
.asst-msg-mark { width: 22px; height: 22px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; margin-top: 2px; }
.asst-bubble { font-size: 13px; line-height: 1.55; border-radius: var(--r-lg); padding: 11px 13px; max-width: 86%; }
.asst-msg.ai .asst-bubble { background: var(--surface-2); border: 1px solid var(--line); border-top-left-radius: var(--r-sm); }
.asst-msg.me .asst-bubble { background: var(--accent); color: var(--on-accent); border-top-right-radius: var(--r-sm); }
.asst-src { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 9px; display: flex; flex-direction: column; gap: 5px; }
.asst-src-item { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--ink-2); }
.asst-src-item svg { color: var(--accent); flex: none; }
.asst-draft { margin-top: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; border-top: 1px dashed var(--line-2); padding-top: 10px; }
.asst-chips { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.asst-chip { border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); border-radius: var(--r-pill); padding: 5px 11px; font-size: 11.5px; text-align: left; }
.asst-chip:hover { border-color: var(--accent-line); color: var(--accent-ink); background: var(--accent-soft); }
.asst-input { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); }
.asst-input input { flex: 1; border: 1px solid var(--line-2); border-radius: var(--r); height: 38px; padding: 0 12px; background: var(--surface); color: var(--ink); font-family: var(--font-sans); font-size: 13px; outline: none; }
.asst-input input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.asst-foot { font-size: 10.5px; padding: 0 14px 12px; text-align: center; line-height: 1.5; }
.asst-typing { display: inline-flex; gap: 4px; align-items: center; padding: 3px 0; }
.asst-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.asst-typing i:nth-child(2) { animation-delay: .2s; } .asst-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ---------- responsive ---------- */
/* hamburger + drawer scrim are desktop-hidden by default */
.tb-burger { display: none; }
.tb-left { min-width: 0; }
.sb-scrim { display: none; }

/* tablet: collapse sidebar to an icon rail (phones get the full drawer below) */
@media (min-width: 769px) and (max-width: 1080px) {
  .sidebar { width: 64px; min-width: 64px; }
  .sb-word, .sb-glabel, .sb-item span, .sb-count, .sb-foot { display: none; }
  .sb-item { justify-content: center; padding: 0; }
  .sb-brand { justify-content: center; padding: 16px 0; }
}

/* phone: off-canvas drawer + compact header */
@media (max-width: 768px) {
  .tb-burger { display: inline-flex; flex: none; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 190;
    width: 264px; min-width: 264px;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .sb-scrim {
    display: block; position: fixed; inset: 0; z-index: 185;
    background: oklch(0.2 0.02 260 / 0.42);
    opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  .sb-scrim.on { opacity: 1; pointer-events: auto; }

  /* compact topbar: drop the big search, keep controls reachable */
  .topbar { gap: 8px; padding: 0 12px; }
  .tb-search { display: none; }
  .tb-right { margin-left: auto; gap: 4px; }
  .tb-role { display: none; }
  .tb-title h1 { overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
  .screen { padding: 18px 14px 40px; }
}

/* dashboard + screen grids (shared) */
.grid { display: grid; gap: var(--gap); }
.cards-4 { grid-template-columns: repeat(4, 1fr); }
.cards-5 { grid-template-columns: repeat(5, 1fr); }
.cards-3 { grid-template-columns: repeat(3, 1fr); }
.cards-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1240px) { .cards-5 { grid-template-columns: repeat(3, 1fr); } .cards-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) { .grid[class*="cards-"] { grid-template-columns: 1fr; } }

/* ---------- toasts ---------- */
.toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 9px; background: var(--ink); color: var(--paper); font-size: 12.5px; font-weight: 500; padding: 10px 16px; border-radius: var(--r-pill); box-shadow: var(--shadow-lg); max-width: 90vw; }
.toast svg { color: var(--stable); flex: none; }
.toast.warn svg { color: var(--watch); }
:root[data-theme="dark"] .toast { background: var(--raised); color: var(--ink); border: 1px solid var(--line-2); }

/* ---------- notifications popover ---------- */
.tb-pop.notif { min-width: 340px; padding: 0; overflow: hidden; }
.notif-h { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.notif-list { max-height: 380px; }
.notif-item { display: flex; align-items: flex-start; gap: 11px; width: 100%; padding: 11px 14px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink); text-align: left; }
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--surface-2); }
.notif-ic { width: 30px; height: 30px; border-radius: var(--r); display: grid; place-items: center; flex: none; margin-top: 1px; }
.notif-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; margin-top: 6px; }
