/* =====================================================================
   STAKER COLLINS · FLIP OS V5 — base layer
   All-new design language: deep-violet rail, warm paper canvas,
   shadow-floated cards, editorial type + mono data labels.
   ===================================================================== */

:root {
  /* canvas + ink */
  --paper: #f6f5f2;
  --card: #ffffff;
  --ink: #17141f;
  --ink2: #4b4754;
  --mut: #837e8d;
  --mut2: #b5b1bd;
  --hair: rgba(23, 20, 31, .08);
  --hair2: rgba(23, 20, 31, .055);

  /* brand */
  --brand: #5246e0;
  --brand-deep: #4035c9;
  --brand-ink: #4a3ed1;
  --brand-soft: #edecfb;
  --brand-ring: rgba(82, 70, 224, .22);

  /* rail */
  --rail-bg: #161129;
  --rail-ink: #b7b1cc;
  --rail-hi: #ffffff;
  --rail-line: rgba(255, 255, 255, .09);
  --rail-active: rgba(124, 110, 245, .28);

  /* status */
  --ok: #0e7a4e;     --ok-soft: #e0f4ea;
  --warn: #cf5409;   --warn-soft: #ffeedd;
  --bad: #d23730;    --bad-soft: #fdeae7;
  --info: #2563c4;   --info-soft: #e9f0fb;

  /* geometry */
  --rs: 10px;          /* controls */
  --rc: 18px;          /* cards */
  --rm: 22px;          /* modal */
  --rail-w: 76px;
  --rail-x: 268px;     /* expanded */

  --lift: 0 1px 2px rgba(25, 20, 45, .05), 0 10px 30px -14px rgba(25, 20, 45, .16);
  --lift-lg: 0 2px 6px rgba(25, 20, 45, .07), 0 28px 60px -20px rgba(25, 20, 45, .3);

  --f-ui: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(.23, .7, .25, 1);
}

:root[data-night="on"] {
  --paper: #15131c;
  --card: #1f1c29;
  --ink: #f1eff6;
  --ink2: #c8c4d2;
  --mut: #918c9e;
  --mut2: #5d5969;
  --hair: rgba(255, 255, 255, .1);
  --hair2: rgba(255, 255, 255, .065);

  --brand: #6d61ee;
  --brand-deep: #7d72f4;
  --brand-ink: #a59cf8;
  --brand-soft: rgba(109, 97, 238, .17);
  --brand-ring: rgba(125, 114, 244, .35);

  --rail-bg: #100d1c;
  --rail-ink: #9b94b3;

  --ok: #4cc591;     --ok-soft: rgba(76, 197, 145, .14);
  --warn: #f59d59;   --warn-soft: rgba(245, 157, 89, .14);
  --bad: #f0796f;    --bad-soft: rgba(240, 121, 111, .14);
  --info: #82aef0;   --info-soft: rgba(130, 174, 240, .13);

  --lift: 0 1px 2px rgba(0, 0, 0, .35), 0 12px 32px -14px rgba(0, 0, 0, .55);
  --lift-lg: 0 4px 10px rgba(0, 0, 0, .4), 0 30px 70px -18px rgba(0, 0, 0, .7);
}

/* ============================ base ============================ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 var(--f-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }
::selection { background: var(--brand-ring); }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* micro data label — V5 signature */
.lab {
  font: 600 10.5px/1.3 var(--f-mono);
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--mut);
}

/* mobile/desktop-only helpers */
@media (min-width: 741px) { .m-only { display: none !important; } }
@media (max-width: 740px) { .d-only { display: none !important; } }

/* ============================ shell ============================ */
.shell { min-height: 100vh; min-height: 100dvh; padding-left: var(--rail-w); }

