/* cliv.tech's shared design: colours, sizes, and the controls every app uses.
   This file is the same in every app. Change one copy, then copy it to the
   others. Each app's app.css loads after it, sets --accent, and holds only
   what is its own.

   Sizes come in two sets. A mouse gets the first. A touch screen, or any
   screen 640px wide or less, gets the second: bigger text, 44px controls, and
   16px inputs, so phones don't zoom in on them. Use the variables, not
   numbers, so both sets apply. */

:root {
  color-scheme: dark;
  --bg: #101010;
  --side: #161616;
  --term: #121212;
  --panel: #141414;
  --raised: #1b1b1b;
  --menu: #1f1f1f;
  --text: #f2f2f0;
  --muted: #9a9a96;
  --faint: #6a6a66;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --fill: rgba(255, 255, 255, 0.045);
  --fill-strong: rgba(255, 255, 255, 0.08);
  --well: rgba(0, 0, 0, 0.2);
  --green: #3dd68c;
  --amber: #e6b450;
  --red: #ff6b6b;
  /* Each app sets its own accent. */
  --accent: #f2f2f0;
  /* Text on the accent. A page may pick dark or light to suit the colour. */
  --accent-ink: #161616;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --app-h: 100dvh;

  /* Text. --text-md is body text. */
  --text-2xs: 11px;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
  --text-lg: 15px;
  --text-xl: 18px;
  --text-2xl: 22px;
  --text-3xl: 26px;
  /* Inputs, which phones zoom in on below 16px. */
  --text-input: 14px;

  /* Heights of things you press. */
  --control-lg: 44px;  /* a form's main button, a sign-in button */
  --control-h: 38px;   /* buttons, inputs, selects */
  --control-sm: 32px;  /* small buttons, chips */
  --icon-btn: 38px;    /* square icon buttons, matching --control-h */
  --icon-sm: 28px;     /* icon buttons inside a row: ⋯, ×, a pin */
  --row-h: 34px;       /* a line in a list or menu: folders, menu items */
  --text-btn-h: 28px;  /* a word that acts, like Log out */

  /* Space. --gap sits between controls side by side. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --gap: 8px;
  --field-gap: 14px;   /* between one form field and the next */

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;

  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

@media (pointer: coarse), (max-width: 640px) {
  :root {
    --text-2xs: 12px;
    --text-xs: 13px;
    --text-sm: 14px;
    --text-md: 15px;
    --text-lg: 16px;
    --text-xl: 19px;
    --text-2xl: 24px;
    --text-3xl: 28px;
    --text-input: 16px;

    --control-lg: 48px;
    --control-h: 44px;
    --control-sm: 40px;
    --icon-btn: 44px;
    --icon-sm: 36px;
    --row-h: 44px;
    --text-btn-h: 36px;

    --gap: 10px;
    --field-gap: 16px;
  }
  /* However an app styles a field, a phone mustn't zoom in on it. */
  input:where(:not([type="checkbox"], [type="radio"], [type="color"], [type="range"])), select, textarea { font-size: max(16px, 1em) !important; }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: var(--text-md); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid #d8d8d4; outline-offset: 2px; }
input[type="checkbox"], input[type="radio"] { flex: 0 0 auto; width: 16px; height: 16px; min-height: 0; margin: 0; padding: 0; accent-color: var(--accent); }
@media (pointer: coarse), (max-width: 640px) { input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; } }

.brand { font-size: var(--text-xl); font-weight: 650; letter-spacing: -0.045em; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: var(--text-sm); max-width: 40rem; line-height: 1.45; }
.hint + label, .hint + .split, .hint + .check { margin-top: var(--space-3); }
.side-label { margin: 12px 16px 6px; color: var(--faint); font-size: var(--text-2xs); letter-spacing: 0.08em; text-transform: uppercase; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  flex: 0 0 auto;
  height: var(--control-h);
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius);
  background: #f4f4f2;
  color: #161616;
  font-size: var(--text-md);
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
}
.btn.small { height: var(--control-sm); padding: 0 10px; font-size: var(--text-sm); }
.btn.large { height: var(--control-lg); padding: 0 20px; font-size: var(--text-lg); }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn.accent:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #fff); }
.btn.danger { background: var(--red); color: #1a0b0b; }
.btn.ghost { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn.ghost:hover:not(:disabled) { background: var(--fill); }
.btn:disabled { opacity: 0.45; }
.btn.busy, .btn.busy:disabled { opacity: 0.85; cursor: progress; }
.btn.busy .spinner { width: 12px; height: 12px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: var(--icon-btn);
  height: var(--icon-btn);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: var(--fill); }
.icon-btn.small { width: var(--icon-sm); height: var(--icon-sm); font-size: 16px; }

/* A word that acts, with no box. It still gets a full-height place to press. */
.text-btn {
  display: inline-flex;
  align-items: center;
  min-height: var(--text-btn-h);
  margin-top: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: var(--text-sm);
  text-align: left;
}
.text-btn:hover { color: var(--red); }

.chip { display: inline-flex; align-items: center; height: var(--control-sm); padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 99px; background: transparent; color: var(--muted); font-size: var(--text-sm); }
.chip:hover { color: var(--text); }
.chip.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--field-gap); color: var(--muted); font-size: var(--text-sm); }
/* :where keeps these weak, so an app's own field rules win. */
input:where(:not([type="checkbox"], [type="radio"], [type="color"], [type="range"], [type="file"])), select {
  width: 100%;
  height: var(--control-h);
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--well);
  color: var(--text);
  font-size: var(--text-input);
}
textarea:where(*) { padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--well); color: var(--text); font-family: inherit; font-size: var(--text-input); line-height: 1.5; }
.check { flex-direction: row; align-items: center; gap: var(--space-2); min-height: 28px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-3); }
.form-group { margin: 18px 0 8px; color: var(--text); font-size: var(--text-md); font-weight: 600; }
.form-error { margin: 0 0 8px; color: var(--red); font-size: var(--text-sm); }
.form-error:empty { display: none; }
.form-actions { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--gap); }
.form-actions-end { display: flex; gap: var(--gap); margin-left: auto; }

