:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6f6f6a;
  --line: #deded8;
  --accent: #b5481f;
  --ok: #2f7d4f;
  --warn: #b07a12;
  --bad: #b3261e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a, .topbar nav .soon { padding: 5px 8px; border-radius: 6px; text-decoration: none; font-size: 14px; }
.topbar nav a { color: var(--text); }
.topbar nav a:hover { background: var(--bg); }
.topbar nav a.active { background: var(--text); color: var(--panel); }
.topbar nav .soon { color: #b9b9b2; cursor: default; }

main { max-width: 1400px; margin: 0 auto; padding: 20px; }
h1 { font-size: 22px; margin: 0 0 8px; }
.muted { color: var(--muted); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin-top: 20px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

h2 { font-size: 17px; margin: 28px 0 10px; }
.small { font-size: 13px; }
.count { font-weight: 400; font-size: 18px; }
button, .button {
  font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--text);
  background: var(--text); color: var(--panel); cursor: pointer; text-decoration: none; display: inline-block;
}
button.secondary, .button.secondary { background: var(--panel); color: var(--text); }
button[type="button"] { background: var(--panel); color: var(--text); border-color: var(--line); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
textarea { width: 100%; }
code { font-size: 13px; background: #efefea; padding: 1px 4px; border-radius: 4px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sync { font-size: 13px; }
.sync.running { color: var(--warn); }
.sync.ok { color: var(--ok); }
.sync.bad, .bad { color: var(--bad); }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); }
.notice.bad { border-color: var(--bad); }
.notice.ok { border-color: var(--ok); color: var(--ok); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.filters, .bulkbar {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 12px 0;
}
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.bulkbar { position: sticky; top: 0; z-index: 5; align-items: center; }
.bulkbar .or { color: var(--muted); font-size: 13px; }
.tag-picker { position: relative; }
.tag-picker summary { cursor: pointer; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag-picker-body {
  position: absolute; top: 40px; left: 0; z-index: 10; width: min(560px, 90vw); max-height: 60vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.tag-picker fieldset { border: 0; padding: 4px 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.tag-picker legend { font-size: 12px; color: var(--muted); padding: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card {
  position: relative; display: flex; flex-direction: column; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; color: inherit; text-decoration: none; cursor: pointer;
}
.card:has(input:checked) { outline: 3px solid var(--accent); }
.card input[type="checkbox"] { position: absolute; top: 8px; left: 8px; width: 20px; height: 20px; }
.card img { width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; background: #ddd; }
.card-body { padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; }
.card .title { font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none; }
.card .meta { font-size: 12px; color: var(--muted); display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: #ecebe6; }
.tag.g-product { background: #f3dfd4; }
.tag.g-style { background: #dfe7f1; }
.tag.g-shot { background: #e3efe2; }
.tag.g-material { background: #efe8d6; }
.flag { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: #fbe3df; color: var(--bad); }
.flag.f-near_duplicate { background: #fdf0d6; color: var(--warn); }

.pager { display: flex; gap: 8px; margin: 16px 0; flex-wrap: wrap; }
.photo-detail { display: grid; grid-template-columns: minmax(0, 480px) 1fr; gap: 24px; align-items: start; }
.photo-detail img.big { width: 100%; border-radius: 10px; }
.tag-editor fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.tag-editor legend { font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (max-width: 760px) { .photo-detail { grid-template-columns: 1fr; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; margin: 16px 0; }
.panel h2 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px 16px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid label.check { flex-direction: row; color: var(--text); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.preview { width: 100%; border-radius: 8px; border: 1px solid var(--line); }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.arch { font-size: 10px; padding: 0 4px; border-radius: 4px; background: #e7eef5; color: #3b5a78; }

.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 14px; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafaf7; }
.table tr.inactive td { opacity: .55; }
.warn { color: var(--warn); }
label.block { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-top: 12px; }
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.preview-box { margin-top: 0; }
.sample { border-top: 1px dashed var(--line); padding: 8px 0; }
.sample div { white-space: pre-wrap; }
.sample.title div { font-weight: 600; }
.ok-text { color: var(--ok); }
.small-btn { padding: 2px 8px; font-size: 12px; }
details.panel summary { cursor: pointer; font-weight: 600; }
.segments { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.segment-card { display: flex; flex-direction: column; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.segment-card h3 { margin: 0; }
.segment-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
#locations-table { border-radius: 8px; overflow: hidden; }

.legend { display: flex; gap: 8px; flex-wrap: wrap; }
.legend .cell { padding: 4px 10px; border-radius: 6px; font-size: 13px; }
.cell.active { background: #d8eedd; }
.cell.queued { background: #fdf0d6; }
.cell.risk { background: #f8d4cf; }
.cell.paused { background: #e4e4df; }
.cell.hole { background: #fff; border: 1px dashed #c9c9c2; }
.matrix-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.matrix { border-collapse: collapse; font-size: 13px; }
.matrix th, .matrix td { border: 1px solid var(--line); padding: 4px; text-align: center; }
.matrix th.prod { text-align: left; white-space: nowrap; padding: 4px 10px; position: sticky; left: 0; background: var(--panel); }
.matrix th.seg { background: #fafaf7; }
.matrix th.loc { height: 120px; vertical-align: bottom; white-space: nowrap; }
.matrix th.loc span { writing-mode: vertical-rl; transform: rotate(180deg); display: inline-block; }
.matrix td.cell { width: 30px; height: 30px; }
.matrix td.cell a { color: var(--text); text-decoration: none; font-weight: 600; display: block; }
.matrix td.cell label { display: block; cursor: pointer; }
.status { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #ecebe6; white-space: nowrap; }
.status.s-active { background: #d8eedd; color: #1f5e36; }
.status.s-draft { background: #fdf0d6; color: #7a5410; }
.status.s-archived { background: #eee; color: #888; }
.pair-text { white-space: pre-wrap; font-size: 13px; max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs img { width: 120px; border-radius: 6px; }
.who { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.login { max-width: 420px; margin: 40px auto; }
code.wrap { white-space: pre-wrap; word-break: break-all; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin: 16px 0; }
.stat { display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; color: var(--text); text-decoration: none; }
.stat b { font-size: 28px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat em { font-style: normal; font-size: 12px; }
.presets .card { cursor: default; }
.ab-card { border-top: 1px solid var(--line); padding: 10px 0; }
.table tr.win td { background: #e3efe2; font-weight: 600; }
.chat .msg { max-width: 80%; margin: 6px 0; padding: 8px 10px; border-radius: 10px; background: #f0efe9; white-space: pre-wrap; }
.chat .msg.out { margin-left: auto; background: #e3efe2; }
.seasons select { font-size: 11px; padding: 2px; }
.seasons td.lv2 { background: #d8eedd; }
.seasons td.lv0 { background: #eee; }
.seasons .now { outline: 2px solid var(--accent); }
.matrix tr.in-season th.prod { background: #d8eedd; }