/* ---- rail (dark violet, expands on hover) ---- */
.rail {
  position: fixed; inset: 0 auto 0 0; width: var(--rail-w); z-index: 90;
  background: var(--rail-bg);
  display: flex; flex-direction: column; align-items: stretch;
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  overflow: hidden auto;
  transition: width .26s var(--ease);
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail:hover, .rail.pin { width: var(--rail-x); box-shadow: var(--lift-lg); }
.rail > * { flex-shrink: 0; }

.rail .r-item {
  display: flex; align-items: center; gap: 13px;
  width: 100%; min-height: 46px; padding: 0 14px;
  border-radius: 12px; color: var(--rail-ink);
  font-size: 14.5px; font-weight: 550; white-space: nowrap;
  transition: background .15s var(--ease), color .15s var(--ease);
  text-align: left;
}
.rail .r-item .i { width: 21px; height: 21px; }
.rail .r-item:hover { background: rgba(255, 255, 255, .08); color: var(--rail-hi); }
.rail .r-item.on { background: var(--rail-active); color: var(--rail-hi); }
.rail .r-item .r-lab { opacity: 0; transition: opacity .18s var(--ease); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.rail:hover .r-item .r-lab, .rail.pin .r-item .r-lab { opacity: 1; }
.rail .r-num { opacity: 0; transition: opacity .18s; font: 600 11px/1 var(--f-mono); color: var(--rail-ink);
  background: rgba(255,255,255,.1); border-radius: 99px; padding: 4px 8px; }
.rail:hover .r-num, .rail.pin .r-num { opacity: 1; }

.r-logo { display: flex; align-items: center; gap: 12px; padding: 4px 8px 16px; white-space: nowrap; width: 100%; text-align: left; }
.r-logo .mark { width: 38px; height: 38px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(145deg, #6a5cf0, #4d41dd); color: #fff; }
.r-logo .mark svg { width: 23px; height: 23px; fill: currentColor; }
.r-logo .r-name { opacity: 0; transition: opacity .18s; min-width: 0; }
.rail:hover .r-name, .rail.pin .r-name { opacity: 1; }
.r-logo .r-name b { display: block; color: #fff; font-size: 15px; letter-spacing: -.01em; line-height: 1.2; }
.r-logo .r-name span { display: block; color: var(--rail-ink); font: 600 10px/1.4 var(--f-mono); letter-spacing: .14em; text-transform: uppercase; }

.r-sep { height: 1px; background: var(--rail-line); margin: 12px 8px; }
.r-cap { font: 600 9.5px/1 var(--f-mono); letter-spacing: .16em; text-transform: uppercase; color: rgba(255,255,255,.34);
  padding: 6px 14px 8px; white-space: nowrap; opacity: 0; transition: opacity .18s; }
.rail:hover .r-cap, .rail.pin .r-cap { opacity: 1; }

.r-flip { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 50px; padding: 6px 9px;
  border-radius: 12px; white-space: nowrap; text-align: left;
  transition: background .15s var(--ease); }
.r-flip:hover { background: rgba(255, 255, 255, .08); }
.r-flip.on { background: var(--rail-active); }
.r-flip img { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; flex: none;
  outline: 2px solid rgba(255, 255, 255, .14); }
.r-flip .rf-t, .r-me .rf-t { opacity: 0; transition: opacity .18s; min-width: 0; flex: 1; }
.rail:hover .rf-t, .rail.pin .rf-t { opacity: 1; }
.r-flip .rf-t b { display: block; color: #fff; font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; line-height: 1.3; }
.r-flip .rf-t span { display: block; color: var(--rail-ink); font-size: 11.5px; line-height: 1.3; }

.r-grow { flex: 1 1 auto; min-height: 12px; }

.r-me { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border-radius: 14px;
  white-space: nowrap; text-align: left; background: rgba(255, 255, 255, .06); margin-top: 8px;
  border: 1px solid rgba(255, 255, 255, .07); }
.r-me:hover { background: rgba(255, 255, 255, .12); }
.r-me .ava { width: 36px; height: 36px; flex: none; }
.r-me .rf-t b { display: block; color: #fff; font-size: 14px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; line-height: 1.3; }
.r-me .rf-t span { display: block; color: #cfc9e2; font-size: 11.5px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; }

.ava { border-radius: 99px; display: grid; place-items: center; color: #fff; background: #3c3650;
  font: 700 12px/1 var(--f-ui); width: 32px; height: 32px; overflow: hidden; flex: none; }
.ava img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: inherit; }

/* ============================ header ============================ */
.head {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  min-height: 68px; padding: 12px clamp(18px, 3vw, 36px);
  background: color-mix(in srgb, var(--paper) 84%, transparent);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border-bottom: 1px solid var(--hair2);
}
.head .h-burger { display: none; }
.head .h-search { display: none; }
.head .h-t { flex: 1; min-width: 0; }
.head .h-t .lab { margin-bottom: 1px; }
.head .h-t h1 { font-size: 21px; font-weight: 700; letter-spacing: -.022em; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head .h-acts { display: flex; align-items: center; gap: 10px; }

.finder { position: relative; }
.finder .f-box {
  display: flex; align-items: center; gap: 9px; min-width: 270px; padding: 9px 14px;
  background: var(--card); border: 1px solid var(--hair); border-radius: var(--rs);
  color: var(--mut); box-shadow: var(--lift);
  transition: border-color .15s, box-shadow .15s;
}
.finder .f-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3.5px var(--brand-ring); }
.finder .f-box .i { width: 16px; height: 16px; }
.finder input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--ink); font-size: 14px; }
.finder input::placeholder { color: var(--mut2); }
.finder kbd { font: 600 10px/1 var(--f-mono); color: var(--mut2); border: 1px solid var(--hair); border-radius: 5px; padding: 3px 5px; }
.f-pop { position: absolute; top: calc(100% + 10px); right: 0; width: min(440px, 80vw); max-height: 62vh; overflow-y: auto;
  background: var(--card); border-radius: 16px; box-shadow: var(--lift-lg); border: 1px solid var(--hair2); z-index: 60; padding: 8px; }
.f-pop .fp-cap { padding: 10px 12px 4px; }
.f-pop .fp-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border-radius: 11px; text-align: left; }
.f-pop .fp-row:hover { background: var(--paper); }
.f-pop .fp-row img { width: 40px; height: 30px; border-radius: 7px; object-fit: cover; }
.f-pop .fp-row .gl { width: 36px; height: 36px; border-radius: 10px; background: var(--paper); display: grid; place-items: center; color: var(--mut); }
.f-pop .fp-row b { display: block; font-size: 13.5px; }
.f-pop .fp-row span { display: block; font-size: 12px; color: var(--mut); }
.f-pop .fp-none { padding: 24px; text-align: center; color: var(--mut); font-size: 13.5px; }

/* ============================ buttons ============================ */
.b {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 17px; border-radius: var(--rs);
  font-size: 14px; font-weight: 600; white-space: nowrap;
  background: var(--card); color: var(--ink); border: 1px solid var(--hair);
  box-shadow: var(--lift); transition: all .15s var(--ease);
}
.b .i { width: 16px; height: 16px; }
.b:hover { border-color: var(--mut2); }
.b.pri { background: var(--brand); border-color: transparent; color: #fff; box-shadow: 0 8px 20px -8px var(--brand-ring), var(--lift); }
.b.pri:hover { background: var(--brand-deep); }
.b.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink2); }
.b.ghost:hover { background: rgba(23, 20, 31, .06); color: var(--ink); }
:root[data-night="on"] .b.ghost:hover { background: rgba(255, 255, 255, .08); }
.b.bad { color: var(--bad); background: var(--bad-soft); border-color: transparent; box-shadow: none; }
.b.sm { min-height: 33px; padding: 0 13px; font-size: 13px; border-radius: 9px; }
.b.ic { width: 40px; padding: 0; }
.b.ic.sm { width: 33px; }
.b.full { width: 100%; }

/* ============================ forms ============================ */
.fld { display: flex; flex-direction: column; gap: 7px; }
.fld > .lab { color: var(--ink2); }
.fld input, .fld select, .fld textarea, .tin {
  width: 100%; border: 1px solid var(--hair); background: var(--card); border-radius: var(--rs);
  padding: 10px 13px; font-size: 14.5px; outline: 0;
  transition: border-color .15s, box-shadow .15s;
}
:root[data-night="on"] .fld input, :root[data-night="on"] .fld select,
:root[data-night="on"] .fld textarea, :root[data-night="on"] .tin { background: rgba(255,255,255,.05); }
.fld textarea { resize: vertical; min-height: 78px; }
.fld input:focus, .fld select:focus, .fld textarea:focus, .tin:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3.5px var(--brand-ring); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
/* compact time column · roomy notes column (appointment form) */
.grid2.grid-time { grid-template-columns: minmax(168px, max-content) 1fr; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 13px; }

/* ============================ page canvas ============================ */
.page { padding: clamp(18px, 3vw, 34px); display: none; }
.page.on { display: block; }
.vstack { display: flex; flex-direction: column; gap: 18px; }
.ptitle { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 4px; }
.ptitle h2 { font-size: 24px; font-weight: 700; letter-spacing: -.025em; }
.ptitle .psub { color: var(--mut); font-size: 13.5px; margin-top: 3px; }

/* ============================ responsive shell ============================ */
.veil { position: fixed; inset: 0; z-index: 85; background: rgba(13, 10, 25, .5);
  opacity: 0; pointer-events: none; transition: opacity .2s; }
.shell.rail-open .veil { opacity: 1; pointer-events: auto; }
.dock { display: none; }

@media (max-width: 880px) {
  .shell { padding-left: 0; }
  .rail { transform: translateX(-100%); width: var(--rail-x); transition: transform .26s var(--ease); }
  .shell.rail-open .rail { transform: none; }
  .rail .r-lab, .rail .r-num, .rail .r-cap, .rail .rf-t, .rail .r-name { opacity: 1 !important; }
  .head { min-height: 60px; padding: 10px 12px; gap: 10px; flex-wrap: wrap; }
  .head .h-burger { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; color: var(--ink2); flex: none; }
  .head .h-burger:hover { background: rgba(23,20,31,.06); }
  .head .h-acts { gap: 8px; }
  /* New property collapses to an icon — the dock + page buttons carry the label */
  .head .h-acts > .b.pri { width: 42px; padding: 0; }
  .head .h-acts > .b.pri span { display: none; }
  .head .h-acts > .b.pri .i { width: 19px; height: 19px; }
  /* search collapses behind a toggle */
  .head .h-search { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; color: var(--ink2); flex: none; }
  .head .h-search:hover { background: rgba(23,20,31,.06); }
  .head.s-open .h-search { background: var(--brand-soft); color: var(--brand-ink); }
  .head .finder { display: none; }
  .head.s-open .h-t { display: none; }
  .head.s-open .h-acts { flex: 1; min-width: 0; }
  .head.s-open .h-acts > .b.pri { display: none; }
  .head.s-open .finder { display: block; flex: 1; min-width: 0; order: -1; }
  .head.s-open .f-box { min-width: 0; width: 100%; }
  .finder kbd { display: none; }
  .f-pop { left: 0; right: 0; width: auto; max-height: 50vh; }
  .head .h-t h1 { font-size: 17px; }
  .page { padding: 16px 14px calc(110px + env(safe-area-inset-bottom)); }
  .grid2 { grid-template-columns: 1fr; }
  .grid2.grid-time { grid-template-columns: 1fr; }
  .grid2.keep2 { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .rowflex.spread { flex-wrap: wrap; }
  /* 16px inputs — stops iOS zoom-on-focus */
  .fld input, .fld select, .fld textarea, .tin, .finder input, .amtbox input { font-size: 16px; }

  /* bottom dock */
  .dock {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--card) 90%, transparent);
    backdrop-filter: blur(16px) saturate(1.3);
    -webkit-backdrop-filter: blur(16px) saturate(1.3);
    border-top: 1px solid var(--hair2);
  }
  .dock button { display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--mut); font-size: 10.5px; font-weight: 600; padding: 6px 2px; border-radius: 12px; min-height: 48px; }
  .dock button .i { width: 22px; height: 22px; }
  .dock button.on { color: var(--brand-ink); }
  .dock .dk-add { margin-top: -22px; }
  .dock .dk-add span.ring { width: 52px; height: 52px; border-radius: 99px; display: grid; place-items: center;
    background: var(--brand); color: #fff; box-shadow: 0 10px 24px -8px var(--brand-ring); }
  .dock .dk-add .i { width: 24px; height: 24px; }
}
@media (min-width: 881px) { .veil { display: none; } }

/* ============================ native-app feel ============================ */
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }
* { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
/* UI chrome shouldn't be text-selectable (inputs and page content stay selectable) */
button, .dock, .rail, .tabbar, .segm, .vswitch, .chip, .lab, .pick { -webkit-user-select: none; user-select: none; }
/* tactile press feedback on touch screens */
@media (hover: none) {
  .b:active, .dock button:active, .dk-add:active .ring, .tabu:active, .r-item:active, .r-flip:active,
  .chip:active, .lrow:active, .cg-i:active, .vswitch:active { transform: scale(.96); transition: transform .08s var(--ease); }
}
/* installed (home-screen) mode: content sits under the status bar — pad it out */
@media (display-mode: standalone) {
  .head { padding-top: calc(10px + env(safe-area-inset-top)); }
  .rail { padding-top: calc(14px + env(safe-area-inset-top)); }
  .gate { padding-top: env(safe-area-inset-top); }
}
/* roomier touch targets on phones */
@media (max-width: 620px) {
  .lrow { min-height: 56px; }
  .task-row { padding-top: 13px; padding-bottom: 13px; }
  .tbl tbody tr { padding: 14px 18px 15px; }
  .b.sm { min-height: 38px; }
  .chip { min-height: 28px; }
}

/* swipe-to-dismiss support */
@media (max-width: 880px) {
  .rail { touch-action: pan-y; }
  .veil { touch-action: none; }
}