/* ---------- Dialogs ---------- */
dialog {
  width: min(480px, calc(100vw - 24px));
  max-height: min(760px, calc(var(--app-h) - 24px));
  overflow: auto;
  padding: var(--space-5);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--raised);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.62); }
dialog h2 { margin: 0 0 6px; font-size: var(--text-xl); letter-spacing: -0.03em; }
dialog > .hint { margin: 0 0 var(--space-4); }
dialog[open] { animation: dialog-in 0.18s ease-out; }
dialog[open]::backdrop { animation: fade-in 0.18s ease-out; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; margin: 10px 0 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; flex: 0 0 auto; min-height: var(--control-h); padding: 0 14px; border: 0; background: transparent; color: var(--muted); font-size: var(--text-md); font-weight: 600; }
.tab:hover, .tab.on { color: var(--text); }
.tab.on::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
.tab-panel { min-height: 300px; animation: fade-in 0.15s ease-out; }
.tab-panel a { color: var(--accent); }

/* ---------- Menus ---------- */
.row-menu-backdrop { position: fixed; inset: 0; z-index: 29; }
.row-menu { position: fixed; z-index: 30; min-width: 200px; padding: 5px; border: 1px solid var(--line-strong); border-radius: 11px; background: var(--menu); box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5); animation: pop-in 0.12s ease-out; transform-origin: top left; }
.menu-item { display: flex; align-items: center; justify-content: space-between; gap: 18px; width: 100%; min-height: var(--row-h); padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--text); font-size: var(--text-md); text-align: left; }
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--fill-strong); outline: none; }
.menu-item:disabled { color: var(--faint); cursor: default; }
.menu-item.danger { color: var(--red); }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--line); }
.menu-title { margin: 4px 10px 6px; color: var(--faint); font-size: var(--text-2xs); font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; }

