/* App shell. Rule: the page itself never scrolls — only panels inside it do. */
*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }

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

.sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: fixed; left: 12px; top: -60px; z-index: 100;
  background: var(--amber); color: var(--amber-ink); padding: 8px 14px; border-radius: 8px;
  font-weight: 600; text-decoration: none;
}
.skip:focus { top: 12px; }

.ico {
  width: 1.25em; height: 1.25em; flex: none;
  stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.rail {
  display: flex; flex-direction: column; gap: 6px;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 16px; }
.brand-mark {
  width: 40px; height: 40px; flex: none; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--amber); color: var(--amber-ink);
  font-family: var(--font-head); font-size: 1.7rem; line-height: 1;
}
.brand-name { font-family: var(--font-head); font-size: 1.7rem; line-height: 1; letter-spacing: 0.04em; }
.brand-sub { color: var(--muted); font-size: 0.74rem; }

.hubs { display: grid; gap: 4px; }
.hub {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap); padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-weight: 500;
  border: 1px solid transparent;
}
.hub:hover { background: var(--surface-2); color: var(--ink); }

/* Managers: the number of attendance entries waiting for approval, on People, on the Attendance tab and on the phone menu */
.nbadge {
  display: inline-grid; place-items: center; flex: none;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--amber); color: var(--amber-ink); font-size: 0.7rem; font-weight: 700; line-height: 1;
}
.hub { position: relative; }
.hub .nbadge { margin-left: auto; }
.hub[aria-current="true"] {
  background: var(--amber-soft); color: var(--amber);
  border-color: rgba(242, 169, 59, 0.28);
}

.rail-foot { margin-top: auto; display: grid; gap: 8px; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 0.82rem; }

.main {
  display: grid;
  /* an explicit 0-min column: with the default auto column, a nowrap header (subtitle + search + buttons) stretches the whole page past the window */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0; min-height: 0;
}

.page-head {
  position: relative; z-index: 20; /* lets the search results float over the page below */
  display: flex; align-items: center; gap: 12px;
  padding: 16px var(--gutter) 10px;
}
.page-head .titles { min-width: 0; flex: 1; }
.page-head h1 {
  font-family: var(--font-head); font-weight: 400;
  font-size: 2.1rem; line-height: 1; letter-spacing: 0.03em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.page-head .sub { color: var(--muted); font-size: 0.86rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-actions { display: flex; align-items: center; gap: 8px; }
.head-mobile-brand { display: none; }

/* ---------- page search (header) ---------- */
.gsearch { position: relative; flex: none; width: clamp(200px, 26vw, 300px); }
.gsearch-box { position: relative; }
.gsearch-box .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.gsearch input { min-height: 38px; padding-left: 38px; padding-right: 34px; -webkit-appearance: none; appearance: none; }
.gsearch input:focus { border-color: var(--amber); outline: none; }
.gsearch-kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none;
  min-width: 22px; padding: 1px 6px; text-align: center;
  border: 1px solid var(--line-strong); border-radius: 6px;
  color: var(--muted); font: 500 0.74rem var(--font-mono);
}
.gsearch:focus-within .gsearch-kbd { display: none; }
.head-actions .search-toggle { display: none; } /* phones only; the selector outranks .icon-btn, which loads later */

.gsearch-list {
  position: absolute; top: calc(100% + 6px); right: 0;
  width: max(100%, 380px); max-width: calc(100vw - 2 * var(--gutter));
  max-height: min(60vh, 440px); overflow-y: auto; overscroll-behavior: contain;
  padding: 6px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
.sr-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid transparent;
  text-decoration: none; color: var(--ink);
}
.sr-item.active { background: var(--surface-2); border-color: var(--line-strong); }
.sr-main { display: grid; min-width: 0; }
.sr-label { font-weight: 600; }
.sr-sub { color: var(--muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-item .badge { flex: none; }
.sr-item mark { background: none; color: var(--amber); }
.sr-empty { padding: 14px 12px; color: var(--muted); font-size: 0.9rem; }

.tabs {
  display: flex; gap: 4px; padding: 0 var(--gutter);
  border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none; /* a section with many pages: the tab bar scrolls sideways instead of squeezing them */
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; white-space: nowrap;
  padding: 10px 16px; min-height: 42px; display: inline-flex; align-items: center;
  color: var(--muted); text-decoration: none; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab .nbadge { margin-left: 8px; }
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] { color: var(--amber); border-bottom-color: var(--amber); }

.view {
  position: relative;
  min-height: 0; overflow: hidden;
  padding: 16px var(--gutter) var(--gutter);
  display: flex; flex-direction: column;
  outline: none;
}

.bottombar { display: none; }

/* ---------- tablet: icon rail ---------- */
@media (max-width: 1024px) and (min-width: 721px) {
  :root { --rail-w: 72px; }
  .brand-name, .brand-sub, .hub .lbl, .who .who-text { display: none; }
  .brand { justify-content: center; padding-inline: 0; }
  .hub { justify-content: center; padding: 0; }
  .hub .nbadge { position: absolute; top: 4px; right: 6px; margin: 0; } /* the icon-only rail: the badge sits on the icon's corner */
  .who { justify-content: center; }
}

/* ---------- phone: bottom bar ---------- */
@media (max-width: 720px) {
  :root { --gutter: 14px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .rail { display: none; }
  .page-head { padding-top: calc(10px + env(safe-area-inset-top)); gap: 10px; }
  .page-head h1 { font-size: 1.7rem; }
  .page-head .sub { display: none; }
  .head-mobile-brand { display: grid; width: 34px; height: 34px; border-radius: 10px; font-size: 1.4rem; }
  .head-actions .search-toggle { display: inline-grid; }
  .gsearch { display: none; }
  .gsearch.open { /* the box takes over the header while searching */
    display: block; position: absolute; inset: 0; width: auto; z-index: 2;
    padding: calc(8px + env(safe-area-inset-top)) var(--gutter) 8px; background: var(--bg);
  }
  .gsearch-list { left: var(--gutter); right: var(--gutter); top: 100%; width: auto; max-width: none; }
  .gsearch-kbd { display: none; }
  .tab { flex: 1 0 auto; justify-content: center; padding: 10px 10px; font-size: 0.86rem; }
  .tabs { padding: 0 var(--gutter); }
  .view { padding-bottom: 12px; }

  .bottombar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bhub {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 56px; padding: 6px 2px; color: var(--muted);
    text-decoration: none; font-size: 0.7rem; font-weight: 500;
  }
  .bhub { position: relative; }
  .bhub .nbadge { position: absolute; top: 4px; left: calc(50% + 4px); }
  .bhub .ico { width: 1.4em; height: 1.4em; }
  .bhub[aria-current="true"] { color: var(--amber); }
}

/* Very short screens or heavy zoom: let the page scroll rather than clip content. */
@media (max-height: 480px) {
  html, body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
  .view { overflow: visible; }
}

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

@media print {
  html, body { overflow: visible; height: auto; background: #fff; color: #000; }
  .app { display: block; height: auto; }
  .rail, .tabs, .bottombar, .head-actions, .gsearch, .quickbar, .sale-form, .toasts { display: none !important; }
  .view, .panel, .panel-body { overflow: visible !important; height: auto !important; }
  .panel, .kpi { border-color: #999; background: #fff; }
}
