:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202b;
  --muted: #5d6b7a;
  --line: #d9dee5;
  --accent: #1f5fa8;
  --accent-text: #ffffff;
  --good: #1d7a3e;
  --good-bg: #e6f4ea;
  --bad: #b3261e;
  --bad-bg: #fdecea;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --chip: #eef1f5;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151a; --panel: #1a2027; --text: #e6ebf1; --muted: #98a6b5; --line: #2c3540;
    --accent: #5aa2f0; --accent-text: #0b1220; --good: #6fd08f; --good-bg: #16301f;
    --bad: #ff8a80; --bad-bg: #3a1a18; --warn: #ffcc66; --warn-bg: #3a2e14; --chip: #24303b;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11151a; --panel: #1a2027; --text: #e6ebf1; --muted: #98a6b5; --line: #2c3540;
  --accent: #5aa2f0; --accent-text: #0b1220; --good: #6fd08f; --good-bg: #16301f;
  --bad: #ff8a80; --bad-bg: #3a1a18; --warn: #ffcc66; --warn-bg: #3a2e14; --chip: #24303b;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.hidden { display: none !important; }

header#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
header#topbar .brand { font-weight: 700; font-size: 18px; color: var(--text); }
header#topbar nav { display: flex; gap: 14px; align-items: center; font-size: 15px; }
header#topbar nav a.active { font-weight: 700; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }

