/* Joseph Eid - Order Tracker
   Palette: the brand dark-green mark, on cool paper. Mobile first. */

:root {
  /* The olive is the accent; --on-brand is whatever text sits on top of it.
     Both flip in dark mode, which is why they travel as a pair. */
  --brand:      #4A5430;
  --brand-dark: #3A4226;
  --brand-soft: #EDF0E1;
  --on-brand:   #ffffff;

  /* The bar across the top keeps its own tokens: in dark mode the accent goes
     pale, and a pale bar with white text on it would be unreadable. */
  --header-bg:   #000000;
  --header-bg-2: #2A3020;   /* only the login gradient, to warm it toward olive */
  --header-ink:  #ffffff;
  --header-ink-2:#B9B9B2;

  --bg:      #ffffff;
  --card:    #ffffff;
  --ink:     #000000;
  --muted:   #6B6B66;
  --line:    #E4E4E1;
  --line-2:  #F4F4F1;

  --danger:  #B4291F;
  --danger-bg: #FBEAE8;
  --warn:    #8A6100;
  --warn-bg: #FBF0DA;

  --live:    #B5CC7A;

  --radius:  14px;
  /* Page and cards are both pure white, so the card edge does the separating. */
  --shadow:  0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  --safe-b:  env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Olive goes pale so it reads on a dark ground, and the text on it goes dark. */
    --brand:      #A3B36A;
    --brand-dark: #8FA057;
    --brand-soft: #232A16;
    --on-brand:   #14180F;

    --header-bg:   #000000;
    --header-bg-2: #222717;
    --header-ink:  #F5F5F3;
    --header-ink-2:#95958E;

    --bg:     #0D0D0C;
    --card:   #171716;
    --ink:    #F5F5F3;
    --muted:  #9A9A94;
    --line:   #2A2A28;
    --line-2: #201F1E;

    --danger:  #EE9C92;
    --danger-bg: #2E1917;
    --warn:    #E3BE79;
    --warn-bg: #2E2510;

    --live:    #A3B36A;

    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Several containers below set display:flex/grid, which would otherwise
   beat the [hidden] attribute. Keep hidden meaning hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

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

input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
textarea { resize: vertical; min-height: 76px; }

label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  min-height: 44px;
}
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:active { background: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:active { background: var(--line-2); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--header-ink-2); }
.btn-danger { background: transparent; border-color: var(--line); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; min-height: 34px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.icon-btn {
  background: none; border: none; cursor: pointer;
  font-size: 26px; line-height: 1; color: var(--muted);
  width: 40px; height: 40px; border-radius: 10px;
}
.icon-btn:active { background: var(--line-2); }

/* ---------- login ---------- */

.login-wrap {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--header-bg-2), var(--header-bg) 55%, var(--header-bg-2));
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--card);
  border-radius: 18px;
  padding: 30px 26px 26px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-mark {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--header-bg); color: var(--header-ink);
  display: grid; place-items: center;
  font-weight: 700; letter-spacing: .04em;
  margin-bottom: 16px;
}
.login-card h1 { font-size: 21px; }
.login-sub { margin: 3px 0 22px; color: var(--muted); font-size: 13px; }
.login-card label { margin-top: 14px; }
.login-card .btn { margin-top: 20px; }

