/*
   Repair Shop Order Tracker - shared components (Team 02)
   Needs tokens.css first.
   Every service's screens reuse these classes - don't restyle them per page;
   page-specific layout goes in pages.css.

   Contents
     0. Utilities            5. Feedback (toast, banner, dialog, empty, skeleton, note)
     1. Brand mark           6. Data (panel, stat, timeline, quote table, data table)
     2. Badges + priority    7. Staff app shell (sidebar, top bar, filters)
     3. Buttons              8. Customer portal (mobile-first)
     4. Form fields
 */


/* 0. Utilities */
.muted { color: var(--ink-2); }
.small { font-size: var(--fs-meta); }
.red   { color: var(--danger); }
.b     { font-weight: 600; }
.num   { font-family: var(--mono); text-align: right; white-space: nowrap; } /* money, counts */

/* Hidden on screen but still read by screen readers (e.g. a label for an icon-only button). */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Inline SVG line icons: 1.5px stroke, colour follows the text. */
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }


/* 1. Brand mark ("RS" square with gold underline) */
.brand { display: flex; gap: var(--s3); align-items: center; }
.brand-name { font-weight: 600; font-size: 15px; }
.mark {
  display: inline-grid; place-items: center; flex: none;
  width: 30px; height: 30px; font-size: 12px;
  background: var(--accent); color: var(--on-accent);
  font-family: var(--mono); font-weight: 500;
  border-radius: var(--radius); border-bottom: 3px solid var(--gold);
}
.mark.xs { width: 24px; height: 24px; font-size: 10px; border-bottom-width: 2px; }


/* 2. Badges (status = tint + dot + text, never colour alone) */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 9px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-small); font-weight: 500; white-space: nowrap;
  color: var(--st-received); background: var(--st-received-bg); /* default */
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Keyed on the EXACT database status value - ui.js sets data-status="..." and the label. */
.badge[data-status="received"]            { color: var(--st-received);        background: var(--st-received-bg); }
.badge[data-status="diagnosing"]          { color: var(--st-diagnosing-text); background: var(--st-diagnosing-bg); }
.badge[data-status="awaiting_approval"]   { color: var(--st-awaiting);        background: var(--st-awaiting-bg); }
.badge[data-status="in_repair"]           { color: var(--st-repair);          background: var(--st-repair-bg); }
.badge[data-status="ready_for_pickup"]    { color: var(--st-ready);           background: var(--st-ready-bg); }
.badge[data-status="collected"]           { color: var(--st-collected);       background: var(--st-collected-bg); }
.badge[data-status="returned_unrepaired"],
.badge[data-status="cancelled"]           { color: var(--st-stopped);         background: var(--st-stopped-bg); }

/* Notification statuses (Service 2) reuse the same colour families. */
.badge[data-status="queued"] { color: var(--st-received); background: var(--st-received-bg); }
.badge[data-status="sent"]   { color: var(--st-ready);    background: var(--st-ready-bg); }
.badge[data-status="failed"] { color: var(--st-stopped);  background: var(--st-stopped-bg); }

/* Overdue = red OUTLINE badge (white inside) so it never looks like "Cancelled". */
.badge.overdue  { color: var(--danger); background: var(--surface); box-shadow: inset 0 0 0 1px var(--danger); }
/* Warranty = purple with a square dot. */
.badge.warranty { color: var(--warranty); background: var(--warranty-bg); }
.badge.warranty::before { border-radius: 1px; }
.badge.xs { height: 18px; font-size: 11px; padding: 0 6px; margin-left: var(--s1); }

/* Priority: small coloured square + the word (High / Medium / Low). */
.pri { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-small); font-weight: 500; }
.pri::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--priority-low); }
.pri[data-priority="High"]::before   { background: var(--priority-high); }
.pri[data-priority="Medium"]::before { background: var(--priority-medium); }
.pri[data-priority="Low"]::before    { background: var(--priority-low); }


/* 3. Buttons (always <button>, never a styled <div> or <a>) */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 38px; padding: 0 var(--s4);
  font-weight: 500; white-space: nowrap; cursor: pointer;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  transition: background-color .12s, border-color .12s;
}
.btn:hover { background: var(--canvas); }