button, .btn {
  font: inherit; font-size: 15px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 8px 12px; min-height: 38px;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
button:hover { border-color: var(--accent); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.good { background: var(--good-bg); color: var(--good); border-color: var(--good); }
button.bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
button.on { outline: 2px solid var(--accent); outline-offset: 1px; font-weight: 700; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; }
button:disabled { opacity: .5; cursor: default; }

input, textarea, select {
  font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 38px;
  width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
label.field { display: block; margin: 0 0 12px; }
label.field > span.lbl, .lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .03em; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.project-card { display: flex; gap: 12px; color: var(--text); }
.project-card:hover { text-decoration: none; border-color: var(--accent); }
.project-card img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--chip); flex: none; }

.badge { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; font-weight: 700; text-align: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 14px; background: var(--chip); font-size: 14px; border: 1px solid transparent; }
.chip button { border: 0; background: none; padding: 0 2px; min-height: 0; color: var(--muted); font-size: 15px; }
.chip.sel { background: var(--accent); color: var(--accent-text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Filters + grid */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar select, .toolbar input { width: auto; min-width: 0; flex: 1 1 140px; }
.toolbar .search { flex: 2 1 200px; }
.grid { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; } }
.tile { position: relative; aspect-ratio: 3 / 4; background: var(--chip); border-radius: 8px; overflow: hidden; display: block; border: 2px solid transparent; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .st { position: absolute; left: 4px; top: 4px; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 8px; background: rgba(0,0,0,.6); color: #fff; }
.tile .st.keep { background: var(--good); color: #fff; }
.tile .st.skip { background: #777; }
.tile .notes { position: absolute; right: 4px; top: 4px; font-size: 11px; padding: 1px 6px; border-radius: 8px; background: rgba(0,0,0,.6); color: #fff; }
.tile .prop { position: absolute; right: 4px; bottom: 4px; }
.tile .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.7)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.selected { border-color: var(--accent); }
.tile.selected::after { content: "\2713"; position: absolute; right: 6px; bottom: 6px; width: 24px; height: 24px; border-radius: 12px; background: var(--accent); color: var(--accent-text); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.tile.skipped img { opacity: .45; }

.batchbar { position: sticky; bottom: 0; z-index: 15; margin: 12px -16px -16px; padding: 10px 16px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Photo detail */
.detail { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 980px) { .detail { grid-template-columns: minmax(0, 1.3fr) minmax(360px, 1fr); align-items: start; } .detail .imgwrap { position: sticky; top: 70px; } }
.imgwrap { background: #000; border-radius: var(--radius); overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 240px; touch-action: pan-y; }
.imgwrap img { max-height: 78vh; width: auto; max-width: 100%; display: block; }
.nav-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.meta { font-size: 13px; color: var(--muted); }
.list-editor { display: flex; flex-direction: column; gap: 6px; }
.list-editor .li { display: flex; gap: 6px; align-items: flex-start; }
.list-editor .li textarea { min-height: 38px; height: 38px; }
.list-editor .li button { flex: none; }
.use-for { border-left: 4px solid var(--good); padding-left: 10px; background: var(--good-bg); border-radius: 8px; padding: 10px; margin-bottom: 12px; }
.use-for .lbl { color: var(--good); }
.dont-use { border-left: 4px solid var(--bad); background: var(--bad-bg); border-radius: 8px; padding: 10px; margin-bottom: 12px; }
.dont-use .lbl { color: var(--bad); }
.transcript { white-space: pre-wrap; background: var(--chip); border-radius: 8px; padding: 10px; font-size: 14px; max-height: 240px; overflow: auto; }
.saving { font-size: 12px; color: var(--muted); min-height: 16px; }
.history { font-size: 13px; }
.history li { margin-bottom: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { outline: none; background: var(--accent); color: var(--accent-text); }
details summary { cursor: pointer; font-weight: 600; margin: 8px 0; }

/* Voice mode */
.voice { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; display: flex; flex-direction: column; touch-action: pan-y; }
.voice .vtop { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); background: rgba(0,0,0,.6); }
.voice .vtop button { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); }
.voice .vimg { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; min-height: 0; }
.voice .vimg img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.voice .vbottom { padding: 10px 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); background: rgba(0,0,0,.75); display: flex; flex-direction: column; gap: 8px; }
.voice .live { min-height: 44px; max-height: 22vh; overflow: auto; font-size: 16px; line-height: 1.35; }
.voice .live .interim { color: #9fb3c8; }
.voice textarea { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.25); min-height: 44px; height: 44px; }
.voice .controls { display: flex; gap: 8px; align-items: center; }
.voice .rec { width: 64px; height: 64px; border-radius: 32px; border: 3px solid #fff; background: #c62828; color: #fff; font-weight: 700; font-size: 13px; flex: none; }
.voice .rec.on { animation: pulse 1.4s infinite; background: #ff1744; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,23,68,.6); } 70% { box-shadow: 0 0 0 14px rgba(255,23,68,0); } 100% { box-shadow: 0 0 0 0 rgba(255,23,68,0); } }
.voice .navbtn { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); min-width: 56px; min-height: 48px; }
.voice .vinfo { font-size: 13px; color: #c8d3de; }
.voice .arrow { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.35); color: #fff; border: 0; font-size: 28px; width: 44px; height: 64px; }
.voice .arrow.l { left: 6px; } .voice .arrow.r { right: 6px; }

/* Review */
.prop-card { margin-bottom: 12px; }
.prop-card .phead { display: flex; gap: 12px; align-items: flex-start; }
.prop-card .phead img { width: 96px; height: 128px; object-fit: cover; border-radius: 8px; background: var(--chip); flex: none; }
table.diff { width: 100%; border-collapse: collapse; font-size: 14px; margin: 10px 0; table-layout: fixed; }
table.diff th, table.diff td { border-top: 1px solid var(--line); padding: 6px; vertical-align: top; text-align: left; word-wrap: break-word; }
table.diff th { width: 22%; color: var(--muted); font-weight: 600; }
table.diff td.b { background: var(--bad-bg); }
table.diff td.a { background: var(--good-bg); }
table.diff ul { margin: 0; padding-left: 18px; }

/* Items */
.item-card .counts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.item-card .counts .chip.zero { background: var(--warn-bg); color: var(--warn); }
.must { white-space: pre-wrap; font-size: 14px; margin-top: 6px; }

/* Upload */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; text-align: center; background: var(--panel); }
.drop.over { border-color: var(--accent); background: var(--chip); }
.up-row { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.up-row .name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-row progress { width: 110px; }
.up-row .res { width: 120px; text-align: right; }
.res.ok { color: var(--good); } .res.dup { color: var(--warn); } .res.err { color: var(--bad); }

/* Keys */
.keybox { font-family: ui-monospace, Menlo, monospace; word-break: break-all; background: var(--chip); padding: 10px; border-radius: 8px; }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple td, table.simple th { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; }

/* Login */
.login { max-width: 380px; margin: 10vh auto; }

/* Modal + toast */
.modal-back { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 16px; overflow: auto; }
.modal { background: var(--panel); color: var(--text); border-radius: var(--radius); padding: 16px; width: 100%; max-width: 560px; margin-top: 6vh; }
#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(120px); z-index: 100; background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 32px); transition: transform .2s; font-size: 15px; }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--bad); color: #fff; }
#toast.good { background: var(--good); color: #fff; }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 12px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 6px 12px; border-radius: 16px; background: var(--chip); color: var(--text); font-size: 14px; }
.tabs a.active { background: var(--accent); color: var(--accent-text); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

[hidden] { display: none !important; }
select {
  -webkit-appearance: none; appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%238a96a3' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
