/* Zidos Trail v9 Shell — base reset, topbar, Clio glass nav, toast */
*, *::before, *::after {
  box-sizing: border-box;
  scrollbar-width: none;
}

*::-webkit-scrollbar { display: none; }

html {
  scroll-behavior: smooth;
  background: var(--canvas);
  color: var(--ink);
  max-width: 100vw;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  max-width: 100vw;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

/* Embedded Trail demo in hero showcase */
html.is-embedded,
html.is-embedded body {
  overflow: hidden;
  height: 100%;
  max-height: 100%;
  touch-action: pan-y;
  scrollbar-width: none;
}

html.is-embedded .app-viewport {
  min-height: 0;
  height: auto;
  overflow: hidden;
  padding-bottom: 16px;
}

html.is-embedded body #page-overview #ovGrid.p2-reference {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  height: auto;
  min-height: 0;
  margin: 0;
  overflow: hidden;
}

html.is-embedded #page-overview #ovStrip,
html.is-embedded #page-overview #r8Limits,
html.is-embedded #page-overview .restore2-hints,
html.is-embedded #page-overview #restore2Hints,
html.is-embedded #page-overview .ov-r1,
html.is-embedded #page-overview .ov-r3,
html.is-embedded #page-overview .r29-trends,
html.is-embedded #page-overview .r29-overview-bottom,
html.is-embedded #ovAcc,
html.is-embedded #r8Health,
html.is-embedded #r8Season,
html.is-embedded .topbar-controls,
html.is-embedded #hgBar,
html.is-embedded #hgDrillHost,
html.is-embedded #ovStash,
html.is-embedded .r29-advisor {
  display: none;
}

@media (max-width: 768px) {
  html.is-embedded body #page-overview #ovGrid.p2-reference {
    grid-template-columns: minmax(0, 1fr);
  }
  html.is-embedded #page-overview #ovSoon,
  html.is-embedded body #page-overview #ovGrid.p2-reference > [data-w="upcoming"] {
    display: none;
  }
  /* Compact phone demo: three primary actions share one row instead of two. */
  html.is-embedded body #page-overview #ovHero .r29-quick {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Embedded preview: one fixed window for every tab; only the first screen is shown.
   Limits keeps the subscriptions widget; the window height follows that screen. */
html.is-embedded .page-actions { display: none; }
html.is-embedded .page-inner { padding-bottom: 0; }
html.is-embedded body #page-budgets .page-inner { padding-bottom: 0; }
html.is-embedded #page-budgets #bTabs,
html.is-embedded #page-budgets #bNewLim,
html.is-embedded #page-budgets #bMonth,
html.is-embedded #page-budgets .r5c-budget-toolbar,
html.is-embedded #page-budgets .m4v2-minis2,
html.is-embedded #page-budgets .q1-foot { display: none; }

html.is-embedded #page-transactions #r8Panel,
html.is-embedded #page-transactions #opNudge,
html.is-embedded #page-transactions #opPending,
html.is-embedded #page-transactions #opFooter,
html.is-embedded #page-transactions #fltBtn,
html.is-embedded #page-transactions #opMoreBtn { display: none; }
html.is-embedded #page-transactions #opBody tr:nth-child(n+3) { display: none; }

html.is-embedded #page-analytics .r29-analytics-layout :is(.card, .r29-assistant),
html.is-embedded #page-analytics .r29-analytics-layout > aside,
html.is-embedded #page-analytics .r29-health-kpi { display: none; }

html.is-embedded #page-cashflow #cfGoalCard,
html.is-embedded #page-cashflow #incomeTemplates,
html.is-embedded #page-cashflow .g2,
html.is-embedded #page-cashflow .page-inner > .card:last-child,
html.is-embedded #page-cashflow .cb,
html.is-embedded #page-cashflow .cf-sel,
html.is-embedded #page-cashflow .cf-metrics,
html.is-embedded #page-cashflow .rank-row { display: none; }