/* ONE primary button per screen - the single main action. */
.btn.primary { color: var(--on-accent); background: var(--accent-btn); border-color: var(--accent-btn); }
.btn.primary:hover { background: var(--accent-btn-hover); border-color: var(--accent-btn-hover); }
.btn.primary:active { background: var(--accent-btn-active); border-color: var(--accent-btn-active); }

.btn.danger { color: var(--danger); border-color: var(--danger-border); }
.btn.danger:hover { background: var(--danger-tint); }

.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--sunken); }

.btn.sm    { height: 30px; padding: 0 var(--s3); font-size: var(--fs-meta); }
.btn.block { width: 100%; }

/* Disabled (and while a request is running - ui.js sets disabled + "Saving..."). */
.btn:disabled, .btn:disabled:hover { opacity: .55; cursor: not-allowed; }
.btn.primary:disabled:hover { background: var(--accent-btn); }
.btn[aria-busy="true"] { cursor: progress; }

.btn-row { display: flex; gap: var(--s2); flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }


/* 4. Form fields (label ABOVE input, required marker, hint/error below) */
/* Markup:
   <div class="field">
     <label for="phone">Customer phone <em>*</em></label>
     <input id="phone" name="phone" required aria-describedby="phone-hint">
     <small class="field-hint" id="phone-hint">e.g. 01012345678</small>
   </div>
   On error ui.js adds .has-error + aria-invalid="true" and puts the backend message in the hint. */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s3); }
.field > label { font-size: var(--fs-meta); font-weight: 500; }
.field em { color: var(--accent); font-style: normal; } /* required * - aria: the input has "required" */

.input, .field input, .field select, .field textarea {
  width: 100%; height: 40px; padding: 0 var(--s3);
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.field textarea { height: auto; min-height: 88px; padding: 10px var(--s3); resize: vertical; line-height: 1.5; }
.field input::placeholder, .field textarea::placeholder { color: var(--ink-2); opacity: 1; }

.input:focus, .field input:focus, .field select:focus, .field textarea:focus,
.filters select:focus {
  outline: 2px solid transparent;
  border-color: var(--accent); box-shadow: var(--focus);
}

.field-hint { color: var(--ink-2); font-size: var(--fs-small); }
.field.has-error input, .field.has-error select, .field.has-error textarea,
[aria-invalid="true"] { border-color: var(--danger); }
.field.has-error .field-hint { color: var(--danger); }

/* Form sections (New order, Add technician): fieldsets with a small caps legend, two-column grid. */
.form-group { margin: 0 0 var(--s3); padding: 0; border: 0; }
.form-group + .form-group { padding-top: var(--s3); border-top: 1px solid var(--line); }
.form-group legend {
  padding: 0; margin-bottom: var(--s2);
  font-size: 12px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: var(--s4); }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
}


/* 5. Feedback */

/* Toasts: dark, bottom-right, auto-hide after 4s (ui.js). Shadow allowed (it floats). */
.toast-stack {
  position: fixed; right: var(--s5); bottom: var(--s5); z-index: 100;
  display: flex; flex-direction: column; gap: var(--s2);
  width: min(360px, calc(100vw - 2 * var(--s4)));
}
.toast {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--s3) 14px;
  color: var(--on-ink); background: var(--ink);
  border-radius: var(--radius); border-left: 4px solid var(--toast-ok);
  box-shadow: var(--shadow-pop);
  animation: toast-in .16s ease-out;
}
.toast span { color: var(--toast-sub); font-size: var(--fs-meta); }
.toast.err  { border-left-color: var(--toast-err); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Banner: page-level message that stays (e.g. "2 notifications failed"). */
.banner {
  padding: 10px 14px; font-size: var(--fs-meta);
  background: var(--accent-tint); border: 1px solid var(--banner-border); border-radius: var(--radius);
}
.banner a { color: var(--gold-text); font-weight: 500; }
.banner.err { background: var(--danger-tint); border-color: var(--danger-border); }

/* Confirm dialog: native <dialog> opened with showModal() - traps focus, Esc closes.
   Replaces browser confirm(). Says exactly what will happen. */
.dialog {
  width: min(440px, calc(100vw - 2 * var(--s4)));
  padding: var(--s5); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}
.dialog::backdrop { background: var(--backdrop); }
.dialog h2 { margin: 0 0 var(--s2); font-size: 15px; font-weight: 600; }
.dialog p  { margin: 0 0 var(--s4); color: var(--ink-2); }

/* Empty state: icon + what's going on + the main action (left-aligned, not centred). */
.empty { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s1); padding: var(--s5); }
.empty-icon { color: var(--ink-3); margin-bottom: var(--s1); }
.empty-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.empty .btn { margin-top: var(--s3); }

