/* ==========================================================================
   App Shell — topbar, rail, responsive navigation
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px var(--gap);
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 14px var(--gutter) 48px;
  min-height: 100dvh;
  transition: grid-template-columns 0.32s var(--ease);
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 10px;
  z-index: 50;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  min-height: var(--top-h);
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: var(--r-2xl);
  background: var(--glass);
  box-shadow: var(--shadow-md);
  backdrop-filter: saturate(1.45) blur(18px);
  -webkit-backdrop-filter: saturate(1.45) blur(18px);
}

.topbar__menu {
  display: none !important;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding-right: 8px;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  flex: none;
  border-radius: 17px;
  color: var(--on-primary);
  background:
    radial-gradient(circle at 30% 20%, color-mix(in srgb, var(--primary) 55%, #ffffff) 0%, transparent 48%),
    linear-gradient(145deg, var(--primary) 0%, var(--primary-strong) 100%);
  box-shadow: 0 10px 22px -12px var(--primary), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}
.brand__mark svg { width: 29px; height: 29px; }

.brand__text { display: grid; line-height: 1.12; min-width: 0; }
.brand__text b {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 760;
  letter-spacing: -0.03em;
  white-space: nowrap;
}
.brand__text small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.075em;
  text-transform: uppercase;
  white-space: nowrap;
}

.topbar__context {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 700;
  white-space: nowrap;
}
.pill--soft {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-2);
}
.pill--demo {
  border: 1px dashed color-mix(in srgb, var(--warn) 45%, var(--line));
  background: var(--warn-soft);
  color: var(--warn);
  letter-spacing: 0.02em;
}

.topbar__tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  min-width: 0;
}

.finder-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 40px;
  padding: 0 10px 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  transition: all 0.2s var(--ease);
}
.finder-btn:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--surface);
}
.finder-btn kbd {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--faint);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 700;
}

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  transition: all 0.2s var(--ease);
}
.icon-btn:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--surface);
  transform: translateY(-1px);
}
.icon-btn .dot-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 0 2px var(--surface-2);
}

.ico--moon { display: none; }
:root[data-theme="dark"] .ico--sun { display: none; }
:root[data-theme="dark"] .ico--moon { display: block; }

.clock {
  display: grid;
  justify-items: end;
  gap: 1px;
  padding: 0 8px 0 4px;
  min-width: 78px;
  line-height: 1.1;
}
.clock strong {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
}
.clock span {
  color: var(--faint);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 44px;
  max-width: 230px;
  padding: 4px 8px 4px 5px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface-2);
  text-align: left;
  transition: all 0.2s var(--ease);
}
.user-pill:hover {
  border-color: var(--line-strong);
  background: var(--surface);
}
.user-pill__text { display: grid; min-width: 0; line-height: 1.18; }
.user-pill__text b {
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-pill__text small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.user-pill__chev { width: 14px; height: 14px; color: var(--faint); }

/* ── Sidebar rail ───────────────────────────────────────── */
.rail {
  position: sticky;
  top: calc(var(--top-h) + 30px);
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: var(--rail-w);
  max-height: calc(100dvh - var(--top-h) - 48px);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-2xl);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: width 0.32s var(--ease);
  overflow: hidden;
}

.rail__scroll {
  display: grid;
  gap: 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.rail__group {
  display: grid;
  gap: 3px;
  padding: 5px 0 9px;
  border-bottom: 1px solid var(--line-faint);
}
.rail__group:last-child { border-bottom: 0; padding-bottom: 2px; }

.rail__label {
  padding: 10px 11px 5px;
  color: var(--faint);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: opacity 0.2s;
}

.rail__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border-radius: 13px;
  color: var(--muted);
  font-size: var(--fs-md);
  font-weight: 650;
  text-align: left;
  transition: all 0.18s var(--ease);
}
.rail__item:hover {
  color: var(--text);
  background: var(--well);
}
.rail__item.is-active {
  color: var(--on-primary);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  box-shadow: 0 10px 20px -13px var(--primary), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
.rail__item.is-active .ico { color: var(--on-primary); }
.rail__item .ico { width: 19px; height: 19px; }
.rail__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity 0.18s;
}
.rail__badge {
  margin-left: auto;
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}
.rail__item.is-active .rail__badge {
  background: rgba(255, 255, 255, 0.18);
  color: var(--on-primary);
}
.rail__badge--alert { background: var(--bad-soft); color: var(--bad); }

