/* =========================================================================
   layout.css — reset, typography, app shell, navigation, page grids
   All colour / radius / shadow / font / motion values come from theme.css.
   Breakpoints: base = phone · 640 = large phone · 768 = tablet
                1024 = laptop (sidebar appears) · 1440 = wide desktop
   ========================================================================= */

/* ---------------------------------------------------------------- reset -- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--tp-canvas);
  color: var(--tp-ink);
  font-family: var(--tp-font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--tp-font-display);
  font-style: italic;
  font-weight: var(--tp-w-display);
  letter-spacing: var(--tp-track-display);
  text-transform: var(--tp-case-display);
  line-height: 1.04;
}

p { margin: 0; }

img, svg, canvas { display: block; max-width: 100%; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input, select, textarea { font: inherit; color: inherit; }

a { color: inherit; text-decoration: none; }

ul { margin: 0; padding: 0; list-style: none; }

:focus-visible {
  outline: 2px solid var(--tp-acc);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ----------------------------------------------------------- type scale -- */
.display-hero {
  font-family: var(--tp-font-display);
  font-style: italic;
  font-weight: var(--tp-w-display);
  font-size: clamp(3rem, 13vw, var(--tp-hero));
  letter-spacing: var(--tp-track-display);
  text-transform: var(--tp-case-display);
  line-height: .92;
}

.display-lg { font-size: clamp(1.75rem, 6vw, 2.5rem); }
.display-md { font-size: clamp(1.25rem, 4.4vw, 1.6rem); }
.display-sm { font-size: 1.05rem; }

.mono {
  font-family: var(--tp-font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.eyebrow {
  font-family: var(--tp-font-mono);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--tp-mute);
}

.muted { color: var(--tp-mute); }
.ink-acc { color: var(--tp-acc); }
.ink-acc-2 { color: var(--tp-acc-2); }
.ink-ok { color: var(--tp-ok); }
.ink-warn { color: var(--tp-warn); }
.ink-danger { color: var(--tp-danger); }

/* ------------------------------------------------------------ app shell -- */
.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
}

.app-shell[hidden] { display: none; }
.app-shell > .tp-fx { position: fixed; inset: 0; }

.sidebar {
  display: none;
  flex: 0 0 248px;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.25rem 1rem;
  background: var(--tp-surf);
  border-right: var(--tp-bw) solid var(--tp-line);
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .25rem .5rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: var(--tp-r-sm);
  background: var(--tp-grad);
  color: var(--tp-acc-ink);
  font-size: 1.15rem;
}

.brand-name {
  font-family: var(--tp-font-display);
  font-style: italic;
  font-weight: var(--tp-w-display);
  font-size: 1.3rem;
  letter-spacing: var(--tp-track-display);
  text-transform: var(--tp-case-display);
  line-height: 1;
}

.brand-sub {
  display: block;
  font-family: var(--tp-font-mono);
  font-size: .6rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--tp-mute);
}

.nav-group-label {
  font-family: var(--tp-font-mono);
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--tp-mute);
  padding: 0 .6rem .5rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem .7rem;
  border-radius: var(--tp-r-sm);
  border-left: 3px solid transparent;
  color: var(--tp-mute);
  font-weight: 600;
  font-size: .92rem;
  transition: background var(--tp-dur) var(--tp-ease),
              color var(--tp-dur) var(--tp-ease),
              transform var(--tp-dur) var(--tp-ease);
}

.nav-item i { width: 1.15rem; text-align: center; font-size: .95rem; }
.nav-item:hover { background: var(--tp-surf-2); color: var(--tp-ink); }
.nav-item:active { transform: scale(var(--tp-press)); }

.nav-item.active {
  background: var(--tp-acc-plate);
  border-left-color: var(--tp-acc);
  color: var(--tp-acc);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding-top: 1rem;
  border-top: var(--tp-bw) solid var(--tp-line);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 0;
  flex: 1;
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 50%;
  background: var(--tp-acc-2-plate);
  color: var(--tp-acc-2);
  font-family: var(--tp-font-display);
  font-style: italic;
  font-weight: var(--tp-w-display);
  font-size: 1rem;
}