html.is-embedded #page-receipts .rc-split,
html.is-embedded #page-receipts #rcHelp { display: none; }

html.is-embedded #page-family .family-layout,
html.is-embedded #page-family .debt-friend-head { display: none; }

html.is-embedded #page-integrations .g2 > .card:nth-child(n+3),
html.is-embedded #page-integrations summary { display: none; }

/* Subscription dialog: keep the receipts scene, drop the tall bottom inset. */
html.is-embedded body .ztsw-layer .ztsw-body { padding-bottom: 24px; }
html.is-embedded body .ztsw-layer .ztsw-scene { margin-bottom: 0; }

/* Cover / redistribute sheet: category icons keep the demo's 32 px size. */
html.is-embedded #mHelp .m4v2-catic,
html.is-embedded .m4v2-rm-sheet .m4v2-catic {
  width: 32px;
  height: 32px;
  flex: none;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--ink-2);
}
html.is-embedded #mHelp .m4v2-catic svg,
html.is-embedded .m4v2-rm-sheet .m4v2-catic svg {
  width: 16px;
  height: 16px;
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0s !important;
  }
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  accent-color: var(--lime);
}

input[type="checkbox"],
input[type="radio"],
input[type="range"],
progress,
meter {
  accent-color: var(--lime);
}

button, a {
  touch-action: manipulation;
}

button {
  cursor: pointer;
  border: 0;
  background: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  z-index: 999;
  padding: 10px 18px;
  background: var(--panel);
  color: var(--ink);
  border-radius: 999px;
  font-weight: 500;
}

.skip-link:focus {
  left: 16px;
  top: 16px;
}

.sr,
.sr-only,
.zt-number-live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

/* Common UI controls */
.iconbtn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 500 13px/1 var(--sans);
  cursor: pointer;
  padding: 0;
}

.iconbtn svg {
  width: 18px;
  height: 18px;
}

/* Viewport */
.app-viewport {
  width: 100%;
  max-width: 1392px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  padding: 0 16px 120px;
}

@media (min-width: 840px) {
  .app-viewport {
    padding: 0 28px 120px;
  }
}

/* Header & Topbar — the header sits outside .app-viewport, so it carries the side insets
   itself (mock .ph-surface padding 16px / pick3 .ov-top min-height 44) */
header.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  padding: 14px 16px 10px;
  background: transparent;
  position: relative;
  z-index: 80;
}

@media (min-width: 840px) {
  header.app-topbar {
    padding-left: 28px;
    padding-right: 28px;
  }
}

header.app-topbar .brand-section {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

header.app-topbar .zt-wordmark {
  height: 26px;
  width: auto;
  display: block;
}

/* Mock assets/wordmark-full-{light,dark}.svg: the sign is ink-on-light in the light
   theme and its light counterpart in the dark theme (parity check 18.10: dark header
   wordmark was invisible). One of the two imgs is always display:none. */
header.app-topbar .zt-wordmark-dark {
  display: none;
}

:is([data-theme="dark"], .dark) header.app-topbar .zt-wordmark {
  display: none;
}

:is([data-theme="dark"], .dark) header.app-topbar .zt-wordmark-dark {
  display: block;
}

header.app-topbar .app-title {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
}

.topbar-controls,
.r29-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Mock .ov-top tools: round 40px plates on panel; the hit area stays 44px (owner a11y rule) */
header.app-topbar .tool {
  position: relative;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--panel);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

header.app-topbar .tool svg {
  width: 20px;
  height: 20px;
}

/* Mock .tool u: the Findings count sits on the plate's corner, ink on canvas */
header.app-topbar .tool .findings-count {
  position: absolute;
  right: -3px;
  top: -3px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--canvas);
  font: 500 10px/17px var(--sans);
  text-align: center;
  pointer-events: none;
}

header.app-topbar :is(#syncBtn, #accBtn, .topbar-btn) {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  border: 0;
  background: var(--panel);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  list-style: none;
}

