/**
 * app.css — base reset, the phone shell, bottom nav, screen header chrome
 * (site label, hero, avatar, iOS back), the week strip, and shared primitives
 * (pills, section labels, toast). Page-specific styles live in their own files.
 */

*{box-sizing:border-box}
html,body{margin:0}
body{background:var(--ground);font-family:var(--sans);color:var(--ink);-webkit-font-smoothing:antialiased;
  min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px}
button{font-family:inherit;cursor:pointer;border:none;background:none;color:inherit;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent}
input{font-family:inherit}
.tnum{font-variant-numeric:tabular-nums;font-family:var(--mono)}

/* phone shell (framed on desktop, full-bleed on a phone) */
.phone{width:400px;max-width:100%;height:min(860px,100vh - 40px);background:var(--paper);border-radius:34px;
  box-shadow:var(--shadow-lg), 0 0 0 10px var(--frame);overflow:hidden;display:flex;flex-direction:column;position:relative;
  -webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent}
.phone input:not(:disabled){-webkit-user-select:text;user-select:text}
@media (max-width:440px){ body{padding:0} .phone{border-radius:0;height:100vh;box-shadow:none} }

.scroll{flex:1;overflow-y:auto;-webkit-overflow-scrolling:touch;scrollbar-width:none;-ms-overflow-style:none}
.scroll::-webkit-scrollbar{display:none;width:0;height:0}
.pad{padding:calc(62px + env(safe-area-inset-top)) 22px calc(104px + env(safe-area-inset-bottom))}
.pad.col{display:flex;flex-direction:column;min-height:100%}
.pf-spacer{flex:1;min-height:14px}

/* sticky frosted top bar (holds brand bar on top-level screens, back link on sub-screens);
   fixed height so brand & back centre identically */
.tnav{position:absolute;left:0;right:0;top:0;z-index:40;display:flex;align-items:center;box-sizing:border-box;
  height:calc(54px + env(safe-area-inset-top));border-radius:34px 34px 0 0;padding:env(safe-area-inset-top) 22px 0;
  background:color-mix(in srgb,var(--paper) 20%,transparent);-webkit-backdrop-filter:blur(25px);backdrop-filter:blur(25px)}
@media (max-width:440px){.tnav{border-radius:0}}
.tnav .brandbar{margin:0;width:100%} .tnav .iosback{margin:0;font-size:14.5px}

/* brand bar — logo + product name + customer */
.brandbar{display:flex;align-items:center;gap:9px;margin:2px 0 14px;min-height:22px}
.brandbar .logo{display:flex;flex:none} .brandbar .logo svg{height:22px;width:auto;flex:none;display:block}
.brandbar .brandname{font-size:14.5px;font-weight:600;letter-spacing:-.2px;color:var(--brand)}
@media (prefers-color-scheme:dark){.brandbar .brandname{color:var(--accent)}}
:root[data-theme="dark"] .brandbar .brandname{color:var(--accent)} :root[data-theme="light"] .brandbar .brandname{color:var(--brand)}
.brandbar .cust{margin-left:auto;font-size:14.5px;font-weight:600;color:var(--muted);letter-spacing:.2px}

/* bottom nav — frosted, floats over content */
.bnav{position:absolute;left:0;right:0;bottom:0;display:flex;justify-content:space-around;align-items:center;
  background:color-mix(in srgb, var(--paper) 20%, transparent);
  -webkit-backdrop-filter:blur(25px);backdrop-filter:blur(25px);
  padding:8px 8px calc(8px + env(safe-area-inset-bottom))}