/* Skeleton loading rows: flat bars that gently pulse (no gradient - team rule). */
.skel { display: flex; flex-direction: column; gap: var(--s2); width: 100%; }
.skel i { display: block; height: 12px; border-radius: 3px; background: var(--sunken);
  animation: skel-pulse 1.2s ease-in-out infinite alternate; }
@keyframes skel-pulse { from { opacity: 1; } to { opacity: .45; } }

/* Small inline note (e.g. "Exceeds the initial estimate by ..."). */
.note { margin-top: var(--s3); padding: var(--s2) 10px; font-size: var(--fs-meta); border-radius: var(--radius-sm); }
.note.warn { color: var(--st-awaiting); background: var(--st-awaiting-bg); }


/* 6. Data components */

/* Panel: white box with a 1px border - borders separate, not shadows. */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel-title { margin: 0 0 var(--s3); padding-bottom: 10px; border-bottom: 1px solid var(--line); font-size: 15px; font-weight: 600; }

/* Stat tiles (Performance page). Number in mono. */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s4); }
.stat { display: flex; flex-direction: column; gap: 2px; padding: var(--s4);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.stat small { font-size: var(--fs-small); font-weight: 500; color: var(--ink-2); }
.stat b { font-family: var(--mono); font-size: 28px; font-weight: 500; letter-spacing: -.02em; }
.stat b i { font-family: var(--font); font-size: 14px; font-style: normal; color: var(--ink-2); }
.stat span { font-size: var(--fs-small); }
.up { color: var(--success); }

/* Status timeline (order detail): newest first, newest dot filled green. */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.timeline li { position: relative; display: flex; flex-direction: column; padding: 0 0 14px 12px; }
.timeline li::before {
  content: ""; position: absolute; left: -25px; top: 5px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--ink-3);
}
.timeline li:first-child::before { background: var(--success); border-color: var(--success); }
.timeline li span { font-size: var(--fs-meta); color: var(--ink-2); }

/* Quote breakdown: label left, money right in mono, bold total with a dark rule above. */
.kv { width: 100%; border-collapse: collapse; }
.kv th, .kv td { padding: 7px 0; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
.kv td:last-child { text-align: right; font-family: var(--mono); white-space: nowrap; }
.kv .total th, .kv .total td { font-weight: 600; border-bottom: none; border-top: 2px solid var(--ink); padding-top: 10px; }

/* Data table. Wrap in .table-wrap so corners are rounded and wide tables scroll. */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  padding: 10px var(--s3); text-align: left; white-space: nowrap;
  font-size: 12px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-2); background: var(--table-head); border-bottom: 1px solid var(--line);
}
.tbl td { padding: 10px var(--s3); vertical-align: middle; border-bottom: 1px solid var(--line); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl td small { display: block; font-size: var(--fs-small); color: var(--ink-2); }
.tbl .r { text-align: right; }
.tbl .code { font-family: var(--mono); white-space: nowrap; }
.tbl tbody tr.is-link { cursor: pointer; }
.tbl tbody tr.is-link:hover td { background: var(--accent-tint); }
/* Overdue row: red left edge (plus the overdue badge/text - never colour alone). */
.tbl tr.is-overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger); }