/* ---------- Panels: drawers and sheets ----------
   Each is opt-in by class, so an app takes them one at a time.
   - dialog.drawer: a panel down the right edge, over a dimmed page.
   - dialog.sheet: a dialog on a desktop, a panel up from the bottom on a phone.
   - dialog.full: a dialog on a desktop, the whole screen on a phone.
   - .row-menu.sheet-menu: a menu where it was opened, or a sheet on a phone.
   - .drawer-open and .drawer-scrim: a side panel as a drawer on a phone, set
     by sideDrawer in panels.js, which also slides each of these with a finger.
   - .nav-list > .nav-item: big rows with an icon, for menus in a sheet.
   - .grabber: the handle along a sheet dialog's top edge. A sheet menu draws
     its own, and shows its .sheet-only parts. */
dialog.drawer { display: none; flex-direction: column; width: min(430px, 100vw); height: var(--app-h, 100dvh); max-width: 100vw; max-height: none; margin: 0 0 0 auto; padding: 0; overflow: hidden; border: 0; border-left: 1px solid var(--line-strong); border-radius: 0; background: var(--side); }
dialog.drawer[open] { display: flex; animation: drawer-in 0.22s ease-out; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); padding: 18px var(--space-4) 10px 20px; }
.drawer-head .hint { margin: 2px 0 0; }
.drawer-body { flex: 1; min-height: 0; overflow: auto; padding: 4px 12px 24px 20px; }
.grabber, .sheet-only { display: none; }
.nav-list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.nav-item { display: flex; align-items: center; gap: var(--space-4); width: 100%; min-height: var(--control-lg); padding: 0 var(--space-4); border: 0; border-radius: 99px; background: transparent; color: var(--text); font-size: var(--text-lg); text-align: left; text-decoration: none; }
.nav-item:hover:not(:disabled), .nav-item:focus-visible { background: var(--fill-strong); outline: none; }
.nav-item svg { flex: 0 0 auto; width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.nav-item.danger { color: var(--red); }
.nav-item.danger svg { stroke: currentColor; }
.nav-item[hidden] { display: none; }
@media (max-width: 800px) { dialog.drawer { width: 100vw; border-left: 0; } }
@media (max-width: 640px) {
  dialog.sheet, dialog.full { max-width: 100vw; margin: auto 0 0; border-width: 1px 0 0; }
  dialog.sheet { width: 100vw; max-height: 88dvh; padding: 8px var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom)); border-radius: 20px 20px 0 0; animation: sheet-in 0.22s ease-out; }
  dialog.full { width: 100vw; height: var(--app-h, 100dvh); max-height: none; padding: calc(var(--space-4) + env(safe-area-inset-top)) var(--space-5) 0; border: 0; border-radius: 0; animation: sheet-in 0.22s ease-out; }
  /* Its buttons sit along the bottom, however short the page. */
  dialog.full > form { display: flex; flex-direction: column; min-height: 100%; }
  dialog.full .form-actions { position: sticky; bottom: 0; z-index: 2; margin: auto calc(-1 * var(--space-5)) 0; padding: var(--space-3) var(--space-5) calc(var(--space-3) + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--raised); }
  dialog.sheet .grabber, .sheet-menu::before { content: ""; display: block; width: 36px; height: 4px; margin: 0 auto 12px; border-radius: 4px; background: var(--line-strong); }
  .sheet-menu .sheet-only { display: block; }
  .row-menu.sheet-menu { z-index: 40; top: auto !important; right: 0; bottom: 0; left: 0 !important; width: 100%; max-height: 80dvh; overflow: auto; padding: 8px 8px calc(12px + env(safe-area-inset-bottom)); border-width: 1px 0 0; border-radius: 20px 20px 0 0; animation: sheet-in 0.22s ease-out; }
  .sheet-menu .menu-item { min-height: 52px; padding: 0 var(--space-4); font-size: var(--text-lg); }
  .sheet-menu .menu-title { margin: 0 var(--space-4) 8px; font-size: var(--text-xs); }
  /* Above drawers, which sit at 30. */
  .row-menu-backdrop.dim { z-index: 39; background: rgba(0, 0, 0, 0.5); animation: fade-in 0.18s ease-out; }
  .nav-item { min-height: 52px; }
}
/* A side panel that's a drawer on a phone, from panels.js's sideDrawer: it
   slides over the page from the left, above a dimmed scrim. */
