:root {
  --bg: #ffffff;
  --panel: #faf9f7;
  --well: #f3f2ef;
  --ink: #1c1b19;
  --muted: #6f6c66;
  --faint: #a19d95;
  --line: #e7e4de;
  --line-strong: #d3cfc7;
  --accent: #1c1b19;
  --focus: #8a6d3b;
  --sold: #c0392b;
  --ok: #3d7a4f;
  --hold: #b7791f;
  --danger: #a3302a;
  --radius: 6px;
  --serif: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: clamp(16px, 4vw, 40px);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: inherit; }

/* ------------------------------------------------------------------ layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 14px var(--gutter);
  background: rgba(255,255,255,.94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--serif); font-size: 22px; letter-spacing: .01em; text-decoration: none; white-space: nowrap; }
.brand small { font-family: var(--sans); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-left: 10px; }
.topbar .spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }
main { padding: 24px var(--gutter) 120px; max-width: 1400px; margin: 0 auto; }

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: #fff; cursor: pointer;
  font-size: 14px; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); }
.btn.danger { color: var(--danger); border-color: #e8c9c6; }
.btn.danger:hover { border-color: var(--danger); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--panel); }
.login { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 36px 28px; }
.login h1 { font-family: var(--serif); font-weight: 500; font-size: 34px; margin: 0; text-align: center; }
.login p.sub { text-align: center; color: var(--muted); margin: 4px 0 28px; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; }
.login .btn { width: 100%; margin-top: 8px; }
.login .note { color: var(--faint); font-size: 12px; text-align: center; margin: 18px 0 0; }

/* ------------------------------------------------------------------ fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; min-width: 0; }
.field > label, .field > .label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.field .hint { font-size: 12px; color: var(--faint); }
.field .err { font-size: 12px; color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: #fff;
  font-size: 16px; /* prevents iOS zoom on focus */
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(138,109,59,.15); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 42px; padding: 10px 0; cursor: pointer; font-size: 15px; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--ink); flex: none; }
.check small { display: block; color: var(--faint); font-size: 12px; }
.lock { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); border: 1px solid var(--line); border-radius: 3px; padding: 1px 5px; }
.req { color: var(--sold); }

.grid { display: grid; gap: 0 18px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-6 { grid-column: span 6; }
.span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; }
@media (max-width: 720px) {
  .span-8, .span-6, .span-4 { grid-column: span 12; }
  .span-3 { grid-column: span 6; }
}

/* ----------------------------------------------------------------- library */
.lib-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.lib-head h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(30px, 4vw, 42px); margin: 0; line-height: 1.1; }
.stats { color: var(--muted); font-size: 13px; margin-top: 6px; }
.toolbar { display: grid; gap: 10px; grid-template-columns: minmax(200px, 2fr) repeat(5, minmax(120px, 1fr)); margin-bottom: 24px; }
.toolbar select, .toolbar input { min-height: 40px; font-size: 14px; }
@media (max-width: 1000px) { .toolbar { grid-template-columns: repeat(3, minmax(0, 1fr)); } .toolbar .search { grid-column: span 3; } }
@media (max-width: 560px) { .toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); } .toolbar .search { grid-column: span 2; } }