.bnav button{display:flex;flex-direction:column;align-items:center;gap:6px;padding:8px 20px;border-radius:12px;color:var(--ink-2);font-size:11px;font-weight:700}
.bnav button .ic{line-height:0;position:relative}
.bnav button .ic svg{width:18px;height:18px;display:block}
.bnav button.on{color:var(--ink)}
.bnav button .badge{position:absolute;top:-7px;left:100%;margin-left:-9px;background:var(--crit);color:#fff;font-size:10px;font-weight:800;min-width:16px;height:16px;border-radius:8px;display:grid;place-items:center;padding:0 4px}

/* screen header — centered site label, then title + avatar row */
.siteover{font-size:12.5px;font-weight:700;color:var(--muted);letter-spacing:.2px;text-align:center;margin:2px 0 14px}
.avatar{width:46px;height:46px;border-radius:50%;flex:none;background:var(--surface);box-shadow:0 1px 2px rgba(16,32,54,.04);
  color:var(--ink);font-weight:700;font-size:15px;display:grid;place-items:center;letter-spacing:.3px}
.avatar:active{transform:scale(.95)}
.hero{padding:14px 2px 0}
.hero .titlerow{display:flex;align-items:center;gap:12px}
.hero .titlerow .t{flex:1;min-width:0}
.hero .t{font-size:34px;font-weight:800;letter-spacing:-1.1px;line-height:1}
.hero .dt{color:var(--muted);font-size:13.5px;margin-top:8px;font-weight:600}

/* iOS back — chevron + label, one tap target; lighter tint in dark mode */
.iosback{display:inline-flex;align-items:center;gap:6px;color:var(--brand);font-size:16px;font-weight:600;padding:8px 6px 8px 0;margin:2px 0 20px;line-height:1}
@media (prefers-color-scheme:dark){ .iosback{color:var(--accent)} }
:root[data-theme="dark"] .iosback{color:var(--accent)}
:root[data-theme="light"] .iosback{color:var(--brand)}
.iosback .chev{width:19px;height:19px;display:block;flex:none}
.iosback:hover{opacity:.75}

/* week strip — square day tiles */
.week{display:grid;grid-template-columns:repeat(7,1fr);gap:8px;margin:22px 0 0}
.wd{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;aspect-ratio:1;border-radius:14px;background:none;border:1px solid var(--line-2)}
.wd .l{font-size:11px;color:var(--muted);font-weight:800;text-transform:uppercase;letter-spacing:.3px}
.wd .n{font-size:16px;font-weight:700}
.wd.today{background:var(--brand);border-color:var(--brand)}
.wd.today .l{color:rgba(255,255,255,.82)} .wd.today .n{color:#fff}
.wd.future .l, .wd.future .n{color:var(--faint)}
.wd.sel:not(.today){border-color:var(--brand);border-width:2px;background:var(--surface-2)}
.wd:not(.today):hover{background:var(--surface-2)}

/* shared primitives */
.grp{font-size:11px;text-transform:uppercase;letter-spacing:.6px;color:var(--muted);font-weight:800;margin:22px 2px 12px}
.foot-note{font-size:11.5px;color:var(--muted);text-align:center;margin-top:8px}
.ro-note{display:flex;align-items:center;gap:8px;background:var(--surface-2);border:none;color:var(--ink-2);
  font-size:12.5px;font-weight:600;padding:10px 13px;border-radius:12px;margin:0}
.ro-note .lnk{color:var(--brand);font-weight:800;background:none;border:none;padding:0;cursor:pointer;font-size:inherit;font-family:inherit;text-decoration:underline}
.pill{display:inline-flex;align-items:center;gap:5px;font-size:12px;font-weight:800;padding:6px 12px;border-radius:20px;letter-spacing:.2px}
.pill.ok{background:var(--ok-wash);color:var(--ok-ink)} .pill.warn{background:var(--warn-wash);color:var(--warn-ink)}
.pill.crit{background:var(--crit-wash);color:var(--crit-ink)} .pill.info{background:var(--info-wash);color:var(--info)} .pill.due{background:var(--due-wash);color:var(--due-ink)} .pill.na{background:var(--line-2);color:var(--muted)}

.toast{position:absolute;left:16px;right:16px;bottom:82px;background:var(--frame);color:#fff;padding:12px 16px;border-radius:13px;
  font-weight:700;font-size:13.5px;text-align:center;box-shadow:var(--shadow-lg);opacity:0;transform:translateY(10px);transition:.26s;pointer-events:none;z-index:30}
.toast.show{opacity:1;transform:translateY(0)}

/* loading spinner — centered placeholder while a section's API data loads; size via --spinner-size (createSpinner()'s argument) */
/* height:100% + flex:1 center it in the parent's own box (flex column or a sized block) instead of just top-packing at content height */
.spinner-wrap{display:flex;align-items:center;justify-content:center;width:100%;height:100%;flex:1;min-height:120px;padding:24px 0;box-sizing:border-box}
.spinner{width:var(--spinner-size,28px);height:var(--spinner-size,28px);border-radius:50%;
  border:calc(var(--spinner-size,28px) * .12) solid var(--line);border-top-color:var(--accent);
  animation:spin .7s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
@media (prefers-reduced-motion:reduce){.spinner{animation-duration:1.6s}}

@media (prefers-reduced-motion:reduce){*{transition:none!important}}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}

/* ─────────────────────────────────────────────────────────────────────────
   RESPONSIVE SHELL
   Base (mobile) = phone layout. The .sidebar collapses (its #tnav/#bnav are
   absolutely positioned to .phone) and .main fills the middle. Avoid
   display:contents here — it breaks tap hit-testing on descendants in mobile
   Safari/WebKit. Desktop turns these into a real left sidebar.
   ───────────────────────────────────────────────────────────────────────── */
.sidebar{display:block}
.main{display:flex;flex-direction:column;flex:1 1 auto;min-height:0}

/* mobile / PWA: the sidebar restructure puts #bnav before the content in the DOM;
   lift the bottom nav above the positioned cards so it can't be painted over. */
@media (max-width:759px){ .bnav{z-index:45} }

/* desktop / large-tablet: real left-sidebar shell (Claude/ChatGPT style) */
@media (min-width:760px){
  body{padding:0;background:var(--paper)}
  .phone{width:100%;max-width:100%;height:100vh;height:100dvh;border-radius:0;box-shadow:none;
    background:var(--paper);display:flex;flex-direction:row}

  .sidebar{display:flex;flex-direction:column;width:232px;flex:none;height:100dvh;
    background:var(--surface);border-right:1px solid var(--line)}
  .main{display:block;flex:1 1 auto;min-width:0;height:100dvh;overflow:hidden}

  /* brand row — fixed height so the persistent brand never shifts */
  .tnav{position:static;height:52px;flex:none;margin-top:10px;border-radius:0;padding:0 18px 0 25px;
    z-index:1;display:flex;align-items:center;background:none;border:none;box-shadow:none;
    -webkit-backdrop-filter:none;backdrop-filter:none}
  .tnav .brandbar{width:100%;margin:0;gap:12px}
  .tnav .brandbar .logo{width:19px;flex:none;display:flex;align-items:center;justify-content:center}
  .tnav .brandbar .logo svg{width:19px;height:17px}
  .tnav .brandbar .cust{display:none}          /* company shown in the sidebar foot instead */

  /* vertical nav (icons kept), active = accent pill */
  .bnav{position:static;height:auto;width:auto;flex-direction:column;align-items:stretch;
    justify-content:flex-start;padding:6px 12px;gap:2px;background:none;border:none;border-radius:0;
    box-shadow:none;-webkit-backdrop-filter:none;backdrop-filter:none}
  .bnav button{flex:0 0 auto;flex-direction:row;justify-content:flex-start;gap:12px;width:100%;
    height:auto;padding:11px 13px;border-radius:10px;font-size:14px;position:relative}
  .bnav button .ic{display:inline-flex;position:relative}
  .bnav button .ic svg{width:19px;height:19px}
  .bnav button.on{background:var(--accent-wash);color:var(--accent)}
  .bnav button .badge{top:-5px;left:13px}

  /* profile foot: company label above the avatar button */
  .sidefoot{margin-top:auto;display:flex;flex-direction:column;align-items:flex-start;gap:10px;
    padding:14px 16px;border-top:1px solid var(--line)}
  .sidefoot:empty{display:none}
  .sidefoot .cust{margin:0;padding:0;background:none;text-transform:none;letter-spacing:0;
    font-size:12.5px;font-weight:700;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%}
  .sidefoot .avatar{margin:0;width:38px;height:38px;font-size:13px;flex:none;
    background:var(--accent-wash);color:var(--accent);box-shadow:inset 0 0 0 1px var(--line)}

  /* main content column — centered, component-aware grid (not a uniform stretch) */
  .scroll{flex:1;height:100%}
  .pad{padding:26px 34px 44px;max-width:840px;margin-inline:auto;
    display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:12px 16px;align-content:start}
  .pad.col{display:flex;flex-direction:column}      /* profile / report / detail stay single-column */
  .pad > *{grid-column:1 / -1}                        /* full-width by default */
  .pad > .iosback{margin:2px 0 14px}                  /* the back link moved into content */

  /* fixed-size components must not stretch */
  .pad > .week{max-width:440px}
  .pad > .sumrow{max-width:560px}
  .pad > .periods{max-width:560px}
  .pad > .search{max-width:560px}

  /* per-role: which card rows flow into columns (scoped; class names collide across roles) */
  body[data-role="operator"] .items{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:14px;margin-top:12px}
  body[data-role="operator"] .pad > .tick,
  body[data-role="operator"] .pad > .prow{grid-column:auto}

  body[data-role="manager"] .pad > .tick,
  body[data-role="manager"] .pad > .crow,
  body[data-role="manager"] .pad > .srow,
  body[data-role="manager"] .pad > .scard,
  body[data-role="manager"] .pad > .prow{grid-column:auto}

  body[data-role="admin"] .pad > .acard,
  body[data-role="admin"] .pad > .erow2,
  body[data-role="admin"] .pad > .crow{grid-column:auto}

  body[data-role="super"] .pad > .acard,
  body[data-role="super"] .pad > .erow2{grid-column:auto}
}