.user-meta { min-width: 0; }

.user-meta strong {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-meta small {
  display: block;
  font-size: .7rem;
  color: var(--tp-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --------------------------------------------------------- main column -- */
.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem .9rem;
  background: color-mix(in oklab, var(--tp-canvas) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: var(--tp-bw) solid var(--tp-line);
}

.topbar-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.topbar-title h1 {
  font-size: 1.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title .eyebrow { display: none; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: .45rem;
  flex: 0 0 auto;
}

.pages {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 1rem .9rem 2rem;
}

.page { display: none; }
.page.active { display: block; animation: tp-fade var(--tp-dur-slow) var(--tp-ease) both; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: 1rem;
}

.page-head h2 { font-size: clamp(1.5rem, 5vw, 2rem); }

/* -------------------------------------------------------------- grids --- */
.grid {
  display: grid;
  gap: .85rem;
  grid-template-columns: minmax(0, 1fr);
}

.grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: minmax(0, 1fr); }
.grid-3 { grid-template-columns: minmax(0, 1fr); }
.grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.span-all { grid-column: 1 / -1; }

/* ------------------------------------------------- mobile bottom tabs --- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: .1rem;
  padding: .35rem .35rem calc(.35rem + env(safe-area-inset-bottom, 0px));
  background: color-mix(in oklab, var(--tp-surf) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: var(--tp-bw) solid var(--tp-line);
}

.tab-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .18rem;
  min-height: 48px;
  padding: .3rem .15rem;
  border-radius: var(--tp-r-sm);
  color: var(--tp-mute);
  font-size: .62rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  transition: color var(--tp-dur) var(--tp-ease),
              background var(--tp-dur) var(--tp-ease),
              transform var(--tp-dur) var(--tp-ease);
}

.tab-item i { font-size: 1.05rem; }
.tab-item:active { transform: scale(var(--tp-press)); }

.tab-item.active {
  color: var(--tp-acc);
  background: var(--tp-acc-plate);
}

/* -------------------------------------------------- sheet + scrim ------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: color-mix(in oklab, var(--tp-bg) 70%, transparent);
  backdrop-filter: blur(2px);
  animation: tp-fade var(--tp-dur) var(--tp-ease) both;
}

.scrim[hidden] { display: none; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  padding: .5rem .9rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  background: var(--tp-surf);
  border-top: var(--tp-bw) solid var(--tp-line);
  border-radius: var(--tp-r-lg) var(--tp-r-lg) 0 0;
  box-shadow: var(--tp-sh);
  animation: tp-sheet var(--tp-dur-slow) var(--tp-ease) both;
}

.sheet[hidden] { display: none; }

.sheet-grip {
  width: 42px;
  height: 4px;
  margin: .25rem auto .85rem;
  border-radius: 999px;
  background: var(--tp-line);
}

.sheet-title {
  font-size: 1.1rem;
  margin-bottom: .6rem;
}

.sheet-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
}

/* -------------------------------------------------------- wide layout --- */
@media (min-width: 640px) {
  body { font-size: 15.5px; }

  .grid { gap: 1rem; }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .pages { padding: 1.25rem 1.25rem 2.5rem; }
  .topbar { padding: .7rem 1.25rem; }
  .topbar-title h1 { font-size: 1.3rem; }
}

@media (min-width: 768px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
  .sidebar { display: flex; }
  .tabbar { display: none; }

  .main { padding-bottom: 0; }

  .topbar {
    padding: .85rem 1.75rem;
    background: transparent;
    backdrop-filter: none;
  }

  .topbar-title h1 { font-size: 1.55rem; }
  .topbar-title .eyebrow { display: block; }

  .pages { padding: 1.5rem 1.75rem 3rem; }

  .grid { gap: 1.15rem; }

  .dashboard-layout { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
  .control-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .auto-layout { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
  .split-aside { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
}

@media (min-width: 1440px) {
  .sidebar { flex-basis: 268px; }
  .grid { gap: 1.25rem; }
}
