/* ==========================================================================
   iViRTH ONE — UI foundation (Phase 1 preview)
   Mobile-first, fluid, dark-first with a light theme.
   Breakpoints: <640 phone · 640–1023 tablet (icon rail) · ≥1024 desktop
   ========================================================================== */

:root {
  --bg: #0a0b0f;
  --surface: #12141b;
  --surface-2: #191c25;
  --surface-3: #222633;
  --line: #272b38;
  --text: #eceef5;
  --muted: #9097a8;
  --accent: #8c7dff;
  --accent-2: #5fd4ff;
  --accent-ink: #0a0b0f;
  --ok: #3fd396;
  --warn: #f6b84e;
  --danger: #ff6f6f;
  --info: #62b6ff;
  --ai: #b79bff;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 18px 40px -14px rgba(0, 0, 0, .55);
  --sidebar: 264px;
  --rail: 80px;
  --topbar: 64px;
  --gap: clamp(12px, 2vw, 20px);
  --font: Inter, "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --surface-3: #e6e9f2;
  --line: #e1e5ee;
  --text: #12141c;
  --muted: #5c6375;
  --accent: #5a49e0;
  --accent-2: #1e88c7;
  --accent-ink: #ffffff;
  --ok: #15865a;
  --warn: #a86a05;
  --danger: #c93b3b;
  --info: #1e6fb8;
  --ai: #6a4fd6;
  --shadow: 0 14px 34px -16px rgba(20, 24, 44, .28);
  color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 100% -12%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
    radial-gradient(900px 480px at -10% 110%, color-mix(in srgb, var(--accent-2) 8%, transparent), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: clamp(1.45rem, 2.6vw, 2rem); letter-spacing: -.02em; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#view:focus { outline: none; }
svg { width: 20px; height: 20px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
.noscript { padding: 24px; }
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* ---------- Shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 14px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 18px; }
.brand-mark { width: 38px; height: 38px; border-radius: 50%; box-shadow: 0 0 0 1px var(--line); flex: none; }
.brand-text strong { display: block; font-size: 1rem; letter-spacing: -.01em; }
.brand-text small { color: var(--muted); font-size: .75rem; }
.nav { display: grid; gap: 4px; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); }
.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.nav-item .count, .count {
  margin-left: auto;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  text-align: center;
}
.side-foot { margin-top: auto; }
.me { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.me strong { display: block; font-size: .9rem; }
.me small { color: var(--muted); font-size: .75rem; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 clamp(14px, 2.5vw, 28px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.content {
  overflow-x: clip;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: clamp(16px, 2.5vw, 28px);
  padding-bottom: 104px;
}
.menu-btn { display: grid; }
@media (min-width: 1024px) { .topbar .menu-btn { display: none; } }

.search-trigger {
  flex: 1;
  max-width: 480px;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  text-align: left;
  min-width: 0;
}
.search-trigger span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-trigger:hover { border-color: var(--accent); }
kbd {
  font: 600 .7rem/1 var(--font);
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.icon-btn {
  position: relative;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: .8rem;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn .dot {
  position: absolute;
  top: 8px;
  right: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface-2);
}

.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  font-weight: 700;
  font-size: .8rem;
}
.avatar.sm { width: 32px; height: 32px; }
.avatar.xs { width: 26px; height: 26px; font-size: .68rem; }
.ai-av { background: var(--surface-3); color: var(--ai); }

/* Scrim + off-canvas drawer (tablet and phone) */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(3, 4, 8, .55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}

/* Tablet: icon rail that opens into a drawer */
@media (min-width: 640px) and (max-width: 1023px) {
  .app { grid-template-columns: var(--rail) minmax(0, 1fr); }
  .sidebar { width: var(--rail); padding: 16px 10px; }
  .sidebar .brand { justify-content: center; padding: 4px 0 16px; }
  .sidebar .brand-text, .sidebar .side-foot-text, .sidebar .nav-label {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .nav-item { justify-content: center; padding: 12px 0; }
  .nav-item .count { position: absolute; top: 2px; right: 2px; min-width: 18px; padding: 0 5px; font-size: .65rem; }
  .me { justify-content: center; padding: 8px; }
}

/* Phone: off-canvas drawer + bottom navigation */
@media (max-width: 639px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .content { padding-bottom: 96px; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .search-trigger { max-width: none; }
  .topbar { gap: 8px; }
}
.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.bottom-nav a, .bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--muted);
  font-size: .68rem;
  text-decoration: none;
  min-width: 0;
}
.bottom-nav span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bottom-nav .is-active { color: var(--accent); }
.bottom-nav svg { width: 22px; height: 22px; }

@media (max-width: 639px) {
  .bottom-nav { display: grid; }
}

/* Drawer open state (tablet + phone) */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    width: min(300px, 86vw);
    z-index: 50;
    padding: 20px 14px;
    transform: translateX(-105%);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1);
    box-shadow: var(--shadow);
  }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .app.nav-open .sidebar .brand-text,
  .app.nav-open .sidebar .side-foot-text,
  .app.nav-open .sidebar .nav-label {
    position: static; width: auto; height: auto; overflow: visible; clip: auto; white-space: normal;
  }
  .app.nav-open .sidebar .brand { justify-content: flex-start; padding: 4px 8px 18px; }
  .app.nav-open .nav-item { justify-content: flex-start; padding: 10px 12px; }
  .app.nav-open .nav-item .count { position: static; min-width: 22px; padding: 1px 7px; font-size: .72rem; }
  .app.nav-open .me { justify-content: flex-start; padding: 12px; }
}
@media (min-width: 1024px) {
  .sidebar { width: var(--sidebar); }
}

/* Vertical rhythm: every top-level block in the page is separated by one gap */
.content > * + * { margin-top: var(--gap); }

/* ---------- Page primitives ---------- */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px 20px;
}
.page-head .muted { margin-top: 6px; max-width: 62ch; }
.eyebrow {
  margin: 0 0 6px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(16px, 2vw, 22px);
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-bottom: 14px;
}
.notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 34%, transparent);
  font-size: .9rem;
}
.notice svg { color: var(--warn); margin-top: 2px; }
.notice p { margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 18px; margin: 0; }
.error { color: var(--danger); font-size: .9rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: transform .15s, background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.98); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { box-shadow: 0 8px 22px -8px color-mix(in srgb, var(--accent) 80%, transparent); }
.btn.ghost { background: transparent; }
.btn.danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: .84rem; border-radius: 10px; }
.btn.block { width: 100%; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--muted);
  white-space: nowrap;
}
.badge.ai { background: color-mix(in srgb, var(--ai) 16%, transparent); color: var(--ai); }
.badge.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge.pending, .badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.badge.info { background: color-mix(in srgb, var(--info) 16%, transparent); color: var(--info); }

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.seg button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: .85rem;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .18); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: .85rem;
  transition: border-color .15s, color .15s;
}
.chip:hover { border-color: var(--accent); color: var(--text); }