/* 7. Staff app shell (admin + technician, works from 1024px) */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 22px; padding: 18px var(--s3);
  background: var(--surface); border-right: 1px solid var(--line);
}
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a {
  display: flex; align-items: center; gap: 10px; padding: var(--s2) 10px;
  color: var(--ink-2); font-weight: 500; text-decoration: none; border-radius: var(--radius);
}
.side nav a:hover { color: var(--ink); background: var(--canvas); }
/* Active page: green tint + accent bar on the left. Set aria-current="page" on the link. */
.side nav a[aria-current="page"] { color: var(--ink); background: var(--accent-tint); box-shadow: inset 3px 0 0 var(--accent); }
.nav-count { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.nav-count.alert { padding: 0 6px; color: var(--on-ink); background: var(--danger); border-radius: 10px; }

.me { display: flex; align-items: center; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.me small { display: block; color: var(--ink-2); }
.me .btn { margin-left: auto; }
.av { display: grid; place-items: center; flex: none; width: 32px; height: 32px;
  font-size: 12px; color: var(--on-ink); background: var(--ink); border-radius: 50%; }

.main { min-width: 0; padding: 22px 28px; }
/* Top bar: page title + subtitle left, ONE primary action right. */
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s4); margin-bottom: var(--s4); }
.topbar h1 { margin: 0; font-size: var(--fs-h1); font-weight: 600; }
.topbar p  { margin: 0; color: var(--ink-2); }

/* Filter bar: search, selects, overdue toggle. */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: var(--s3); }
.filters select {
  height: 36px; padding: 0 10px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.search {
  display: flex; align-items: center; gap: var(--s2); width: 300px; height: 36px; padding: 0 10px;
  color: var(--ink-3); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.search:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.search input { width: 100%; border: none; outline: none; background: transparent; color: var(--ink); }
.search input::placeholder { color: var(--ink-2); opacity: 1; }

/* Toggle switch: a real checkbox (keyboard + screen reader work for free), drawn as a switch.
   <label class="toggle"><input type="checkbox" name="overdue"><span class="track"></span>Overdue only</label> */
.toggle { position: relative; display: inline-flex; align-items: center; gap: var(--s2); font-weight: 500; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .track { position: relative; width: 30px; height: 18px; border-radius: 9px; background: var(--line-strong); transition: background-color .12s; }
.toggle .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--surface); transition: transform .12s;
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(12px); }
.toggle input:focus-visible + .track { box-shadow: var(--focus); }


/* 8. Customer portal (designed at 375px first, no sidebar) */
.portal { max-width: 480px; margin: 0 auto; min-height: 100vh; background: var(--surface); }
@media (min-width: 520px) {
  .portal { margin: var(--s6) auto; min-height: 0; border: 1px solid var(--line-strong); border-radius: var(--radius-lg); }
}
.portal-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s4) 20px; border-bottom: 1px solid var(--line); font-weight: 600; }
.portal-body { padding: 22px 20px 26px; }

/* Status headline in plain words: "Your Galaxy S22 is waiting for your approval". */
.hero { margin: var(--s1) 0 6px; font-size: 22px; font-weight: 600; line-height: 1.3; }

/* Vertical stepper: done = dark dot, now = accent dot, future = hollow dot. */
.stepper { list-style: none; margin: 20px 0; padding: 0; }
.stepper li { position: relative; padding: 0 0 var(--s3) 26px; font-size: 13.5px; color: var(--ink-2); }
.stepper li::before {
  content: ""; position: absolute; left: 0; top: 4px; width: 12px; height: 12px;
  border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface);
}
.stepper li::after { content: ""; position: absolute; left: 7px; top: 18px; bottom: -2px; width: 2px; background: var(--line); }
.stepper li:last-child::after { display: none; }
.stepper li.done::before { background: var(--ink); border-color: var(--ink); }
.stepper li.done::after  { background: var(--ink); }
/* aria-current="step" is what a screen reader announces for the current step. */
.stepper li[aria-current="step"] { color: var(--ink); font-weight: 600; }
.stepper li[aria-current="step"]::before { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-tint); }

/* Quote card on the portal. */
.card { padding: var(--s4); background: var(--card-bg); border: 1px solid var(--line); border-radius: var(--radius); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }
.card p { margin: var(--s1) 0 14px; }
.card .btn-row .btn { flex: 1; }
.card small { display: block; margin-top: 10px; font-size: var(--fs-small); }

/* Where the real Cloudflare Turnstile widget renders (it draws its own box). */
.turnstile-slot { min-height: 65px; margin-bottom: var(--s3); }