.shell-expense {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--lime);
  color: var(--lime-ink);
  font: 500 13px/1 var(--sans);
  border: 0;
  cursor: pointer;
}

@media (max-width: 839px) {
  body:has(#page-overview.active) .shell-expense {
    display: none;
  }
}

.shell-expense-label {
  display: inline;
  font: inherit;
}

header.app-topbar :is(#askBtn, #proBtn, #syncBtn, .shell-menu > summary) svg {
  width: 20px;
  height: 20px;
}

header.app-topbar .shell-menu > summary::-webkit-details-marker {
  display: none;
}

header.app-topbar .ava,
header.app-topbar .shell-menu > summary {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  list-style: none;
  border-radius: 50%;
  font-weight: 600;
  font-size: 14px;
  background: var(--well);
  color: var(--ink);
}

.shell-menu {
  position: relative;
}

.shell-menu:not([open]) .shell-menu-panel {
  display: none;
}

.shell-menu[open] .shell-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--panel);
  border-radius: 20px;
  box-shadow: 0 12px 32px rgba(17, 17, 17, 0.16);
  padding: 12px;
  min-width: 220px;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
}

/* Clio Glass Bottom Navigation (1:1 with approved reference) */
@media (max-width: 839px) {
  /* focus is never left under the floating dock (WCAG 2.4.11): keyboard focus scrolls the target above it */
  html { scroll-padding-bottom: calc(64px + max(20px, env(safe-area-inset-bottom, 20px)) + 8px); }

  header.app-topbar nav.nav-pill-container {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: max(20px, env(safe-area-inset-bottom, 20px));
    height: 64px;
    padding: 6px;
    display: flex;
    align-items: stretch;
    border-radius: 999px;
    background: var(--glass);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 0 6px 20px rgba(17, 17, 17, 0.12);
    z-index: 80;
    isolation: isolate;
  }

  nav.nav-pill-container .nav-pill-btn {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 44px;
    background: transparent;
    border: 0;
    border-radius: 999px;
    font: 500 11px/1.2 var(--sans);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    z-index: 2;
    text-decoration: none;
    cursor: pointer;
    padding: 4px;
    transition: color var(--fade) var(--ease);
  }

  nav.nav-pill-container .nav-pill-btn.active {
    color: var(--lime-ink);
  }

  nav.nav-pill-container .nav-thumb {
    position: absolute;
    left: 6px;
    top: 6px;
    bottom: 6px;
    background: var(--lime);
    border-radius: 999px;
    transform: translateX(var(--x, 0px));
    width: var(--w, 0px);
    pointer-events: none;
    z-index: 1;
  }
}

@media (min-width: 840px) {
  header.app-topbar nav.nav-pill-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    background: var(--well);
    isolation: isolate;
  }

  nav.nav-pill-container .nav-pill-btn {
    position: relative;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 999px;
    border: 0;
    background: transparent;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    font: 500 14px/1 var(--sans);
    text-decoration: none;
    z-index: 2;
    cursor: pointer;
    transition: color var(--fade) var(--ease);
  }

  nav.nav-pill-container .nav-pill-btn.active {
    color: var(--lime-ink);
  }

  nav.nav-pill-container .nav-thumb {
    position: absolute;
    left: 4px;
    top: 4px;
    bottom: 4px;
    background: var(--lime);
    border-radius: 999px;
    transform: translateX(var(--x, 0px));
    width: var(--w, 0px);
    pointer-events: none;
    z-index: 1;
  }
}

/* Floating Toast */
#zToast.toast-box:not([hidden]) {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(max(20px, env(safe-area-inset-bottom, 20px)) + 76px);
  max-width: 420px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 12px 8px 20px;
  border-radius: 20px;
  background: var(--ink);
  color: var(--panel);
  box-shadow: 0 12px 32px rgba(17, 17, 17, 0.2);
  font: 500 14px/1.3 var(--sans);
  z-index: 85;
}

