﻿*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-ui);
  font-size: var(--fs-md);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
table { border-collapse: collapse; }
svg { flex: none; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; font-family: var(--f-display); }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); font-family: var(--f-display); }

/* ---------- Application shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns .2s ease;
}
.app.rail-min { grid-template-columns: var(--rail-w-min) minmax(0, 1fr); }

/* Sidebar (right side in RTL) */
.rail {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: var(--s4) var(--s3) var(--s4);
  min-height: 0;
  overflow: hidden;
}
.rail-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: 4px 6px 10px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 40px; height: 40px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text b { font-family: var(--f-display); font-size: 22px; font-weight: 700; color: var(--ink); }
.brand-text span { font-size: 11px; color: var(--muted); white-space: nowrap; }
.rail-toggle { width: 40px; height: 40px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; color: var(--ink-2); }
.rail-toggle:hover { color: var(--ink); }
.rail-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 2px; padding-inline-end: 2px; scrollbar-width: thin; }
.rail-group { font-size: 11px; color: var(--muted); padding: 14px 14px 6px; letter-spacing: .02em; white-space: nowrap; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  height: 48px; padding: 0 6px 0 12px;
  border-radius: var(--r-pill);
  color: var(--ink-2);
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-item .ico-wrap { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); flex: none; transition: background .15s, color .15s; }
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--ink); color: var(--on-ink); }
.nav-item[aria-current="page"] .ico-wrap { background: transparent; color: var(--on-ink); }
.nav-item .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-count { min-width: 22px; height: 22px; padding: 0 7px; border-radius: var(--r-pill); background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center; font-family: var(--f-display); }
.nav-item[aria-current="page"] .nav-count { background: var(--on-ink); color: var(--ink); }
.nav-live { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 4px var(--bad-soft); margin-inline-end: 8px; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px transparent; } }
.rail-foot { border-top: 1px solid var(--line-2); padding-top: var(--s3); display: flex; flex-direction: column; gap: 2px; }

.app.rail-min .rail { padding-inline: 14px; }
.app.rail-min .brand-text,
.app.rail-min .nav-label,
.app.rail-min .rail-group,
.app.rail-min .nav-count { display: none; }
.app.rail-min .rail-top { flex-direction: column; padding-inline: 0; }
.app.rail-min .nav-item { width: 56px; height: 56px; padding: 0; justify-content: center; border-radius: 50%; }
.app.rail-min .nav-item .ico-wrap { width: 52px; height: 52px; }
.app.rail-min .nav-item[aria-current="page"] .ico-wrap { background: var(--ink); }
.app.rail-min .nav-item[data-count]::after { content: attr(data-count); position: absolute; top: 2px; left: 2px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; display: grid; place-items: center; padding: 0 4px; font-family: var(--f-display); }
.app.rail-min .nav-live { position: absolute; top: 8px; left: 8px; margin: 0; }

/* Main column */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  margin: var(--s4) var(--s6) 0 var(--s6);
  margin-inline-start: 0;
  height: 68px;
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s3) 0 var(--s4);
  background: var(--surface);
  border-radius: var(--r-pill);
  flex: none;
}
.search-trigger {
  flex: 1; max-width: 520px; height: 46px;
  display: flex; align-items: center; gap: 10px; padding: 0 18px;
  border-radius: var(--r-pill); background: var(--surface-2); color: var(--muted);
  text-align: start; min-width: 200px; white-space: nowrap; overflow: hidden;
}
.search-trigger span:not(.kbd) { overflow: hidden; text-overflow: ellipsis; }
.search-trigger .kbd { white-space: nowrap; flex: none; }
.search-trigger:hover { background: var(--surface-3); }
.search-trigger .kbd { margin-inline-start: auto; }
.topbar-spacer { flex: 1; }
.icon-btn { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); position: relative; flex: none; }
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn .dot { position: absolute; top: 9px; left: 10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; display: grid; place-items: center; font-family: var(--f-display); border: 2px solid var(--surface); }
.profile-chip { display: flex; align-items: center; gap: 10px; padding: 5px 5px 5px 16px; border-radius: var(--r-pill); background: var(--surface-2); }
.profile-chip:hover { background: var(--surface-3); }
.profile-chip .who { display: flex; flex-direction: column; line-height: 1.25; text-align: start; }
.profile-chip .who b { font-size: 14px; }
.profile-chip .who span { font-size: 11.5px; color: var(--muted); }

.sync-pill { display: inline-flex; align-items: center; gap: 8px; height: 46px; padding: 0 16px; border-radius: var(--r-pill); background: var(--surface-2); font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.sync-pill:hover { background: var(--surface-3); }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.sync-pill[data-state="offline"] .sync-dot { background: transparent; border: 2px solid var(--muted); }
.sync-pill[data-state="pending"] .sync-dot { background: var(--warn); }
.sync-pill[data-state="syncing"] .sync-dot { background: var(--info); animation: pulse 1.2s infinite; }
.sync-pill[data-state="attention"] .sync-dot { background: var(--bad); }

/* Live session strip */
.livebar {
  margin: var(--s3) 0 0 var(--s6);
  display: flex; align-items: center; gap: var(--s4);
  padding: 8px 8px 8px 18px;
  min-height: 52px;
  background: var(--ink); color: var(--on-ink);
  border-radius: var(--r-pill);
  font-size: 14px;
  flex: none;
}
.livebar .live-tag { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.livebar .live-tag i { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 4px rgba(210, 60, 50, .3); }
.livebar .sep { opacity: .35; }
.livebar .grow { flex: 1; }
.livebar .btn { height: 38px; }

/* Scrollable workspace */
.view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--s6) 0 var(--s10) var(--s6);
  scroll-behavior: smooth;
}
.view-inner { max-width: 1480px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--s6); }

/* Overlay roots */
.layer { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.layer > * { pointer-events: auto; }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 10px; width: 380px; pointer-events: none; }
.toasts > * { pointer-events: auto; }

@media (max-width: 1400px) {
  .topbar { margin-inline-end: var(--s4); }
  .view { padding-left: var(--s4); }
  .livebar { margin-left: var(--s4); }
  .profile-chip .who { display: none; }
  .profile-chip { padding: 5px; }
}
@media (max-width: 1100px) {
  .sync-pill .sync-text { display: none; }
}
@media (max-width: 860px) {
  .app, .app.rail-min { grid-template-columns: var(--rail-w-min) minmax(0, 1fr); }
  .app .brand-text, .app .nav-label, .app .rail-group, .app .nav-count { display: none; }
  .search-trigger span:not(.kbd) { display: none; }
}
