/* ============================================================
   Datamart — AppShell (THE unified application skeleton)
   ONE shell for every screen: topbar (logo · Datamart/CRM switch ·
   global search · account) + left nav + central content slot +
   right preview drawer slot. Pairs with _ds/app-shell.js.
   Edit here once → every screen updates. Load AFTER
   colors_and_type.css. Uses an `as-` (app-shell) class namespace
   so it never collides with per-screen content styles.
   ============================================================ */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font-sans); color: var(--fg); background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased; font-feature-settings: "cv05" 1, "cv08" 1, "ss01" 1; font-variant-numeric: tabular-nums; }
#root { height: 100vh; overflow: hidden; }
.ti { display: inline-flex; line-height: 1; font-size: 16px; }
svg.ti { width: 1em; height: 1em; }

/* ---- frame ---- */
.app  { display: flex; flex-direction: column; height: 100vh; }
.body { flex: 1; display: flex; min-height: 0; }

/* ============================================================
   TOPBAR
   Three zones on a centered grid: [logo + mode switch] · [search] ·
   [help · alerts · theme · account]. 49px tall, one hairline base.
   ============================================================ */
.as-top { height: var(--topbar-h); flex: none; display: grid; align-items: center;
  grid-template-columns: 1fr minmax(280px, 560px) 1fr; gap: var(--sp-4); padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border); background: var(--bg-canvas); }