#zToast button.t-undo {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--lime);
  color: var(--lime-ink);
  font: 600 13px/1 var(--sans);
  cursor: pointer;
  white-space: nowrap;
}

#zToast button.t-undo.t-ext {
  background: color-mix(in srgb, var(--panel) 16%, transparent);
  color: var(--panel);
}

/* Loading skeleton */
#liveLoading,
.live-auth {
  display: none;
}

html[data-source="live"] #liveLoading,
html[data-source="live"] .live-auth {
  position: fixed;
  inset: 0;
  background: var(--canvas);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.entry-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--ink);
}

.entry-loading svg {
  width: 44px;
  height: 44px;
}

/* Route headings receive programmatic focus for screen readers; no visible ring there (keyboard focus elsewhere keeps its ring). */
h1[tabindex="-1"]:focus, h1[tabindex="-1"]:focus-visible { outline: none; }
/* Phone: no lime «+Трата» in the top row — the expense entry lives in the quick actions and the sheet (owner: one lime per screen). */
@media (max-width: 1023.98px) { .shell-expense { display: none; } }

/* W7: cash-flow segments share the phone capsule language. */
#page-cashflow .card .ch:has(.seg) { flex-wrap: wrap; }
#page-cashflow .card .seg { flex-shrink: 0; }
#page-cashflow .card .seg > button {
  white-space: nowrap;
  font-size: 13px;
  padding: 8px 12px;
}
/* The chart positions wide net labels by their centre, like month names. */
#page-cashflow .chart .cfnet { text-align: center; }

/* Shared page header: Overview's title, scope and period key lines on every route. */
.page .page-header {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin: 4px 2px 14px;
  min-width: 0;
}
.page-header-main {
  order: -10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: 74px 50px;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.page-header-leading { display: contents; }
.page-header-main > .page-header-leading > .page-actions { grid-column: 1 / -1; grid-row: 3; }
.page-header-title { grid-column: 1; grid-row: 2; min-width: 0; }
.page-header-title h1 {
  margin: 0;
  color: var(--ink);
  font: 500 26px/1.2 var(--sans);
  letter-spacing: -.6px;
}
.page-header-title .h-sub { display: none; }
.page-header-scope { grid-column: 2; grid-row: 2; }
.page-header-main > .shell-toolbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  width: 100%;
  min-width: 0;
}
@media (min-width: 1024px) {
  .page .page-header { margin: 0 0 16px; }
  .page-header-main {
    grid-template-columns: minmax(0, 1fr) 123px 180px;
    grid-template-rows: minmax(50px, auto);
    align-items: start;
  }
  /* Actions use the free title area, then wrap without moving the fixed scope/period. */
  .page-header-leading {
    grid-column: 1 / 3;
    grid-row: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    min-width: 0;
  }
  .page-header-main:has(.account-scope) > .page-header-leading { grid-column: 1; }
  .page-header-main .page-header-title {
    display: flex;
    align-items: center;
    min-height: 50px;
    max-width: 100%;
  }
  .page-header-scope { grid-row: 1; min-height: 50px; align-content: center; }
  .page-header-scope:empty { display: none; }
  .page-header-main > .shell-toolbar { grid-column: 3; }
  .page-header-main .page-header-leading > .page-actions {
    flex: 0 1 auto;
    width: auto;
    max-width: 100%;
    margin-left: auto;
  }
}

/* Native inner scroll surfaces fade only where content is currently clipped. */
[data-scroll-edges] {
  --scroll-fade-top: 0px;
  --scroll-fade-bottom: 0px;
  mask-image: linear-gradient(to bottom, transparent, #000 var(--scroll-fade-top), #000 calc(100% - var(--scroll-fade-bottom)), transparent);
}
[data-scroll-edges~="top"] { --scroll-fade-top: 28px; }
[data-scroll-edges~="bottom"] { --scroll-fade-bottom: 28px; }