.msg { margin-top: 12px; font-size: 13px; min-height: 18px; color: var(--danger); }
.msg.ok { color: var(--brand); }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--header-bg);
  color: var(--header-ink);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-in {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 11px 14px;
  max-width: 1180px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark {
  background: rgba(255,255,255,.14);
  border-radius: 8px; padding: 4px 8px;
  font-weight: 700; font-size: 13px; letter-spacing: .04em;
}
.brand-text { font-weight: 650; font-size: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.whoami { font-size: 13px; color: var(--header-ink-2); max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--live); flex: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 25%, transparent);
}
.dot.off { background: #D89B7E; box-shadow: 0 0 0 3px rgba(216,155,126,.22); }

/* ---------- search + phase nav ---------- */

/* In dark mode the black bar and the near-black page would otherwise merge. */
.searchbar {
  background: var(--header-bg);
  padding: 0 14px 12px;
  border-bottom: 1px solid var(--line);
}
.searchbar-in {
  display: flex; gap: 8px; align-items: center;
  max-width: 1180px; margin: 0 auto;
}
.searchbar input {
  background: rgba(255,255,255,.13);
  border-color: rgba(255,255,255,.18);
  color: var(--header-ink);
}
.searchbar input::placeholder { color: var(--header-ink-2); }
.searchbar input:focus { background: rgba(255,255,255,.2); border-color: rgba(255,255,255,.5); box-shadow: none; }

.chip {
  flex: none;
  background: rgba(255,255,255,.13);
  border: 1px solid rgba(255,255,255,.18);
  color: var(--header-ink-2);
  border-radius: 10px; padding: 10px 14px;
  cursor: pointer; font-size: 13px; font-weight: 600;
  min-height: 44px;
}
.chip[aria-pressed="true"] {
  background: var(--header-ink);
  color: var(--header-bg);
  border-color: var(--header-ink);
}

/* Pins directly under the top bar, whose height JS measures into --topbar-h.
   The search row above it is allowed to scroll away. */
.phasenav {
  position: sticky; top: var(--topbar-h, 60px); z-index: 20;
  display: flex; gap: 8px;
  overflow-x: auto; scrollbar-width: none;
  padding: 12px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.phasenav::-webkit-scrollbar { display: none; }
.pill {
  flex: none;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.pill .n {
  font-variant-numeric: tabular-nums;
  background: var(--line-2); color: var(--muted);
  border-radius: 999px; padding: 1px 7px; font-size: 12px;
}
.pill[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pill[aria-pressed="true"] .n { background: rgba(255,255,255,.2); color: inherit; }
.pill .swatch { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* ---------- board ---------- */

.wrap { max-width: 1180px; margin: 0 auto; padding: 16px 14px calc(96px + var(--safe-b)); }

.group { margin-bottom: 26px; }
.group-head {
  display: flex; align-items: center; gap: 9px;
  margin: 0 2px 10px;
}
.group-head .swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.group-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.group-head .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.group-head .rule { flex: 1; height: 1px; background: var(--line); }

.cards { display: grid; gap: 10px; }
@media (min-width: 700px) and (max-width: 1039px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}

.col-empty { color: var(--muted); font-size: 13px; margin: 0; padding: 4px 2px 10px; }

/* On a phone a phase with nothing in it is just noise. */
@media (max-width: 1039px) {
  .group.is-empty { display: none; }
}

/* On a laptop the board turns into one column per phase, so the whole
   workshop is visible at once instead of scrolling through it. */
@media (min-width: 1040px) {
  .wrap { max-width: 1600px; }

  /* Sized so all six phases fit across a 1280px laptop without scrolling -
     seeing the whole workshop at once is the point. Wider screens just get
     roomier columns. */
  #board.board-all {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(185px, 1fr);
    gap: 12px;
    align-items: start;
    overflow-x: auto;
    padding-bottom: 10px;
  }
  /* Narrow columns: the price sits under the name rather than fighting it. */
  #board.board-all .card-top { flex-wrap: wrap; gap: 0 8px; }
  #board.board-all .group { margin-bottom: 0; min-width: 0; }
  #board.board-all .cards { grid-template-columns: 1fr; }
  #board.board-all .group-head { margin-bottom: 12px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--phase, var(--line));
  border-radius: var(--radius);
  padding: 13px 15px;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: grid; gap: 3px;
}
.card:active { transform: scale(.995); }
.card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.card-client { font-weight: 650; font-size: 15.5px; }
.card-price { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.card-item { color: var(--muted); font-size: 13.5px; }
.card-meta {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 7px; font-size: 12px;
}
.tag {
  background: var(--line-2); color: var(--muted);
  padding: 2px 8px; border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.tag.due     { background: var(--warn-bg);   color: var(--warn); font-weight: 600; }
.tag.overdue { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.tag.owing   { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.tag.paid    { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty-title { font-size: 17px; font-weight: 650; color: var(--ink); margin: 0 0 6px; }

/* ---------- fab ---------- */

.fab {
  position: fixed; z-index: 40;
  right: 18px; bottom: calc(18px + var(--safe-b));
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--brand); color: var(--on-brand);
  border: none; cursor: pointer;
  font-size: 30px; line-height: 1;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--brand) 45%, transparent);
}
.fab:active { background: var(--brand-dark); }

/* ---------- sheet ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px);
}
.sheet {
  background: var(--bg);
  width: 100%; max-width: 620px;
  max-height: 92dvh;
  border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: .6 } to { transform: none; opacity: 1 } }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; padding: 24px; }
  .sheet { border-radius: 18px; max-height: 88dvh; }
}
.sheet-grab {
  width: 38px; height: 4px; border-radius: 2px;
  background: var(--line); margin: 9px auto 0; flex: none;
}
@media (min-width: 700px) { .sheet-grab { display: none; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 10px 12px 20px; flex: none;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 17px; }
.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 18px 20px calc(24px + var(--safe-b));
}

.field { margin-bottom: 15px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.section-label {
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
  margin: 22px 0 10px;
}

/* stepper */
.stepper { display: grid; gap: 0; margin: 4px 0 4px; }
.step {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 0 0 2px;
}
.step-rail { display: flex; flex-direction: column; align-items: center; flex: none; width: 18px; }
.step-dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--card);
  margin-top: 4px; flex: none;
}
.step-line { width: 2px; flex: 1; min-height: 20px; background: var(--line); }
.step.done .step-dot { background: var(--brand); border-color: var(--brand); }
.step.done .step-line { background: var(--brand); }
.step.current .step-dot {
  background: var(--phase, var(--brand)); border-color: var(--phase, var(--brand));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--phase, var(--brand)) 22%, transparent);
}
.step-label { padding-bottom: 14px; font-size: 14px; color: var(--muted); }
.step.done .step-label, .step.current .step-label { color: var(--ink); }
.step.current .step-label { font-weight: 650; }
.step-when { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.step.skipped .step-label { opacity: .45; font-style: italic; }

.advance { display: grid; gap: 9px; margin-top: 6px; }
.advance .btn { width: 100%; }

.detail-list { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.detail-row {
  display: flex; justify-content: space-between; gap: 14px;
  background: var(--card); padding: 11px 14px; font-size: 14px;
}
.detail-row dt { color: var(--muted); margin: 0; }
.detail-row dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.detail-row dd a { color: var(--brand); font-weight: 600; text-decoration: none; }

.history { display: grid; gap: 9px; }
.hist {
  display: flex; gap: 10px; align-items: baseline;
  font-size: 13px; color: var(--muted);
}
.hist .swatch { width: 8px; height: 8px; border-radius: 50%; flex: none; align-self: center; }
.hist b { color: var(--ink); font-weight: 600; }
.hist time { margin-left: auto; white-space: nowrap; font-size: 12px; }

.sheet-actions { display: flex; gap: 10px; margin-top: 24px; }
.sheet-actions .btn { flex: 1; }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 90;
  left: 50%; transform: translateX(-50%);
  bottom: calc(88px + var(--safe-b));
  background: var(--ink); color: var(--bg);
  padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  max-width: 90vw;
}
