:root {
  --bg: #f6f7f9; --card: #fff; --ink: #1c2330; --muted: #667085; --line: #e1e5ea;
  --accent: #1f5eff; --accent-ink: #fff; --danger: #c0352b; --ok: #1a7f4b;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151b; --card: #1a2029; --ink: #e8ecf2; --muted: #98a2b3; --line: #2a323e; --accent: #5b8cff; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin-top: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.grow { flex: 1; }

header { display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
main { max-width: 1200px; margin: 0 auto; padding: 1rem; }

button, .btn, select, input, textarea { font: inherit; color: inherit; }
button, .btn { display: inline-block; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); cursor: pointer; text-decoration: none; }
button:hover, .btn:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ghost { background: transparent; }
.danger { color: var(--danger); }
select, input:not([type=range]), textarea { width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .6rem; }
label > :is(input, select, textarea) { margin-top: .25rem; color: var(--ink); }
header select { width: auto; min-width: 12rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.card.center { max-width: 26rem; margin: 15vh auto 0; text-align: center; }
.bar { display: flex; gap: .5rem; align-items: center; margin-bottom: .75rem; flex-wrap: wrap; }
.bar select { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .75rem; align-items: end; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; text-align: left; padding: 0; }
.tile .thumb { aspect-ratio: 4/3; background: var(--line); display: grid; place-items: center; color: var(--muted); font-size: .85rem; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .meta { padding: .5rem .6rem; font-size: .8rem; }
.tile .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.pill { font-size: .72rem; padding: .1rem .5rem; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.pill.published { color: var(--ok); border-color: var(--ok); }
.pill.optimised { color: var(--accent); border-color: var(--accent); }
.pill.err { color: var(--danger); border-color: var(--danger); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 10; overflow: auto; padding: 1rem; }
.sheet { background: var(--bg); border-radius: 14px; max-width: 1150px; margin: 0 auto; }
.sheet-head { display: flex; gap: .6rem; align-items: center; padding: .75rem 1rem; border-bottom: 1px solid var(--line); }
.sheet-body { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1rem; padding: 1rem; }
@media (max-width: 800px) { .sheet-body { grid-template-columns: 1fr; } }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .6rem; }
.row2 > * { margin-bottom: 0; }

.crop-wrap { position: relative; display: inline-block; max-width: 100%; line-height: 0; user-select: none; touch-action: none; }
.crop-wrap img { max-width: 100%; max-height: 60vh; display: block; }
.crop { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.5); cursor: move; }
.crop i { position: absolute; width: 16px; height: 16px; background: #fff; border: 2px solid var(--accent); border-radius: 3px; }
.crop i[data-h=nw] { left: -9px; top: -9px; cursor: nwse-resize; }
.crop i[data-h=ne] { right: -9px; top: -9px; cursor: nesw-resize; }
.crop i[data-h=sw] { left: -9px; bottom: -9px; cursor: nesw-resize; }
.crop i[data-h=se] { right: -9px; bottom: -9px; cursor: nwse-resize; }
.result img { max-width: 100%; max-height: 40vh; border-radius: 8px; background: var(--line); }

.dom { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.dom .users { flex-basis: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .4rem 0; }
.chip { display: inline-flex; gap: .4rem; align-items: center; padding: .15rem .6rem; border: 1px solid var(--line); border-radius: 99px; font-size: .85rem; }
.chip button { border: 0; padding: 0; background: none; color: var(--muted); }