.drawer-open { position: fixed !important; top: 0; bottom: 0; left: 0; z-index: 30; display: flex !important; flex-direction: column; width: min(320px, 86vw) !important; max-width: none; height: var(--app-h, 100dvh); padding-top: env(safe-area-inset-top); overflow: hidden; border-right: 0; border-radius: 0 20px 20px 0; background: var(--side); box-shadow: 12px 0 40px rgba(0, 0, 0, 0.5); animation: drawer-in-left 0.22s ease-out; touch-action: pan-y; }
.drawer-scrim { position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, 0.5); animation: fade-in 0.2s ease-out; }
.drawer-scrim[hidden] { display: none; }
@keyframes drawer-in { from { transform: translateX(40px); opacity: 0; } }
@keyframes drawer-in-left { from { transform: translateX(-100%); } }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }

/* ---------- Toast ---------- */
.toast { pointer-events: none; position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 24px); padding: 12px 16px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--menu); font-size: var(--text-md); }

/* ---------- Status ---------- */
.dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 99px; background: #3c3c3c; }
.dot.ok { background: var(--green); box-shadow: 0 0 0 3px rgba(61, 214, 140, 0.14); }
.dot.syncing, .dot.new { background: var(--amber); }
.dot.error { background: var(--red); }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 99px; animation: spin 0.8s linear infinite; }
.avatar { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 24px; height: 24px; border-radius: 99px; background: #2a2a2a center / cover no-repeat; font-size: var(--text-2xs); font-weight: 650; }
.avatar.lg { width: 64px; height: 64px; font-size: var(--text-2xl); }
.avatar.has-image { color: transparent; }

/* ---------- Signing in happens at auth.cliv.tech ---------- */
.lock { display: none; height: var(--app-h); align-items: center; justify-content: center; padding: var(--space-6); }
.lock-card { display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(340px, 100%); padding: 28px 32px; border: 1px solid var(--line); border-radius: 16px; background: var(--side); text-align: center; }
.lock .brand { font-size: var(--text-2xl); }
.lock-hint { margin: 0; color: var(--muted); font-size: var(--text-md); }
.lock .btn { width: 100%; height: var(--control-lg); }
.lock-home { color: var(--faint); font-size: var(--text-sm); text-decoration: none; }
.lock-home:hover { color: var(--text); }
body.locked .lock { display: flex; }
body.locked .app { display: none; }

/* Notifications in an app's settings (push.js). */
.push-actions { display: flex; flex-wrap: wrap; gap: var(--gap); margin: 4px 0 10px; }
.push-actions [hidden], .push-devices + [hidden] { display: none; }
.push-error:empty { display: none; }
.push-devices { margin: 0 0 6px; padding: 0; list-style: none; max-height: 180px; overflow: auto; }
.push-device { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: var(--text-md); }
.push-device-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.push-device .text-btn { margin: 0; flex: 0 0 auto; }
.push-section { margin: 12px 0 4px; border-top: 1px solid var(--line); padding-top: 8px; }
.push-section > summary { cursor: pointer; padding: 6px 0; font-weight: 600; font-size: var(--text-md); }
.push-device-name small { margin-left: 6px; color: var(--faint); font-size: var(--text-xs); }

/* ---------- Motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.97) translateY(-3px); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
@keyframes breathe { 50% { opacity: 0.5; } }
@media (prefers-reduced-motion: reduce) {
  dialog[open], dialog[open]::backdrop, .row-menu, .row-menu.sheet-menu, dialog.sheet, dialog.full, dialog.drawer[open], .row-menu-backdrop.dim, .drawer-open, .drawer-scrim { animation: none; }
  .spinner { animation-duration: 2.4s; }
}