.field { display: grid; gap: 6px; }
.field label, .label { font-size: .84rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}
select.sm { width: auto; min-height: 32px; padding: 4px 8px; font-size: .8rem; border-radius: 9px; }
textarea { resize: none; line-height: 1.45; }
.grid-two { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 520px) { .grid-two { grid-template-columns: 1fr 1fr; } }
.toggle { cursor: pointer; }
.toggle input[type="checkbox"] { width: 46px; height: 26px; min-height: 0; appearance: none; -webkit-appearance: none; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line); position: relative; flex: none; cursor: pointer; transition: background .2s; }
.toggle input[type="checkbox"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--text); transition: transform .2s; }
.toggle input[type="checkbox"]:checked { background: var(--accent); border-color: transparent; }
.toggle input[type="checkbox"]:checked::after { transform: translateX(20px); background: var(--accent-ink); }

.row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: inherit;
  text-align: left;
  text-decoration: none;
  transition: border-color .15s, background .15s;
}
a.row-item:hover, button.row-item:hover { border-color: var(--accent); }
.row-main { display: grid; gap: 2px; min-width: 0; }
.row-main strong { overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row-item.unread { border-left: 3px solid var(--accent); }
.row-item.is-active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; position: relative; }
.timeline li { display: grid; grid-template-columns: 14px 1fr; gap: 12px; }
.timeline li::before {
  content: "";
  width: 10px;
  height: 10px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.timeline small { display: block; color: var(--muted); font-size: .78rem; }

/* KPI tiles */
.kpis { display: grid; gap: var(--gap); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 1024px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi {
  display: grid;
  gap: 4px;
  text-decoration: none;
  color: inherit;
  transition: transform .2s, border-color .2s;
}
.kpi:hover { transform: translateY(-3px); border-color: var(--accent); }
.kpi-ic {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  margin-bottom: 8px;
}
.kpi-val { font-size: clamp(1.6rem, 3vw, 2.2rem); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

.grid-2 { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); } }

/* Bar chart (heights are set by JS after render) */
.bars { display: flex; align-items: flex-end; gap: clamp(6px, 1.6vw, 14px); height: clamp(150px, 26vw, 200px); margin: 8px 0 12px; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; }
.bar {
  width: 100%;
  max-width: 44px;
  height: 0;
  border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 30%, transparent));
  transition: height .7s cubic-bezier(.2, .8, .2, 1);
}
.bar-col span { font-size: .72rem; color: var(--muted); }

