/* ListingPal — all styling. Mobile-first, designed at 375px.
   Colors live only in these variables; never hardcode a color below. */

:root {
  --bg:            #f4f5f7;
  --surface:       #ffffff;
  --surface-2:     #eceef1;
  --border:        #d6dae0;
  --text:          #16191d;
  --text-dim:      #5b636e;
  --accent:        #1f6feb;
  --accent-text:   #ffffff;
  --accent-soft:   #e3edfd;
  --good:          #1a7f45;
  --good-soft:     #e2f4ea;
  --warn:          #9a6200;
  --warn-soft:     #fdf1dc;
  --danger:        #b3261e;
  --danger-soft:   #fbe6e5;

  --radius:   14px;
  --radius-s: 10px;
  --shadow:   0 1px 2px rgba(16, 20, 27, .07), 0 4px 14px rgba(16, 20, 27, .06);

  --font:  "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-c:"Barlow Condensed", var(--font);
  --font-m:"JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Bottom nav height + iOS home-indicator inset */
  --nav-h: calc(68px + env(safe-area-inset-bottom, 0px));
}

[data-theme="dark"] {
  --bg:            #0d1117;
  --surface:       #161b22;
  --surface-2:     #21262d;
  --border:        #303841;
  --text:          #e8eaed;
  --text-dim:      #9aa4b1;
  --accent:        #4c93ff;
  --accent-text:   #07101f;
  --accent-soft:   #17293f;
  --good:          #4ac97e;
  --good-soft:     #14301f;
  --warn:          #e0a33a;
  --warn-soft:     #33270f;
  --danger:        #f2837c;
  --danger-soft:   #341a19;
  --shadow:        0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

/* The HTML `hidden` attribute must always win. Without this, any `display:`
   rule with ID or class specificity silently overrides it — which is how the
   startup-guard card ended up painted over a perfectly working app. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;          /* deliberately large — the users are retirees */
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body { padding-bottom: var(--nav-h); }

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p  { margin: 0 0 .8em; }

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

/* ---------- Startup guard ---------- */

#startup-guard {
  position: fixed; inset: 0; z-index: 999;
  display: grid; place-items: center;
  padding: 24px; background: var(--bg);
}
.guard-card {
  max-width: 380px; padding: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.guard-icon { font-size: 2.4rem; line-height: 1; margin-bottom: 8px; color: var(--warn); }
.guard-card ol { margin: 0 0 16px; padding-left: 1.2em; }
.guard-card li { margin-bottom: .4em; }
.guard-card button {
  width: 100%; min-height: 54px;
  background: var(--accent); color: var(--accent-text);
  border: 1px solid transparent; border-radius: var(--radius-s);
  font-size: 1.1rem; font-weight: 600; cursor: pointer;
}
.guard-card .guard-secondary {
  margin-top: 10px;
  background: transparent; color: var(--text);
  border-color: var(--border);
}
.guard-card button:disabled { opacity: .55; cursor: default; }
.guard-detail {
  margin: 14px 0 0; font-family: var(--font-m);
  font-size: .75rem; color: var(--text-dim); word-break: break-word;
}

/* ---------- App shell ---------- */

.app { min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title {
  font-family: var(--font-c);
  font-size: 1.45rem; font-weight: 700;
  letter-spacing: .5px; text-transform: uppercase;
  margin: 0; flex: 1;
}
.topbar-back {
  background: none; border: none; padding: 8px; margin: -8px 0 -8px -8px;
  min-width: 44px; min-height: 44px;
  font-size: 1.05rem; font-weight: 600; color: var(--accent);
  cursor: pointer;
}

.screen { padding: 16px; max-width: 640px; margin: 0 auto; }

/* ---------- Bottom navigation ---------- */

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: 68px; padding: 8px 4px;
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-size: .8rem; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.nav button[aria-current="page"] { color: var(--accent); }
.nav .nav-icon { font-size: 1.5rem; line-height: 1; }

/* ---------- Cards & generic blocks ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 10px; }

.muted { color: var(--text-dim); }
.small { font-size: .87rem; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 54px; padding: 12px 20px; width: 100%;
  border: 1px solid transparent; border-radius: var(--radius-s);
  background: var(--surface-2); color: var(--text);
  font-size: 1.05rem; font-weight: 600; text-align: center;
  cursor: pointer; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:active { transform: none; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-danger  { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-big     { min-height: 64px; font-size: 1.2rem; }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Forms ---------- */

.field { margin-bottom: 16px; }
.field label {
  display: block; margin-bottom: 6px;
  font-size: .93rem; font-weight: 600; color: var(--text-dim);
}
/* Match every text-like input rather than listing types one at a time —
   `type="password"` was missed by the original list and rendered unstyled. */
.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.field select,
.field textarea {
  width: 100%; min-height: 52px;
  padding: 12px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-s);
  font-size: 1.05rem;
  /* 16px+ font size prevents iOS Safari from zooming on focus */
}
.field textarea { min-height: 140px; resize: vertical; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
.field-hint { margin: 6px 0 0; font-size: .85rem; color: var(--text-dim); }
.field-counter { float: right; font-family: var(--font-m); font-size: .8rem; }
.field-counter.over { color: var(--danger); font-weight: 600; }

.price-input { position: relative; }
.price-input span {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 1.05rem; color: var(--text-dim); pointer-events: none;
}
.price-input input { padding-left: 30px !important; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; min-height: 56px;
}
.switch-row + .switch-row { border-top: 1px solid var(--border); }

/* ---------- Steps ---------- */

.steps {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 18px;
}
.step {
  flex: 1; height: 6px; border-radius: 3px;
  background: var(--surface-2);
}
.step.done { background: var(--accent); }
.step-label {
  font-family: var(--font-c); text-transform: uppercase; letter-spacing: 1px;
  font-size: .95rem; font-weight: 700; color: var(--text-dim);
  margin-bottom: 6px;
}

/* ---------- Photos ---------- */

.photo-actions { display: flex; gap: 10px; margin-bottom: 16px; }

.photo-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.photo {
  position: relative; aspect-ratio: 1;
  border-radius: var(--radius-s); overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-main-tag {
  position: absolute; left: 0; bottom: 0; right: 0;
  background: var(--accent); color: var(--accent-text);
  font-size: .7rem; font-weight: 700; text-align: center;
  padding: 3px 0; letter-spacing: .5px;
}
.photo-remove {
  position: absolute; top: 2px; right: 2px;
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .62); color: #fff;
  border: none; font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.photo-move {
  position: absolute; top: 2px; left: 2px;
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .62); color: #fff;
  border: none; font-size: 1rem; line-height: 1; cursor: pointer;
}

.photo-open {
  display: block; width: 100%; height: 100%;
  padding: 0; border: none; background: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.photo-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-open:active { opacity: .75; }

.photo-edited {
  position: absolute; left: 4px; top: 4px;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--good); color: #fff;
  font-size: .85rem; font-weight: 700; line-height: 1;
}

/* ---------- Photo editor ---------- */

.editor {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg); overflow-y: auto;
  /* Sits above the bottom nav, so it needs its own safe-area padding. */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.topbar-done {
  background: none; border: none; padding: 8px; margin: -8px -8px -8px 0;
  min-width: 60px; min-height: 44px;
  font-size: 1.05rem; font-weight: 700; color: var(--accent);
  cursor: pointer;
}
.topbar-done:disabled { opacity: .4; }

/* The frame hugs the canvas exactly (width: fit-content). That matters: the
   crop box is positioned in percentages of the frame, so any letterboxing
   between frame and image would make the crop land somewhere else than where
   the user drew it. */
.editor-frame {
  position: relative; display: block;
  width: fit-content; max-width: 100%;
  margin: 0 auto 12px;
  background: var(--surface-2); border-radius: var(--radius-s);
  overflow: hidden;
  touch-action: none;   /* let the crop box own the gesture */
}
/* Cap the height so a tall portrait photo doesn't push every control off
   screen — the adjustment sliders have to be reachable without scrolling. */
.editor-canvas {
  display: block;
  width: auto; height: auto;
  max-width: 100%; max-height: 40vh;
}

.crop-box {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45);
  cursor: move; touch-action: none;
}
/* Handles sit INSIDE the box. They used to overhang by 22px, which the
   frame's overflow:hidden clipped as soon as the box touched an edge —
   leaving the corner ungrabbable exactly when you needed it. */
.crop-handle {
  position: absolute; width: 44px; height: 44px;
  touch-action: none;
}
.crop-handle::after {
  content: ""; position: absolute; width: 18px; height: 18px;
  background: #fff; border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}
.crop-nw { left: 0; top: 0; }
.crop-nw::after { left: 2px; top: 2px; }
.crop-ne { right: 0; top: 0; }
.crop-ne::after { right: 2px; top: 2px; }
.crop-sw { left: 0; bottom: 0; }
.crop-sw::after { left: 2px; bottom: 2px; }
.crop-se { right: 0; bottom: 0; }
.crop-se::after { right: 2px; bottom: 2px; }

/* ---------- Sliders ---------- */

.slider-row { margin-top: 18px; }
.slider-row label {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px; font-size: .93rem; font-weight: 600; color: var(--text-dim);
}
.slider-value { font-family: var(--font-m); font-size: .8rem; }
.slider-row input[type="range"] {
  width: 100%; height: 44px; margin: 0;
  background: transparent; -webkit-appearance: none; appearance: none;
}
.slider-row input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px; background: var(--surface-2);
}
.slider-row input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 3px; background: var(--surface-2);
}
/* Deliberately oversized thumbs — these get dragged with a thumb, not a mouse. */
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 30px; height: 30px; margin-top: -12px;
  border-radius: 50%; background: var(--accent);
  border: 3px solid var(--surface); box-shadow: var(--shadow);
  cursor: pointer;
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface); cursor: pointer;
}

