:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --ink: #1e1c19;
  --muted: #6f6a62;
  --line: #e4dfd6;
  --accent: #9a4a26;
  --accent-ink: #ffffff;
  --ok: #2f6b3f;
  --ok-bg: #e3f0e5;
  --warn: #8a5a0b;
  --warn-bg: #fbefd6;
  --danger: #a3302a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(30, 28, 25, .06), 0 2px 8px rgba(30, 28, 25, .05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
a { color: inherit; }
h1 { font-size: 22px; margin: 4px 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; letter-spacing: -.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; display: flex; gap: 8px; align-items: baseline; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); }
.muted { color: var(--muted); margin: 2px 0; }
.small { font-size: 13px; }
.req { font-size: 11px; text-transform: none; letter-spacing: 0; color: var(--accent); font-weight: 500; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: rgba(245, 243, 239, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar nav { display: flex; gap: 8px; align-items: center; }
.topbar form { margin: 0; }
.logo { font-weight: 700; text-decoration: none; font-size: 17px; letter-spacing: -.01em; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px 16px 48px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel-out { border-color: #d9c2b4; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.head-actions form { margin: 0; }
.back { text-decoration: none; color: var(--muted); font-size: 14px; }
.card-layout { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) {
  .card-layout { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }
  #output { position: sticky; top: 72px; }
}
form.stack { max-width: 720px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit;
  font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: #cbc4b8; }
.btn-sm { min-height: 34px; padding: 5px 11px; font-size: 14px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #853f20; border-color: #853f20; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); font-weight: 500; }
.btn-block { width: 100%; min-height: 48px; font-size: 16px; }

/* forms */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; margin-top: 12px; }
label:first-child { margin-top: 0; }
label small { font-weight: 400; color: var(--muted); }
input:not([type=radio]):not([type=file]), select, textarea {
  font: inherit; font-size: 16px; font-weight: 400; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fcfbf9; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(154, 74, 38, .25); border-color: var(--accent); }
textarea { resize: vertical; }
input[type=file] { font: inherit; font-size: 14px; font-weight: 400; padding: 10px; border: 1px dashed #cfc7ba;
  border-radius: 10px; background: #fcfbf9; width: 100%; }
.brand-pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 600px) { .brand-pick { grid-template-columns: repeat(4, 1fr); } }
.brand-pick label { margin: 0; }
.brand-pick input { position: absolute; opacity: 0; pointer-events: none; }
.brand-pick span { display: block; text-align: center; padding: 12px 8px; border: 1px solid var(--line); border-radius: 10px;
  background: #fcfbf9; font-weight: 600; cursor: pointer; }
.brand-pick input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.brand-pick input:focus-visible + span { outline: 2px solid rgba(154, 74, 38, .4); }
.form-actions { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, rgba(245, 243, 239, 0)); }
.form-error { color: var(--danger); font-weight: 600; margin: 0 0 8px; }
.previews { display: flex; gap: 6px; flex-wrap: wrap; }
.previews img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.previews span { font-size: 12px; font-weight: 400; color: var(--muted); padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; }
.out-form { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }

/* flash */
.flash { padding: 10px 14px; border-radius: 10px; background: var(--ok-bg); color: var(--ok); margin-bottom: 14px; font-weight: 500; }
.flash-error { background: #f8e3e1; color: var(--danger); }

/* filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters select { width: auto; min-width: 140px; }
.filters input[type=search] { flex: 1 1 220px; width: auto; }
.seg { display: inline-flex; background: #ebe7e0; border-radius: 10px; padding: 3px; }
.seg a { text-decoration: none; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap; }
.seg a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.count { font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 2px; }

/* cue cards */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; } }
.cue { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; text-decoration: none; box-shadow: var(--shadow); transition: transform .12s ease, box-shadow .12s ease; }
.cue:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(30, 28, 25, .1); }
.cue-media { position: relative; aspect-ratio: 4 / 5; background: #ece8e1; }
.cue-media > img:first-child { width: 100%; height: 100%; object-fit: cover; display: block; }
.cue-out { position: absolute; right: 8px; bottom: 8px; width: 34%; aspect-ratio: 4 / 5; object-fit: cover;
  border: 2px solid #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.cue-media .pill { position: absolute; left: 8px; top: 8px; }
.noimg { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 13px; }
.cue-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.cue-code { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.cue-meta { color: var(--muted); font-size: 13px; }
.cue-sku { font-size: 12px; font-weight: 600; color: var(--ok); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.chip { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: #f1ede6; color: #4d4740; white-space: nowrap;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; letter-spacing: .02em; }
.pill-in_progress { background: var(--warn-bg); color: var(--warn); }
.pill-approved { background: var(--ok-bg); color: var(--ok); }

/* files */
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.file { position: relative; }
.file img { width: 112px; height: 140px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; background: #ece8e1; }
.card-layout .panel:first-child .file:first-child img { width: 180px; height: 225px; }
.file-doc { display: flex; flex-direction: column; justify-content: center; gap: 6px; width: 112px; height: 140px; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px; background: #faf8f5; text-decoration: none; }
.file-doc .ext { font-weight: 800; font-size: 15px; color: var(--accent); }
.file-doc .fname { font-size: 11px; color: var(--muted); word-break: break-all; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.file-x { position: absolute; top: -7px; right: -7px; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line);
  background: #fff; color: var(--danger); font-size: 16px; line-height: 1; cursor: pointer; box-shadow: var(--shadow); }
.note { white-space: pre-wrap; background: #faf8f5; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.code-line { margin: 0 0 10px; }
.link { color: var(--accent); word-break: break-all; }

/* empty / login / busy */
.empty { text-align: center; padding: 60px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.login-card h1 { margin: 0; }
.login-card .btn { margin-top: 18px; }
.busy { position: fixed; inset: 0; background: rgba(30, 28, 25, .45); display: grid; place-items: center; z-index: 50; }
.busy[hidden] { display: none; }
.busy-box { background: #fff; padding: 22px 26px; border-radius: 14px; text-align: center; min-width: 220px; }
.busy-box p { margin: 12px 0 0; font-weight: 600; }
.spinner { width: 34px; height: 34px; margin: 0 auto; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 480px) {
  .wrap { padding: 12px 12px 40px; }
  .file img, .file-doc { width: 96px; height: 120px; }
  .card-layout .panel:first-child .file:first-child img { width: 150px; height: 188px; }
  .topbar .btn-ghost { font-size: 0; }
  .topbar .btn-ghost::after { content: "Log out"; font-size: 14px; }
}
