/* ==========================================================================
   Car Sales LLC — shared design tokens + base component styles
   Used by both the public storefront (public/) and the staff CRM (public/staff/).
   ========================================================================== */

:root {
  --brand: #1c3f60;
  --brand-dark: #142e47;
  --accent: #c9862b;
  --accent-dark: #a86c1e;
  --ink: #14202c;
  --ink-soft: #3c4a59;
  --slate: #6b7684;
  --line: #e2e6ec;
  --bg: #f4f6f9;
  --bg-alt: #eef1f5;
  --card: #ffffff;
  --ok: #12855a;
  --ok-bg: #e6f6ef;
  --err: #c0392b;
  --err-bg: #fdecea;
  --field: #ffffff;

  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 32, .06);
  --shadow: 0 4px 16px rgba(15, 23, 32, .08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 32, .14);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
html { font-size: 18px; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; font-weight: 800; letter-spacing: -.01em; }
p { margin: 0 0 1rem; }
a { color: var(--brand); }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.wrap-narrow { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 20px; }

/* ── App bar / site header ───────────────────────────────────────────── */
.app-bar {
  background: linear-gradient(100deg, var(--brand-dark) 0%, var(--brand) 60%, #1a3c5c 100%);
  color: #fff;
  padding: .9rem 0;
  padding-top: calc(.9rem + env(safe-area-inset-top, 0px));
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 20;
}
.app-bar .bar-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: nowrap; min-width: 0; }
.brand-mark { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.08rem; color: #fff; text-decoration: none; min-width: 0; overflow: hidden; white-space: nowrap; }
.brand-mark .mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #1a1200; font-weight: 900; font-size: 1.1rem; flex: none; }
.app-bar nav { display: flex; gap: .3rem; flex: none; }
.app-bar nav a, .app-bar nav button {
  color: #fff; text-decoration: none; background: none; border: 0; font-family: inherit; cursor: pointer;
  font-size: .88rem; font-weight: 700; padding: .45rem .8rem; border-radius: 7px; white-space: nowrap;
}
.app-bar nav a:hover, .app-bar nav button:hover { background: rgba(255,255,255,.12); }
.app-bar nav a.active { background: rgba(255,255,255,.2); }

.refresh-btn {
  border: 0; background: rgba(255,255,255,.1); color: #fff; cursor: pointer;
  width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 1.05rem; line-height: 1; flex: none; -webkit-tap-highlight-color: transparent;
}
.refresh-btn:hover { background: rgba(255,255,255,.22); }
.refresh-btn .reload-ico { display: inline-block; transition: transform .15s ease; }
.refresh-btn.spinning .reload-ico { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 640px) {
  .app-bar nav { gap: 0; max-width: 62vw; overflow-x: auto; scrollbar-width: none; }
  .app-bar nav::-webkit-scrollbar { display: none; }
  .app-bar nav a, .app-bar nav button { padding: .4rem .5rem; font-size: .78rem; }
}

/* ── Cards ────────────────────────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.5rem; }
.card-title { font-size: 1.05rem; margin-bottom: 1rem; }

/* ── Forms ────────────────────────────────────────────────────────────── */
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem 1rem; margin: 0 0 1rem; min-width: 0; }
legend { font-size: .74rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--slate); padding: 0 .4rem; }
label { display: block; font-size: .85rem; font-weight: 700; color: var(--ink-soft); margin-bottom: .7rem; }
input, select, textarea {
  width: 100%; box-sizing: border-box; min-height: 44px; margin-top: .3rem;
  padding: .6rem .75rem; border: 1px solid #ccd3dd; border-radius: var(--radius);
  font-size: 1rem; font-family: inherit; color: var(--ink); background: var(--field);
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(28,63,96,.16); }
.row-check { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.row-check input { width: auto; min-height: auto; margin: 0; }
.form-err { min-height: 1.1em; color: var(--err); font-size: .85rem; }
.hint { font-size: .8rem; color: var(--slate); margin: -.4rem 0 .6rem; min-height: 1em; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .6rem 1.3rem; border: 1px solid transparent; border-radius: var(--radius);
  font-size: .95rem; font-weight: 700; font-family: inherit; cursor: pointer; text-decoration: none;
  transition: background-color .15s ease, transform .1s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { background: #9fb3c4; cursor: not-allowed; }
.btn-accent { background: var(--accent); color: #1a1200; }
.btn-accent:hover { background: var(--accent-dark); color: #fff; }
.btn-quiet { background: var(--card); border-color: #ccd3dd; color: var(--ink-soft); }
.btn-quiet:hover { background: #f7f9fb; }
.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover { background: #a3271b; }
.btn-block { display: flex; width: 100%; }
:focus-visible { outline: 3px solid rgba(28,63,96,.5); outline-offset: 2px; }

/* ── Badges / chips ───────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: .18rem .6rem; border-radius: 999px; font-weight: 800; font-size: .7rem; letter-spacing: .02em; text-transform: uppercase; background: #e7ebf0; color: var(--ink-soft); }
.badge-in_prep { background: #eef1f5; color: var(--slate); }
.badge-available { background: var(--ok-bg); color: var(--ok); }
.badge-pending { background: #fdf2e0; color: #a86c1e; }
.badge-sold { background: #ececec; color: #555; }
.chip-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { border: 1px solid var(--line); background: transparent; color: var(--ink-soft); padding: .4rem .9rem; border-radius: 999px; font-size: .82rem; font-weight: 800; cursor: pointer; }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ── Modals ───────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,16,24,.55); }
.modal-panel {
  position: relative; z-index: 1; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0; box-shadow: var(--shadow-lg);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-panel { border-radius: var(--radius-lg); max-height: 88vh; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-close { border: 0; background: var(--bg-alt); width: 32px; height: 32px; border-radius: 50%; font-size: 1rem; cursor: pointer; color: var(--slate); }
.modal-body { padding: 1.1rem 1.3rem; }
.modal-foot { display: flex; gap: .6rem; justify-content: flex-end; padding: 1rem 1.3rem; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* ── Gate / login ─────────────────────────────────────────────────────── */
.gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.gate[hidden] { display: none; }
.gate-card { width: 100%; max-width: 340px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 2rem 1.6rem; text-align: center; }
.gate-logo { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto 1rem; border-radius: 14px; background: var(--brand); color: var(--accent); font-weight: 900; font-size: 1.5rem; }
.gate-card h1 { font-size: 1.25rem; margin-bottom: .2rem; }
.gate-sub { color: var(--slate); font-size: .9rem; margin-bottom: 1.3rem; }
.gate-err { min-height: 1.1em; margin: .7rem 0 0; font-size: .85rem; color: var(--err); }

/* ── Simple lists / rows ──────────────────────────────────────────────── */
.simple-list { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.simple-row { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .55rem .75rem; border: 1px solid var(--line); border-radius: 8px; font-size: .88rem; background: var(--card); }
.simple-row .del { border: 0; background: transparent; color: var(--err); cursor: pointer; font-size: 1.1rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; }
.inline-form input, .inline-form select { flex: 1 1 120px; min-height: 40px; margin-top: 0; }

/* ── KPI grid ─────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.kpi-grid .kpi .num { font-size: 1.5rem; font-weight: 800; color: var(--ink); display: block; }
.kpi-grid .kpi .lbl { font-size: .78rem; color: var(--slate); }
.kpi { padding: 1.1rem 1.2rem; margin-bottom: 0; }

/* ── Toast ────────────────────────────────────────────────────────────── */
.notify-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: .7rem 1.2rem; border-radius: 999px; font-size: .88rem; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 200; box-shadow: var(--shadow-lg);
}
.notify-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Photo lightbox / thumbs ──────────────────────────────────────────── */
.photo-row { display: flex; gap: .5rem; flex-wrap: wrap; margin: .6rem 0; }
.photo-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; cursor: pointer; border: 1px solid var(--line); }
.photo-thumb-wrap { position: relative; }
.photo-del { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--err); color: #fff; font-size: .7rem; cursor: pointer; line-height: 1; }

/* ── Scan modal (VIN barcode camera) ─────────────────────────────────── */
.scan-modal { position: fixed; inset: 0; z-index: 300; background: #000; display: flex; flex-direction: column; }
.scan-modal[hidden] { display: none; }
.scan-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-guide {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%);
  width: 96vw; height: 78vh;
  border: 4px solid rgba(255,255,255,.95); border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.32);
  pointer-events: none;
}
.scan-overlay { position: relative; z-index: 1; margin-top: auto; padding: 1.2rem 1.2rem calc(env(safe-area-inset-bottom,0) + 1.4rem); text-align: center; }
.scan-status { color: #fff; font-size: .9rem; margin: 0 0 .5rem; min-height: 1.2em; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.scan-hint { display: inline-block; margin: 0 0 .8rem; padding: .55rem 1rem; background: rgba(0,0,0,.55); color: #fff; border-radius: 10px; font-size: .88rem; }
.scan-actions { display: flex; gap: .6rem; justify-content: center; }
.scan-actions .btn { background: rgba(255,255,255,.92); }

/* ── Field flash (instant visual feedback when a scan/decode fills a field) */
@keyframes fieldFlash {
  0% { background: rgba(201,134,43,.4); box-shadow: 0 0 0 3px rgba(201,134,43,.3); }
  100% { background: var(--field); box-shadow: none; }
}
.field-flash { animation: fieldFlash .8s ease; }

/* ── Misc utility ─────────────────────────────────────────────────────── */
[hidden] { display: none !important; }
.money { font-weight: 800; }
.money.pos { color: var(--ok); }
.money.neg { color: var(--err); }
.footer-note { text-align: center; color: var(--slate); font-size: .82rem; padding: 2rem 0; }