/* zone 1 — brand mark + Datamart/CRM switcher */
.as-brandzone { justify-self: start; display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.as-logo { width: 28px; height: 28px; border-radius: var(--radius-md); display: grid; place-items: center;
  color: #fff; background: var(--accent); flex: none; }
.as-logo .ti { font-size: 17px; }

/* module switch — borderless workspace-style trigger + menu */
.as-mode { position: relative; }
.as-modebtn { display: inline-flex; align-items: center; gap: var(--sp-3); height: 32px; padding: 0 var(--sp-2) 0 var(--sp-1);
  background: transparent; border: 0; border-radius: var(--radius-md); cursor: pointer;
  white-space: nowrap; font: 600 13.5px var(--font-display); letter-spacing: -0.02em; color: var(--ink-900); }
.as-modebtn:hover { background: var(--hover-surface); }
.as-modebtn .tile { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  border-radius: 6px; color: #fff; font: 600 13px var(--font-display); letter-spacing: 0; flex: none; }
.as-modebtn .tile.dm { background: var(--accent); }
.as-modebtn .tile.crm { background: #16b8c4; }
.as-modebtn .cv { font-size: 15px; color: var(--fg-muted); transition: transform 0.14s ease; }
.as-modebtn .cv.open { transform: rotate(180deg); }
.as-mode-menu { left: 0; right: auto; width: 184px; }
.as-menu button .ck { margin-left: auto; font-size: var(--ico-sm); color: var(--accent); }

/* zone 2 — global search */
.as-search { justify-self: stretch; width: 100%; display: flex; align-items: center; gap: var(--sp-3); height: 34px;
  padding: 0 var(--sp-4); background: var(--surface-100); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); color: var(--fg-muted); cursor: text; box-shadow: var(--shadow-xs); }
.as-search .ti { font-size: 17px; flex: none; }
.as-search .ph { flex: 1; font: 400 13px var(--font-sans); color: var(--fg-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* ⌘K = kanonický `.acrm-kbd` (rt-real/inputs.css) — vlastní `.as-search kbd` zrušen (review ACRM-76 / A5). */

/* zone 3 — utilities + account */
.as-util { justify-self: end; display: inline-flex; align-items: center; gap: var(--sp-0); }
.as-icobtn { width: 32px; height: 32px; border-radius: var(--radius-md); display: grid; place-items: center;
  color: var(--fg-secondary); cursor: pointer; border: 1px solid transparent; background: transparent; position: relative; }
.as-icobtn:hover { background: var(--hover-surface); color: var(--ink-900); }
.as-icobtn .ti { font-size: 18px; }
/* tečka „nepřečtené" — jedno pravidlo pro obě tlačítka utility zóny. Kdo mění hodnoty,
   mění je tady, ne v kopii. */
.as-icobtn.dot::after,
.as-ai-trigger.dot::after { content: ""; position: absolute; top: 7px; right: 7px; width: 6px; height: 6px;
  border-radius: var(--radius-pill); background: var(--critical); border: 1.5px solid var(--bg-canvas); }
.as-div { width: 1px; height: 22px; background: var(--border-strong); margin: 0 var(--sp-2); flex: none; }

/* AI assistant sparkle trigger — sits in the utility zone next to the bell.
   Idle = quiet icon button; active (panel open) = AI gradient accent→violet fill,
   the same identity mark used by the assistant panel (ai-assistant.html). */
.as-ai-trigger { width: 32px; height: 32px; border-radius: var(--radius-md); display: grid; place-items: center;
  color: var(--fg-secondary); cursor: pointer; border: 1px solid transparent; background: transparent; position: relative; }
.as-ai-trigger:hover { background: var(--hover-surface); color: var(--ink-900); }
.as-ai-trigger .ti { font-size: 18px; }
.as-ai-trigger.on { color: #fff; border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-violet)); /* ds-ok: AI identity gradient (vzor Discussion / ai-assistant) */ }

/* BĚŽÍ (AD 30. 7. 2026) — aktivita se v tomhle DS kreslí POHYBEM (.aichat-run),
   stav staticky barvou (tečka, .on). Jsou to tři nezávislé kanály a smí svítit naráz:
   „něco se právě děje" × „něco na tebe čeká" × „panel je otevřený". Běh proto nesahá
   ani na tečku, ani na rám — accent prstenec kolem rámu by se pletl s :focus-visible. */
.as-ai-trigger.is-busy .ti { color: var(--accent); animation: as-ai-busy 1.1s ease-in-out infinite; }
.as-ai-trigger.on.is-busy .ti { color: #fff; } /* na gradientu by accent zmizel; pulzuje jen krytí */
@keyframes as-ai-busy { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) {
  /* pohyb pryč, ale accent ZŮSTÁVÁ — běh musí být vidět i bez animace */
  .as-ai-trigger.is-busy .ti { animation: none; }
}

/* POPISNÁ varianta (AD 31. 7. 2026) — spouštěč nese vedle glyfu jméno persony.
   Jméno persony je produktový obsah, ne dekorace, takže se nemaže kvůli tvaru.
   Tvar bere po sourozencích v téže zóně (.as-acctbtn / .as-modebtn): PRŮHLEDNÉ + hover,
   nikdy orámované tlačítko se stínem — to je v pravé zóně jediné, co by mělo obrys. */
.as-ai-trigger.named { display: inline-flex; width: auto; gap: var(--sp-2);
  padding: 0 var(--sp-3) 0 var(--sp-2); }
.as-ai-trigger.named .nm { font: 600 13px var(--font-display); color: var(--ink-900); letter-spacing: -0.01em; }
.as-ai-trigger.on .nm { color: #fff; }

/* DS.NotifBell mounts here when present — style its trigger like .as-icobtn so the
   unified topbar keeps one bell, with the live inbox popover when notifications.js loads. */
.as-util .nbell { position: relative; }
.as-util .icobtn { width: 32px; height: 32px; border-radius: var(--radius-md); display: grid; place-items: center;
  color: var(--fg-secondary); cursor: pointer; border: 1px solid transparent; background: transparent; }
.as-util .icobtn:hover { background: var(--hover-surface); color: var(--ink-900); }
.as-util .icobtn .ti { font-size: 18px; }

/* account button + menu */
.as-acct { position: relative; }
.as-acctbtn { display: inline-flex; align-items: center; gap: var(--sp-3); height: 32px; padding: 0 var(--sp-2) 0 var(--sp-1);
  border-radius: var(--radius-pill); cursor: pointer; border: 1px solid transparent; background: transparent; }
.as-acctbtn:hover { background: var(--hover-surface); }
.as-acctbtn .av { width: 24px; height: 24px; border-radius: var(--radius-pill); display: grid; place-items: center;
  color: hsl(var(--av-hue, 222) 52% 42%); font: 600 10px var(--font-display);
  background: var(--surface-75); border: 1.5px solid hsl(var(--av-hue, 222) 62% 60%); flex: none; }
.as-acctbtn .nm { font: var(--h3); color: var(--ink-900); letter-spacing: -0.01em; }
.as-acctbtn .cv { font-size: 14px; color: var(--fg-muted); }

.as-menu-scrim { position: fixed; inset: 0; z-index: 80; }
.as-menu { position: absolute; top: calc(100% + 7px); right: 0; z-index: 81; width: 232px; padding: var(--sp-2);
  background: var(--surface-100); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop); }
.as-menu-id { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-3) var(--sp-3); }
.as-menu-id .av { width: 32px; height: 32px; border-radius: var(--radius-pill); display: grid; place-items: center;
  color: hsl(var(--av-hue, 222) 52% 42%); font: 600 12px var(--font-display);
  background: var(--surface-75); border: 1.5px solid hsl(var(--av-hue, 222) 62% 60%); flex: none; }
.as-menu-id .t { display: flex; flex-direction: column; min-width: 0; }
.as-menu-id .n { font: var(--h3); color: var(--ink-900); letter-spacing: -0.01em; }
.as-menu-id .e { font: 400 12px var(--font-sans); color: var(--fg-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-menu-sep { height: 1px; margin: var(--sp-1) var(--sp-2); background: var(--border); }
.as-menu button { display: flex; align-items: center; gap: var(--sp-3); width: 100%; height: 34px; padding: 0 var(--sp-3); border: 0;
  background: transparent; border-radius: var(--radius-sm); font: 500 13px var(--font-sans); color: var(--fg);
  cursor: pointer; text-align: left; }
.as-menu button:hover { background: var(--hover-surface); }
.as-menu button .ti { font-size: var(--ico-sm); color: var(--fg-muted); flex: none; }
.as-menu button .sp { margin-left: auto; font: 500 11px var(--font-mono); color: var(--fg-muted); }

/* animated dark/light toggle inside the user menu */
.as-themebtn .as-toggle { margin-left: auto; position: relative; width: 40px; height: 22px; flex: none;
  border-radius: var(--radius-pill); background: var(--border-strong); transition: background 0.24s ease; }
.as-themebtn .as-toggle .knob { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface-100); box-shadow: var(--shadow-sm); display: grid; place-items: center;
  transition: transform 0.26s cubic-bezier(.34,1.4,.64,1); }
.as-themebtn .as-toggle .knob .ti { font-size: 11px; color: var(--ic-amber); transition: color 0.2s ease; }
.as-themebtn .as-toggle.on { background: var(--accent); }
.as-themebtn .as-toggle.on .knob { transform: translateX(18px); }
.as-themebtn .as-toggle.on .knob .ti { color: var(--accent); }
.as-themebtn:active .as-toggle .knob { width: 22px; }

/* ============================================================
   SIDEBAR (left nav) — 261px, mode-aware
   ============================================================ */
.as-side { width: var(--sidebar-w); flex: none; background: var(--sidebar-bg);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.as-nav { flex: 1; overflow-y: auto; padding: var(--sp-3); display: flex; flex-direction: column; gap: 1px; }

.as-row { display: flex; align-items: center; gap: var(--sp-3); height: var(--row-h-nav); padding: 0 var(--sp-3);
  border-radius: var(--radius-md); font: 500 13px var(--font-sans); color: var(--ink-700); cursor: pointer; user-select: none; }
.as-row > .ti { font-size: 16px; color: var(--ink-500); flex: none; }
.as-row:hover { background: var(--hover-surface); }
.as-row.active { background: var(--active-surface); color: var(--ink-900); }
.as-row.active > .ti { color: var(--ink-700); }
.as-row .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-row .chev { margin-left: auto; font-size: 14px; color: var(--fg-muted); transition: transform 0.14s ease; }
.as-row .chev.col { transform: rotate(-90deg); }
.as-row .count { margin-left: auto; font: 500 11px var(--font-mono); color: var(--fg-muted); }

.as-overline { font: 600 11px var(--font-sans); color: var(--fg-muted); padding: var(--sp-4) var(--sp-3) var(--sp-1); }

.as-sub { display: flex; align-items: center; gap: var(--sp-3); height: var(--row-h-nav); padding: 0 var(--sp-3) 0 var(--sp-4);
  border-radius: var(--radius-md); font: 500 13px var(--font-sans); color: var(--ink-700); cursor: pointer; user-select: none; }
.as-sub:hover { background: var(--hover-surface); }
.as-sub.active { background: var(--active-surface); color: var(--ink-900); }
.as-sub .sg { width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center; color: #fff; flex: none; }
.as-sub .sg .ti { font-size: 11px; }
.as-sub .wand { width: 18px; height: 18px; display: grid; place-items: center; color: var(--accent-violet); flex: none; }
.as-sub .wand .ti { font-size: 15px; }
.as-sub .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-sub .x { margin-left: auto; font-size: 13px; color: var(--fg-muted); }

/* collapsible section header — sentence-case label, chevron left, subtle blue
   count capsule right (RULES §7). Pairs with .as-sec/.caret/.cnt in app-shell.js. */
.as-sec { display: flex; align-items: center; gap: var(--sp-3); height: var(--row-h-nav);
  padding: 0 var(--sp-3); border-radius: var(--radius-md); cursor: pointer; user-select: none;
  font: var(--label); color: var(--fg-secondary); }
.as-sec:hover { background: var(--hover-surface); }
.as-sec .caret { font-size: 14px; color: var(--fg-muted); flex: none; transition: transform 0.14s ease; }
.as-sec .caret.col { transform: rotate(-90deg); }
.as-sec .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-sec .cnt { flex: none; min-width: 18px; padding: 1px 6px; border-radius: var(--radius-pill);
  background: var(--accent-tint); color: var(--accent-ink); text-align: center;
  font: 600 11px var(--font-mono); font-variant-numeric: tabular-nums; }

/* saved-segment colour tile (.as-sub .tile) + dashed „+ new" action (.as-new) */
.as-sub .tile { width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center; color: #fff; flex: none; }
.as-sub .tile .ti { font-size: 11px; }
.as-new { display: flex; align-items: center; gap: var(--sp-3); height: var(--row-h-nav);
  padding: 0 var(--sp-3) 0 var(--sp-4); border-radius: var(--radius-md); cursor: pointer; user-select: none;
  font: 500 13px var(--font-sans); color: var(--fg-muted); }
.as-new:hover { background: var(--hover-surface); color: var(--fg-secondary); }
.as-new > .ti { font-size: 15px; flex: none; }

/* notification badge on a top-level row = full accent, white number (RULES §7) */
.as-row .notif { margin-left: auto; flex: none; display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-pill);
  background: var(--accent); color: #fff; font: 600 10.5px var(--font-mono); font-variant-numeric: tabular-nums; }

/* sidebar footer */
.as-side-foot { border-top: 1px solid var(--border); padding: var(--sp-3); display: flex; flex-direction: column; gap: 1px; }

/* ============================================================
   MAIN content slot + DRAWER slot
   ============================================================ */
.as-main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column;
  position: relative; background: var(--bg-canvas); }

/* the preview drawer mounts into this slot, overlaying the right edge of main.
   Width matches the live record drawer; respects reduced-motion. */
.as-drawer { position: absolute; top: 0; right: 0; height: 100%; width: clamp(404px, 33.333vw, 640px);
  z-index: 50; display: flex; box-shadow: -18px 0 44px -14px rgba(0,0,0,0.28); }
/* full-plane: the drawer becomes an Attio-style record page covering the content area */
.as-drawer.full { width: 100%; box-shadow: none; }
@media (prefers-reduced-motion: no-preference) {
  .as-drawer { animation: as-drawer-in 0.2s cubic-bezier(.4,0,.2,1); }
}
@keyframes as-drawer-in { from { transform: translateX(14px); } to { transform: none; } }

/* ============================================================
   AI ASSISTANT slot (.as-ai)
   The assistant panel docks as the LAST flex child of .body, to the
   right of .as-main. It is a LAYOUT participant (squeeze), NOT an
   overlay: no scrim, no shadow — only a hairline on its left. Width
   400px. Opened via the sparkle trigger in the topbar (.as-ai-trigger)
   + ⌘J / Ctrl+J; open/closed persists in localStorage. The drawer
   (.as-drawer) still opens inside .as-main — i.e. to the LEFT of this
   panel, which stays docked as the right-most column. Below 1280px the
   panel flips to a right-side overlay (scrim + shadow, z60 — under
   popovers 71 and dialogs 80). Pairs with app-shell.js.
   ============================================================ */
.as-ai { width: 400px; flex: none; min-width: 0; min-height: 0; display: flex; flex-direction: column;
  border-left: 1px solid var(--border); background: var(--bg-canvas); }

/* narrow-window overlay: the panel becomes a fixed right-side sheet with a scrim,
   so it never squeezes an already-cramped content area (< 1280px). --ov-scrim /
   --overlay-shadow resolve from the app token layer; fallbacks keep the master honest. */
@media (max-width: 1279px) {
  .as-ai.as-ai-overlay { position: fixed; top: var(--topbar-h); right: 0; bottom: 0; z-index: 60;
    box-shadow: var(--overlay-shadow, -18px 0 44px -14px rgba(0,0,0,0.28)); }
  .as-ai-scrim { position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 59;
    background: var(--ov-scrim, rgba(16,18,22,0.34)); }
}

/* skeleton-page region labels (only on the demo card) */
.as-label { position: absolute; z-index: 60; display: inline-flex; align-items: center; gap: var(--sp-2); height: 22px;
  padding: 0 var(--sp-3); border-radius: var(--radius-pill); background: var(--accent); color: #fff;
  font: 600 11px var(--font-display); letter-spacing: 0.01em; box-shadow: var(--shadow-sm); pointer-events: none; }
.as-label .ti { font-size: 13px; }