.rail__foot {
  display: grid;
  gap: 3px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.rail__item--foot { min-height: 38px; font-size: var(--fs-sm); }
.rail__item--foot .ico { width: 17px; height: 17px; }
#btn-rail .ico { transition: transform 0.3s var(--ease); }

/* Collapsed rail */
html.rail-collapsed { --rail-w: var(--rail-collapsed); }
html.rail-collapsed .rail { padding: 9px 8px; }
html.rail-collapsed .rail__label { opacity: 0; height: 8px; padding: 0; overflow: hidden; }
html.rail-collapsed .rail__item { justify-content: center; padding: 0; }
html.rail-collapsed .rail__text,
html.rail-collapsed .rail__badge { display: none; }
html.rail-collapsed #btn-rail .ico { transform: rotate(180deg); }
html.rail-collapsed .rail__group { border-bottom-color: transparent; }

/* ── Main & page primitives ─────────────────────────────── */
.main {
  min-width: 0;
  outline: none;
}

.view {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  animation: fade-up 0.28s var(--ease);
  padding-bottom: 12px;
}

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  flex-wrap: wrap;
  padding: 4px 2px 2px;
}
.view-head__copy { display: grid; gap: 7px; max-width: 820px; }
.view-head__title {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-family: var(--font-display);
  font-size: clamp(28px, 2.8vw, 38px);
  font-weight: 780;
  letter-spacing: -0.04em;
  line-height: 1.05;
}
.view-head__title .title-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin-top: 2px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  flex: none;
}
.view-head__title .title-mark .ico { width: 23px; height: 23px; }
.view-head__sub {
  max-width: 72ch;
  color: var(--muted);
  font-size: var(--fs-md);
  line-height: 1.55;
}
.view-head__actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.view-split {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr);
  gap: var(--gap);
  align-items: start;
}
.view-split--even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.view-split--wide { grid-template-columns: minmax(0, 2.1fr) minmax(300px, 1fr); }

.nav-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(7, 18, 13, 0.45);
  backdrop-filter: blur(3px);
}

/* ── Kiosk immersive mode ───────────────────────────────── */
body.kiosk-mode .topbar,
body.kiosk-mode .rail,
body.kiosk-mode .nav-scrim,
body.kiosk-mode .skip-link { display: none !important; }
body.kiosk-mode .app {
  grid-template-columns: minmax(0, 1fr);
  padding: 0;
  max-width: none;
}
body.kiosk-mode .main { min-height: 100dvh; }
body.kiosk-mode .view { min-height: 100dvh; animation: none; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 1420px) {
  .brand__text small { display: none; }
  .user-pill__text { max-width: 120px; }
}

@media (max-width: 1240px) {
  .topbar__context { display: none; }
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .topbar__tools { justify-self: end; }
  .view-split, .view-split--wide { grid-template-columns: minmax(0, 1.45fr) minmax(280px, 1fr); }
}

@media (max-width: 1100px) {
  :root { --rail-w: var(--rail-collapsed); }
  html.rail-collapsed { --rail-w: var(--rail-collapsed); }
  .rail__label { opacity: 0; height: 8px; padding: 0; overflow: hidden; }
  .rail__item { justify-content: center; padding: 0; }
  .rail__text, .rail__badge { display: none; }
  .rail__group { border-bottom-color: transparent; }
  .view-split, .view-split--wide, .view-split--even { grid-template-columns: minmax(0, 1fr); }
  .finder-btn span, .finder-btn kbd { display: none; }
  .finder-btn { width: 40px; justify-content: center; padding: 0; }
  .clock { display: none; }
}

@media (max-width: 900px) {
  .app {
    display: block;
    padding: 10px 12px 36px;
  }
  .topbar {
    top: 8px;
    min-height: 64px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    border-radius: 22px;
    padding: 8px 10px;
  }
  .topbar__menu { display: inline-grid !important; }
  .brand { gap: 9px; }
  .brand__mark { width: 42px; height: 42px; border-radius: 14px; }
  .brand__mark svg { width: 25px; height: 25px; }
  .brand__text b { font-size: 17px; }
  .brand__text small { display: none; }
  .main { margin-top: 14px; }
  .user-pill__text, .user-pill__chev { display: none; }
  .user-pill { width: 44px; padding: 4px; justify-content: center; }
  .rail {
    position: fixed;
    top: 10px;
    left: 10px;
    bottom: 10px;
    z-index: 60;
    width: min(280px, calc(100vw - 32px));
    max-height: none;
    border-radius: 24px;
    transform: translateX(calc(-100% - 24px));
    transition: transform 0.3s var(--ease);
    box-shadow: var(--shadow-pop);
  }
  html.nav-open .rail { transform: translateX(0); }
  html.nav-open .nav-scrim { display: block; }
  .rail__label { opacity: 1; height: auto; padding: 10px 11px 5px; }
  .rail__item { justify-content: flex-start; padding: 0 11px; }
  .rail__text, .rail__badge { display: inline-flex; }
  .rail__group { border-bottom-color: var(--line-faint); }
  #btn-rail { display: none; }
  .view-head { align-items: flex-start; gap: 16px; }
  .view-head__actions { width: 100%; }
  .view-head__actions .btn { flex: 1; }
}

@media (max-width: 620px) {
  .app { padding: 8px 8px 28px; }
  .topbar { gap: 8px; }
  .brand__text b { font-size: 15.5px; }
  .brand__mark { width: 38px; height: 38px; border-radius: 12px; }
  .brand__mark svg { width: 22px; height: 22px; }
  .topbar__tools { gap: 5px; }
  .icon-btn { width: 36px; height: 36px; }
  .user-pill { display: none; }
  #btn-theme { display: none; }
  .view-head__title { font-size: 27px; }
  .view-head__title .title-mark { width: 36px; height: 36px; border-radius: 12px; }
  .view-head__title .title-mark .ico { width: 20px; height: 20px; }
}
