/* base.css: reset, global type, focus ring and the responsive shell.
   Colours, spacing, radii and type come only from tokens.css. */

:root {
  /* layout dimensions (not colour/space/type tokens) */
  --nav-h: 68px;
  --header-h: 64px;
  --rail-w: 232px;
  --wrap: 1120px;
}

/* ---------- Reset ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd {
  margin: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: var(--fs-m);
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  line-height: 1.2;
  text-wrap: balance;
}

p,
h1,
h2,
h3,
h4,
h5,
h6,
li,
td,
th {
  overflow-wrap: break-word;
}

img,
picture,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
  text-underline-offset: 3px;
}

[hidden] {
  display: none !important;
}

/* ---------- Focus ---------- */

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Utilities ---------- */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- Shell: mobile first (<720px) ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--header-h);
  padding: calc(var(--space-3) + var(--safe-top)) var(--space-4) var(--space-3);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
}

.app-header > * {
  min-width: 0;
}

/* Fixed bottom tab bar. Height includes the home-indicator inset. */
.app-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: stretch;
  height: calc(var(--nav-h) + var(--safe-bottom));
  margin: 0 auto;
  max-width: 720px;
  padding: var(--space-1) var(--space-3) calc(var(--safe-bottom) + var(--space-1));
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
}

.app-main {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4)
    calc(var(--nav-h) + var(--safe-bottom) + var(--space-6));
  outline: none;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}

.split-list,
.split-detail {
  min-width: 0;
}

/* Offline notice: pinned to the top, under the device inset. */
.offline-banner {
  position: fixed;
  top: var(--safe-top);
  left: 0;
  right: 0;
  z-index: 60;
  padding: var(--space-2) var(--space-4);
  text-align: center;
  font-size: var(--fs-s);
  font-weight: 650;
  background: var(--offered-bg);
  color: var(--offered-fg);
  box-shadow: var(--shadow-1);
}

/* "Updated just now" style status line. */
.live-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.live-status::before {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Shell: tablet (720-959px) ---------- */

@media (min-width: 720px) {
  .app-header {
    padding-left: var(--space-5);
    padding-right: var(--space-5);
  }

  .app-main {
    padding: var(--space-6) var(--space-5)
      calc(var(--nav-h) + var(--safe-bottom) + var(--space-6));
  }
}

/* ---------- Shell: desktop (>=960px), centred column ---------- */

@media (min-width: 960px) {
  /* Header and nav share the same centred column as the main content. */
  .app-header {
    padding: var(--space-2) calc(max(0px, (100% - var(--wrap)) / 2) + var(--space-5));
    min-height: var(--header-h);
  }

  /* Desktop shell: top bar + a left rail. The rail only exists when signed in (the nav is empty otherwise). */
  .app-header {
    padding: var(--space-2) var(--space-5);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  .app-nav {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    right: auto;
    z-index: 20;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: var(--space-1);
    width: var(--rail-w);
    max-width: none;
    height: auto;
    margin: 0;
    padding: var(--space-5) var(--space-3);
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .app-main {
    width: auto;
    margin: 0;
    max-width: none;
    padding: var(--space-6) var(--space-6) var(--space-7);
  }

  body:has(> .app-nav:not(:empty)) .app-main { margin-left: var(--rail-w); }
  .app-main > * { max-width: var(--wrap); margin-left: auto; margin-right: auto; }

  /* Two panes side by side. There is exactly one scroller (the page): no sticky or inner-scrolling panes,
     so the wheel, touch and keyboard all behave the same everywhere. */
  .split {
    grid-template-columns: var(--split-list-w, 380px) minmax(0, 1fr);
    gap: var(--space-5);
    align-items: start;
  }
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* ---------- Integration fixes ---------- */
.app-nav:empty { display: none; }

@media (max-width: 719px) {
}

.page-head { justify-content: space-between; align-items: center; flex-wrap: nowrap; }
.card-link.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
@media (min-width: 960px) { .split-detail .back-link { display: none; } }

@media (max-width: 719px) {
  .qty-big { grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: var(--space-2); }
  .qty-big .qty-num { font-size: var(--fs-xl); }
}

.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
.page-head + .live-status, .page-head ~ .live-status { margin-top: var(--space-2); }
a.card-title { color: inherit; text-decoration: none; }
a.card-title:hover { text-decoration: underline; }