.empty {
  padding: 34px 20px; text-align: center;
  border: 2px dashed var(--border); border-radius: var(--radius);
  color: var(--text-dim);
}
.empty-icon { font-size: 2.6rem; line-height: 1; margin-bottom: 8px; }

/* ---------- Loading ---------- */

.loading { padding: 48px 20px; text-align: center; }
.spinner {
  width: 46px; height: 46px; margin: 0 auto 18px;
  border: 4px solid var(--surface-2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

/* ---------- Chips / badges ---------- */

.chip {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 700; letter-spacing: .3px;
  background: var(--surface-2); color: var(--text-dim);
}
.chip-draft  { background: var(--surface-2); color: var(--text-dim); }
.chip-posted { background: var(--good-soft);   color: var(--good); }
.chip-copied { background: var(--accent-soft); color: var(--accent); }
.chip-sold   { background: var(--warn-soft);   color: var(--warn); }

.banner {
  padding: 12px 14px; border-radius: var(--radius-s);
  font-size: .93rem; margin-bottom: 14px;
}
.banner-info { background: var(--accent-soft); color: var(--text); }
.banner-warn { background: var(--warn-soft);   color: var(--text); }
.banner-error{ background: var(--danger-soft); color: var(--text); }

/* ---------- Format / choice cards ---------- */

.choice-row { display: flex; gap: 10px; margin-bottom: 18px; }
.choice {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
  min-height: 76px; padding: 12px;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius-s);
  text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.choice strong { font-size: 1.02rem; }
.choice span { font-size: .82rem; color: var(--text-dim); line-height: 1.3; }
.choice[aria-pressed="true"] {
  border-color: var(--accent); background: var(--accent-soft);
}
.choice[aria-pressed="true"] span { color: var(--text); }

/* Three-across number inputs for box dimensions. */
.dims-row { display: flex; gap: 10px; }
.dims-row .field { flex: 1; min-width: 0; }
.dims-row .field label { font-size: .82rem; }
.dims-row .field input { padding-left: 10px; padding-right: 6px; }

/* ---------- Research: retailer rows ---------- */

.retailer {
  display: block;
  min-height: 56px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--surface-2); border-radius: var(--radius-s);
  text-decoration: none; color: var(--text);
}
.retailer:active { opacity: .7; }
.retailer-name {
  display: block; font-weight: 600;
  /* Wrap rather than truncate — a store name cut to "Equipment Trader (d…"
     is worse than one that takes two lines. */
  overflow-wrap: anywhere;
}
.retailer-meta {
  display: block; margin-top: 2px;
  font-size: .87rem; color: var(--text-dim);
  overflow-wrap: anywhere;
}
.retailer-meta strong { color: var(--accent); font-size: 1rem; }

/* ---------- Comps ---------- */

.comps {
  background: var(--accent-soft); border-radius: var(--radius-s);
  padding: 12px 14px; margin-top: 8px;
}
.comps-range { font-weight: 700; font-size: 1.05rem; }
.comps a { color: var(--accent); font-weight: 600; }

/* ---------- History ---------- */

.hist-item {
  display: flex; gap: 12px; align-items: center;
  padding: 12px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; text-align: left; cursor: pointer;
}
.hist-thumb {
  width: 66px; height: 66px; flex: none;
  border-radius: var(--radius-s); object-fit: cover;
  background: var(--surface-2);
}
.hist-body { min-width: 0; flex: 1; }
.hist-title {
  font-weight: 600; margin: 0 0 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.hist-meta { font-size: .85rem; color: var(--text-dim); }

.filters { display: flex; gap: 8px; margin-bottom: 14px; }
.filters button {
  flex: 1; min-height: 44px; padding: 8px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text-dim);
  font-size: .93rem; font-weight: 600; cursor: pointer;
}
.filters button[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-text); border-color: var(--accent);
}

/* ---------- Success ---------- */

.success-icon {
  font-size: 3.4rem; line-height: 1; text-align: center;
  color: var(--good); margin-bottom: 8px;
}

/* ---------- Desktop: sidebar nav instead of bottom bar ---------- */

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
  .nav {
    position: sticky; top: 0; left: auto; right: auto; bottom: auto;
    grid-template-columns: 1fr; align-content: start; gap: 4px;
    height: 100vh; padding: 20px 12px;
    border-top: none; border-right: 1px solid var(--border);
  }
  .nav button {
    flex-direction: row; justify-content: flex-start; gap: 12px;
    min-height: 52px; padding: 8px 14px; border-radius: var(--radius-s);
    font-size: 1rem;
  }
  .nav button[aria-current="page"] { background: var(--accent-soft); }
  .app > .app-main { min-width: 0; }
  .topbar { padding-top: 16px; }
  .screen { padding: 24px; }
}
