:root {
  --bg: #f7f4ee;
  --card: #ffffff;
  --ink: #1f2a22;
  --muted: #5b665e;
  --line: #ddd6c8;
  --green: #2f6b3f;
  --green-dark: #224f2e;
  --green-soft: #e3efe4;
  --gold: #b7791f;
  --red: #a32d2d;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { font-size: 21px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; line-height: 1.45; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* buttons */
.btn { border: 3px solid var(--green); background: #fff; color: var(--green-dark); border-radius: 14px; padding: 12px 16px; min-height: 56px; font-weight: 700; cursor: pointer; }
.btn:hover { background: var(--green-soft); }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.big { width: 100%; font-size: 1.15rem; min-height: 68px; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.quiet { border-color: var(--line); color: var(--ink); font-weight: 600; min-height: 52px; padding: 8px 14px; font-size: 1rem; }
.btn.done { background: var(--green-soft); border-color: var(--green); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--card); padding: 32px 24px; border-radius: 20px; width: 100%; max-width: 420px; text-align: center; box-shadow: 0 6px 30px rgba(0,0,0,.08); }
.login-card .logo { font-size: 56px; }
.login-card h1 { margin: 4px 0 0; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-card label { display: block; text-align: left; font-weight: 600; margin-bottom: 6px; }
.login-card input { width: 100%; font-size: 1.3rem; padding: 12px; border: 2px solid var(--line); border-radius: 12px; margin-bottom: 14px; }
.err { color: var(--red); font-weight: 600; min-height: 1.4em; margin-top: 10px !important; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 12px 16px 8px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; }
.logo-sm { font-size: 34px; }
.top h1 { margin: 0; font-size: 1.4rem; }
.sub { margin: 0; color: var(--muted); }
.progress { height: 10px; background: #e7e1d4; border-radius: 6px; margin-top: 8px; overflow: hidden; }
#progressBar { height: 100%; width: 0; background: var(--green); transition: width .4s; }

.howto { margin: 16px; background: var(--card); border-radius: var(--radius); padding: 14px 18px; border: 1px solid var(--line); }
.howto ol { margin: 0; padding-left: 1.3em; }
.howto li { margin: 6px 0; font-size: 1.1rem; }
.safe { margin: 10px 0 0; color: var(--green-dark); font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 16px 12px; }
.filters input { flex: 1 1 260px; }
.filters input, .filters select { padding: 12px; border: 2px solid var(--line); border-radius: 12px; background: #fff; min-height: 52px; }
.filters select { flex: 0 1 220px; }

/* table */
.table { margin: 0 16px 40px; }
.thead, .row { display: grid; grid-template-columns: 52px minmax(180px, 1fr) minmax(240px, 1.2fr) minmax(240px, 1.2fr) 190px; gap: 18px; align-items: start; }
.thead { position: sticky; top: 100px; z-index: 4; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--radius) var(--radius) 0 0; font-weight: 700; font-size: 1rem; }
.row { background: var(--card); border: 1px solid var(--line); border-top: none; padding: 16px 14px; }
.row:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.row.is-done { background: #f3f9f3; }
.num { font-weight: 700; color: var(--muted); font-size: 1.1rem; }
.cell-label { display: none; }

.pname { font-weight: 700; font-size: 1.15rem; margin: 0 0 4px; }
.pmeta { color: var(--muted); font-size: .95rem; margin: 0 0 8px; }
.pmeta a { color: var(--green-dark); }
.photo { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: #eee; cursor: zoom-in; }

.src-main { position: relative; margin-bottom: 8px; }
.src-main .tag { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.7); color: #fff; font-size: .9rem; padding: 3px 10px; border-radius: 8px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.thumbs button { padding: 0; border: 4px solid transparent; border-radius: 10px; background: none; cursor: pointer; width: 68px; height: 68px; }
.thumbs button img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.thumbs button.sel { border-color: var(--gold); }
.file-btn { position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.row.drop { outline: 4px dashed var(--gold); outline-offset: -4px; background: #fff8e8; }

textarea { width: 100%; min-height: 64px; border: 2px solid var(--line); border-radius: 12px; padding: 10px; resize: vertical; margin-bottom: 8px; }

.result-empty { aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 10px; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 12px; font-size: .95rem; }
.working { aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center; text-align: center; background: var(--green-soft); color: var(--green-dark); font-weight: 600; padding: 12px; }
.spinner { width: 44px; height: 44px; border: 5px solid #fff; border-top-color: var(--green); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; color: var(--ink); font-size: 1rem; }
.pager button { min-width: 64px; }
.chosen-badge { position: absolute; right: 8px; top: 8px; background: var(--green); color: #fff; padding: 4px 12px; border-radius: 8px; font-weight: 700; font-size: 1rem; }
.result-wrap { position: relative; }
.row-err { color: var(--red); font-weight: 700; font-size: 1rem; margin: 8px 0; }

.done-col { display: flex; flex-direction: column; gap: 8px; }
.done-msg { color: var(--green-dark); font-weight: 700; text-align: center; font-size: 1.2rem; margin: 8px 0; }
details.fix { margin-top: 8px; font-size: 1rem; }
details.fix summary { cursor: pointer; color: var(--muted); }
details.fix label { display: block; margin-top: 6px; font-weight: 600; }
details.fix input, details.fix textarea { width: 100%; padding: 8px; border: 2px solid var(--line); border-radius: 10px; min-height: 44px; margin: 2px 0 0; }

.empty { text-align: center; color: var(--muted); padding: 30px; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-height: 88vh; max-width: 100%; object-fit: contain; border-radius: 8px; }
.lightbox p { color: #ddd; margin: 10px 0 0; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(120px); background: var(--ink); color: #fff; padding: 14px 20px; border-radius: 12px; font-weight: 600; transition: transform .3s; z-index: 60; max-width: calc(100% - 32px); text-align: center; }
.toast.show { transform: translateX(-50%) translateY(0); }

/* phones & tablets: each product becomes a card */
@media (max-width: 1000px) {
  .thead { display: none; }
  .table { margin: 0 12px 40px; }
  .row { grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; gap: 12px; padding: 14px; }
  .row:last-child { border-radius: var(--radius); }
  .num { display: none; }
  .cell-product { grid-column: 1 / -1; display: grid; grid-template-columns: 90px 1fr; gap: 12px; align-items: start; }
  .cell-product .photo { order: -1; }
  .cell-done { grid-column: 1 / -1; }
  .cell-label { display: block; font-weight: 700; color: var(--ink); font-size: 1.05rem; margin-bottom: 8px; }
  .top .thead { top: 0; }
}
@media (max-width: 480px) {
  html { font-size: 19px; }
  .row { grid-template-columns: 1fr; }
}
.result-cap { margin: 6px 0 0; }

.go { margin-bottom: 12px; }
.result-empty { font-size: 1rem; }
.toast { font-size: 1.1rem; }
@media (max-width: 1000px) {
  .top { position: static; }
  .top h1 { font-size: 1.3rem; }
  .logo-sm { font-size: 30px; }
}