.cards { display: grid; gap: 28px 22px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
@media (max-width: 560px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 12px; } }
.card { text-decoration: none; display: block; color: inherit; }
.card .frame { aspect-ratio: 1; background: var(--well); border-radius: 4px; display: grid; place-items: center; overflow: hidden; position: relative; }
.card .frame img { width: 100%; height: 100%; object-fit: contain; padding: 10px; transition: transform .25s ease; }
.card:hover .frame img { transform: scale(1.02); }
.card .noimg { color: var(--faint); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.card .flags { position: absolute; top: 8px; left: 8px; display: flex; gap: 6px; }
.tag { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; background: #fff; border: 1px solid var(--line); border-radius: 3px; padding: 2px 6px; color: var(--muted); }
.card h3 { font-family: var(--serif); font-weight: 500; font-size: 19px; line-height: 1.2; margin: 10px 0 2px; }
.card .meta { color: var(--muted); font-size: 13px; line-height: 1.45; }
.card .row { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 13px; }

.status { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.available { background: var(--ok); } .dot.sold { background: var(--sold); }
.dot.on_hold { background: var(--hold); } .dot.commission { background: #5a6fa8; }

.empty { text-align: center; padding: 80px 16px; border: 1px dashed var(--line-strong); border-radius: 10px; color: var(--muted); }
.empty h2 { font-family: var(--serif); font-weight: 500; font-size: 28px; margin: 0 0 8px; color: var(--ink); }

/* ------------------------------------------------------------------ editor */
.editor { max-width: 980px; margin: 0 auto; }
.crumbs { margin-bottom: 8px; }
.editor h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(28px, 4vw, 40px); margin: 0 0 4px; line-height: 1.15; word-break: break-word; }
.editor .updated { color: var(--faint); font-size: 12px; margin-bottom: 20px; }
.section { border-top: 1px solid var(--line); padding: 26px 0 10px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.section h2 { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; font-weight: 600; margin: 0; }
.section-head p { margin: 0; color: var(--faint); font-size: 12px; }
.subhead { font-size: 13px; font-weight: 600; margin: 8px 0 12px; grid-column: span 12; display: flex; gap: 8px; align-items: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line-strong); border-radius: 999px; padding: 6px 12px; background: #fff; cursor: pointer; font-size: 14px; min-height: 34px; }
.chip[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* images */
.drop {
  border: 1.5px dashed var(--line-strong); border-radius: 10px; padding: 22px 16px; text-align: center;
  background: var(--panel); color: var(--muted); cursor: pointer; transition: background .15s, border-color .15s;
}
.drop.over { background: #f1ece2; border-color: var(--focus); }
.drop strong { color: var(--ink); font-weight: 600; }
.drop small { display: block; margin-top: 4px; color: var(--faint); font-size: 12px; }
.tiles { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-top: 16px; }
@media (max-width: 560px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.tile { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.tile.main { border-color: var(--ink); }
.tile .pic { aspect-ratio: 1; background: var(--well); display: grid; place-items: center; position: relative; }
.tile .pic img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.tile .badge { position: absolute; top: 6px; left: 6px; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; background: var(--ink); color: #fff; border-radius: 3px; padding: 2px 6px; }
.tile .badge.new { left: auto; right: 6px; background: var(--focus); }
.tile .info { padding: 8px 10px 4px; font-size: 12px; color: var(--muted); line-height: 1.4; min-height: 42px; }
.tile .info b { color: var(--ink); font-weight: 600; }
.tile .acts { display: flex; gap: 2px; padding: 4px 6px 8px; flex-wrap: wrap; }
.tile .acts .btn { min-height: 30px; padding: 0 8px; font-size: 12px; }
.tile .acts .rm { margin-left: auto; color: var(--danger); }

/* save bar */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(255,255,255,.97); border-top: 1px solid var(--line);
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
}
.savebar .inner { max-width: 980px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.savebar .state { color: var(--muted); font-size: 13px; flex: 1; min-width: 0; }
.savebar .state.dirty { color: var(--hold); }

.danger-zone { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }

/* ----------------------------------------------------------- toasts & busy */
#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.15); animation: pop .18s ease-out; }
.toast.error { background: var(--danger); }
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
#busy { position: fixed; inset: 0; z-index: 90; background: rgba(255,255,255,.7); display: grid; place-items: center; padding: 16px; }
.busy-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 18px 22px; display: flex; gap: 12px; align-items: center; box-shadow: 0 10px 40px rgba(0,0,0,.08); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line-strong); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { color: var(--muted); padding: 60px 0; text-align: center; }
.login .err { color: var(--danger); font-size: 13px; margin-bottom: 8px; }
@media (max-width: 560px) {
  .topbar { gap: 8px; }
  .who { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .brand small { display: none; }
  .topbar .btn.small { padding: 0 4px; }
}

a.who { text-decoration: none; border-bottom: 1px solid transparent; }
a.who:hover { color: var(--ink); border-bottom-color: var(--line-strong); }
.linky { background: none; border: 0; padding: 0; color: var(--muted); font-size: 12px; cursor: pointer; text-decoration: underline; }
.linky:hover { color: var(--ink); }
.login .ok, .field > .ok { color: var(--ok); font-size: 13px; margin-bottom: 8px; }