/* ---------- Dashboard / Command ---------- */
.mod-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.mod {
  display: grid;
  gap: 10px;
  padding: 16px;
  text-align: left;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: border-color .15s, transform .15s;
}
.mod:hover { border-color: var(--accent); transform: translateY(-2px); }
.mod strong { font-size: .95rem; }

.dept-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.dept {
  display: grid;
  gap: 10px;
  padding: 18px;
  text-align: left;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s;
}
.dept:hover { transform: translateY(-2px); border-color: var(--accent); }
.dept .kpi-ic { margin: 0; }

/* ---------- Assistant ---------- */
.assistant { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .assistant { grid-template-columns: 260px minmax(0, 1fr); } }
.conv-list { display: flex; flex-direction: column; gap: 10px; align-self: start; }
@media (max-width: 899px) { .conv-list { max-height: 210px; overflow: auto; } }
.conv-items { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.conv-btn {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.conv-btn:hover { background: var(--surface-2); color: var(--text); }
.conv-btn.is-active { background: var(--surface-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.chat { display: flex; flex-direction: column; min-height: min(72vh, 680px); }
.thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 6px 2px 10px;
  min-height: 240px;
  max-height: 56vh;
  scroll-behavior: smooth;
}
.msg { display: flex; gap: 10px; max-width: min(700px, 92%); animation: rise .25s ease both; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; margin-left: auto; }
.bubble {
  padding: 12px 14px;
  border-radius: 16px 16px 16px 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  min-width: 0;
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  border-radius: 16px 16px 4px 16px;
}
.msg-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.msg-meta .small { font-size: .74rem; }
.composer { display: flex; align-items: flex-end; gap: 10px; margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.composer textarea { min-height: 46px; max-height: 160px; }
.composer .btn { width: 46px; min-height: 46px; padding: 0; flex: none; }
.dots { display: flex; gap: 5px; align-items: center; padding: 16px 18px; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Kanban ---------- */
.kanban {
  contain: inline-size;
  max-width: 100%;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(250px, 1fr);
  gap: var(--gap);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.kcol {
  contain: paint;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 260px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}
.kcol > header { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 4px; }
.kcol h2 { font-size: .92rem; }
.kcol .count { background: var(--surface-3); color: var(--muted); }
.kdrop { display: grid; gap: 10px; align-content: start; flex: 1; padding: 4px; border-radius: 12px; transition: background .15s; }
.kdrop.over { background: color-mix(in srgb, var(--accent) 12%, transparent); outline: 1px dashed var(--accent); }
.kcard {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  cursor: grab;
  transition: transform .15s, box-shadow .15s, opacity .15s;
  touch-action: manipulation;
}
.kcard:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.kcard:active { cursor: grabbing; }
.kcard.dragging { opacity: .45; }
.kcard h3 { overflow-wrap: anywhere; }
.kcard .row { justify-content: space-between; gap: 8px; }

/* ---------- Knowledge / Decisions / Workflows ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.toolbar input[type="search"] { flex: 1 1 240px; max-width: 420px; }
.split { display: grid; gap: var(--gap); }
@media (min-width: 1024px) { .split { grid-template-columns: minmax(300px, .9fr) minmax(0, 1.4fr); align-items: start; } }
.master { align-self: start; }
.defs { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px 16px; margin: 18px 0 0; }
.defs dt { margin-top: 12px; font-size: .74rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.defs dd { margin: 0; }
.defs ol { margin: 0; padding-left: 20px; }
@media (min-width: 640px) {
  .defs { grid-template-columns: 130px minmax(0, 1fr); }
  .defs dt { margin: 0; padding-top: 3px; }
}
.ai-panel {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px dashed color-mix(in srgb, var(--ai) 55%, transparent);
  background: color-mix(in srgb, var(--ai) 8%, transparent);
  display: grid;
  gap: 8px;
}
.final { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.final h3 { font-size: 1rem; }

.wf { display: grid; gap: 12px; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .6s ease;
}
.steps { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 8px; }
@media (min-width: 768px) { .steps { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.steps li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: .85rem;
}
.steps li svg { width: 16px; height: 16px; }
.steps li.done { color: var(--ok); }
.steps li.active { color: var(--text); border-color: var(--accent); }
.dot-i {
  width: 20px; height: 20px; flex: none; display: grid; place-items: center;
  border-radius: 50%; font-size: .72rem; font-weight: 700; background: var(--surface-3);
}

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); }
.login-hero { display: none; }
@media (min-width: 960px) {
  .login { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
  .login-hero {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 56px;
    overflow: hidden;
    background:
      radial-gradient(800px 480px at 15% 0%, color-mix(in srgb, var(--accent) 38%, transparent), transparent 60%),
      radial-gradient(640px 460px at 95% 100%, color-mix(in srgb, var(--accent-2) 22%, transparent), transparent 60%),
      var(--surface);
    border-right: 1px solid var(--line);
  }
}
.hero-mark {
  width: clamp(140px, 20vw, 240px);
  height: auto;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line), 0 40px 90px -30px rgba(0, 0, 0, .7);
}
.hero-copy { display: grid; gap: 14px; max-width: 26ch; }
.hero-copy h2 { font-size: clamp(1.6rem, 3vw, 2.5rem); letter-spacing: -.02em; line-height: 1.1; }
.login-panel { display: grid; place-items: center; padding: clamp(22px, 5vw, 56px); }
.login-card { width: min(430px, 100%); display: grid; gap: 14px; }
.login-card h1 { margin-top: 6px; }
.wordmark { height: 44px; width: auto; }
[data-theme="light"] .wordmark { filter: invert(1); }
.login-card .btn.block { margin-top: 4px; }

/* ---------- Dialogs, palette, sheets ---------- */
dialog {
  padding: 0;
  width: min(560px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(3, 4, 8, .62); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .2s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }
.sheet-inner { display: grid; grid-template-rows: auto 1fr auto; max-height: inherit; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 1.1rem; }
.sheet-body { padding: 20px; display: grid; gap: 14px; overflow-y: auto; }
.sheet-body .list { max-height: 50vh; overflow-y: auto; }
.sheet-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line); }

.palette { margin: 12vh auto auto; }
.pal-search { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--muted); }
.pal-search input { border: 0; background: transparent; min-height: 34px; padding: 0; box-shadow: none; }
.pal-search input:focus { box-shadow: none; }
#palList { list-style: none; margin: 0; padding: 8px; max-height: 50vh; overflow-y: auto; display: grid; gap: 2px; }
#palList li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
}
#palList li[aria-selected="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.pal-foot { display: flex; flex-wrap: wrap; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: .75rem; color: var(--muted); }

/* Phone: dialogs become bottom sheets */
@media (max-width: 639px) {
  dialog { width: 100%; max-width: 100%; margin: auto auto 0; border-radius: var(--radius) var(--radius) 0 0; max-height: 92dvh; }
  dialog[open] { animation: sheet-up .25s cubic-bezier(.2, .8, .2, 1); }
  .palette { margin: 0 auto auto; width: 100%; border-radius: 0 0 var(--radius) var(--radius); }
  dialog[open].palette { animation: pop-down .22s ease; }
}
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes pop-down { from { transform: translateY(-10px); opacity: 0; } }

.toasts {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 100;
  display: grid;
  gap: 10px;
  max-width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
@media (max-width: 639px) {
  .toasts { left: 12px; right: 12px; bottom: 90px; max-width: none; }
}
.toast {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: .9rem;
  animation: toast-in .25s ease;
  transition: opacity .3s, transform .3s;
}
.toast.ok { border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.toast.warn { border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Small utilities (kept in CSS so the CSP needs no inline styles) ---------- */
.filter-select { width: auto; min-height: 42px; }
.tags { gap: 8px; justify-content: flex-end; }
.self-start { justify-self: start; }
.hint { margin-top: 12px; }
.gap-top { margin-top: var(--gap); }

/* ---------- Reduced motion & print-safe defaults ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
