:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --card: #ffffff;
  --ink: #1c1c1e;
  --muted: #6b6a68;
  --line: #e2e0db;
  --line-strong: #c9c6bf;
  --accent: #111111;
  --accent-soft: #ecebe7;
  --curtain: #8a6a45;
  --blind: #3c6870;
  --flag-bg: #fff6dc;
  --flag-line: #d9a43a;
  --flag-ink: #7a5206;
  --danger: #b42318;
  --ok: #1f7a4a;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
}
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.muted { color: var(--muted); margin: 4px 0 10px; }
.loading { padding: 40px 16px; color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.logo {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 7px;
  background: var(--accent); color: #fff;
  font: 700 18px/1 Georgia, "Times New Roman", serif; letter-spacing: -.04em;
}
.logo.big { width: 64px; height: 64px; font-size: 36px; border-radius: 14px; margin: 0 auto 16px; }
.top-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  flex: none; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--muted);
}
.pill.confirmed { background: #e3f3ea; color: var(--ok); }
@media (max-width: 560px) { .brand-name { display: none; } }

/* ---------- layout ---------- */
.layout {
  display: flex; flex-direction: column; gap: 12px;
  max-width: 1480px; margin: 0 auto;
  padding: 12px 12px 110px;
}
main { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.source { order: -1; }
@media (min-width: 1100px) {
  body.has-source .layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(380px, 40%); align-items: start; }
  .source { order: 0; position: sticky; top: 64px; max-height: calc(100vh - 150px); overflow: auto; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card > h2 { margin-bottom: 12px; }

/* ---------- source scans ---------- */
.source-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.source-box summary { padding: 12px 16px; font-weight: 600; cursor: pointer; }
.source-list { display: flex; flex-direction: column; gap: 10px; padding: 0 12px 12px; }
.source-list img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.source-pdf iframe { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.source-pdf a { display: inline-block; margin-top: 6px; font-size: 13px; }

/* ---------- notices ---------- */
.notice { background: #eef6f1; border-color: #bfe0cc; }
.problems { background: #fdecea; border-color: #f2b8b2; }
.problems ul, .flags ul { margin: 0; padding-left: 18px; }
.problems li, .flags li { margin: 6px 0; }
.flags { background: var(--flag-bg); border-color: var(--flag-line); }
.flags li { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; }
.flag-text { flex: 1 1 260px; }
.flag-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- fields ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(136px, 100%), 1fr));
  gap: 10px 12px;
}
.grid.tight { grid-template-columns: repeat(auto-fill, minmax(min(84px, 100%), 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
@media (min-width: 420px) { .field.flagged:not(.wide) { grid-column: span 2; } }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.req { color: var(--danger); }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }

input, select, textarea {
  width: 100%;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in */
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 10px;
  min-height: 42px;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input.invalid { border-color: var(--danger); background: #fff5f4; }

.flagged > input, .flagged > select, .flagged > textarea, .flagged > .picker { border-color: var(--flag-line); background: var(--flag-bg); }
.flag-msg {
  display: block;
  font-size: 12.5px; color: var(--flag-ink);
  background: var(--flag-bg); border-left: 3px solid var(--flag-line);
  padding: 4px 8px; border-radius: 4px; margin: 2px 0 6px;
}
.pulse { animation: pulse 1.6s ease-out; }
@keyframes pulse { 0% { box-shadow: 0 0 0 4px rgba(217, 164, 58, .6); } 100% { box-shadow: 0 0 0 14px rgba(217, 164, 58, 0); } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 16px;
  font: inherit; font-weight: 600;
  color: var(--ink); background: #fff;
  border: 1px solid var(--line-strong); border-radius: 10px;
  cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { min-height: 34px; padding: 5px 12px; font-size: 13.5px; }
.btn:disabled { opacity: .5; cursor: wait; }
.link { background: none; border: 0; padding: 4px 2px; font: inherit; font-size: 13.5px; font-weight: 600; text-decoration: underline; cursor: pointer; color: var(--ink); }
.link.danger { color: var(--danger); }
.icon { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; font-size: 15px; }
.tools { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.add-row.center { justify-content: center; }

/* ---------- rooms / products ---------- */
.room-head, .product-head, .dim-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.room-head { justify-content: space-between; margin-bottom: 10px; }
.room-head h2 { font-size: 19px; }

.product {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--curtain);
  border-radius: 10px;
  background: #fcfbf9;
}
.product.is-blind { border-left-color: var(--blind); }
.product-head { margin-bottom: 10px; }
.product-title { flex: 1; min-width: 140px; font-weight: 600; }
.chips { display: flex; gap: 4px; }
.chip {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 12.5px; font-weight: 700;
  background: var(--accent); color: #fff;
}

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; margin-bottom: 12px; }
.segmented button { border: 0; background: #fff; padding: 8px 18px; font: inherit; font-weight: 600; cursor: pointer; min-height: 38px; }
.segmented button + button { border-left: 1px solid var(--line-strong); }
.segmented button.on { background: var(--accent); color: #fff; }

.installation { margin-top: 4px; }
.dims { margin-top: 4px; }
.dim {
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}
.dim-head { justify-content: space-between; margin-bottom: 8px; }
.dim .field.wide { margin-top: 2px; }

@media (max-width: 560px) {
  .layout { padding-left: 8px; padding-right: 8px; }
  .card { padding: 12px; }
  .product { padding: 10px; }
  .dim { padding: 10px; }
}

/* ---------- image pickers ---------- */
.picker { display: flex; flex-wrap: wrap; gap: 6px; border: 1px solid transparent; border-radius: 8px; }
.picker button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 86px; padding: 6px 4px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; font: inherit; font-size: 11.5px; color: var(--muted);
}
.picker button img { width: 70px; height: 62px; object-fit: contain; }
.picker.pelmet button img { height: 22px; }
.picker button.on { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--ink); font-weight: 600; padding: 5px 3px; }

/* ---------- remark images ---------- */
.remark-images { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.thumb { position: relative; }
.thumb img { display: block; width: 96px; height: 96px; object-fit: cover; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.thumb-x {
  position: absolute; top: -8px; right: -8px;
  width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: var(--danger); color: #fff; font-size: 15px; line-height: 1; cursor: pointer;
}
.file-btn { cursor: pointer; }

/* ---------- action bar / toast ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, .05);
}
.dirty { flex: 1; font-size: 13px; color: var(--flag-ink); }
@media (max-width: 420px) { .actionbar .btn { padding: 8px 12px; } }

.toast {
  position: fixed; left: 50%; bottom: 84px; z-index: 40; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 10px;
  background: var(--ink); color: #fff; font-weight: 500;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
}
.toast.error { background: var(--danger); }
.toast .btn { min-height: 30px; }

/* ---------- landing / error pages ---------- */
.empty { max-width: 520px; margin: 12vh auto; padding: 0 16px; text-align: center; }
.empty h1 { font-size: 22px; margin-bottom: 8px; }
.empty p { color: var(--muted); }
