:root {
  --bg: #f6f6f4; --panel: #ffffff; --ink: #18181b; --muted: #71717a; --line: #e7e5e4;
  --accent: #5b4cf5; --accent-ink: #fff; --soft: #f1f0ff; --ok: #15803d; --warn: #b45309; --danger: #dc2626;
  --r: 12px; --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 8px 24px rgb(0 0 0 / .05);
  font: 14px/1.5 ui-sans-serif, -apple-system, "Inter", "Segoe UI", system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d0d10; --panel: #17171b; --ink: #f4f4f5; --muted: #a1a1aa; --line: #2a2a31; --soft: #22203a; --accent: #7c6ff7; --shadow: none; }
}
* { box-sizing: border-box; }
[x-cloak] > * { visibility: hidden; }
body { margin: 0; background: var(--bg); color: var(--ink); }
h1, h2, h3 { margin: 0; letter-spacing: -.02em; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; font-weight: 600; }
a { color: var(--accent); cursor: pointer; text-decoration: none; }
small { display: block; font-size: 12px; }
.muted { color: var(--muted); }
.ok { color: var(--ok); } .warn { color: var(--warn); }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; }
.pad { padding: 20px; }
.stack { display: grid; gap: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 0; }

input, select, textarea {
  width: 100%; font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--soft); }
input[type=color] { padding: 2px; height: 38px; cursor: pointer; }
textarea { resize: vertical; }
label, .field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  font: inherit; font-weight: 500; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); transition: .15s;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; padding: 6px 10px; }
.btn.ghost:hover:not(:disabled) { background: var(--bg); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); margin-left: auto; white-space: nowrap; }
.badge.ready { background: #dcfce7; color: var(--ok); }
.badge.posted { background: var(--soft); color: var(--accent); }
@media (prefers-color-scheme: dark) { .badge.ready { background: #12301d; color: #4ade80; } }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 32px; display: grid; gap: 14px; }
.logo { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 24px; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--panel); }
.side .logo { padding: 0 10px; }
.side nav { display: grid; gap: 2px; }
.side nav a { color: var(--ink); padding: 8px 10px; border-radius: 8px; }
.side nav a:hover { background: var(--bg); }
.side nav a.on { background: var(--soft); color: var(--accent); font-weight: 600; }
.me { margin-top: auto; display: grid; gap: 6px; padding: 0 10px; font-size: 13px; }
.me a { color: var(--muted); }
.main { padding: 28px 32px; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.head p { margin: 4px 0 0; }
.filters { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 10px; margin-bottom: 20px; }
.empty { text-align: center; padding: 60px 0; }

/* grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.thumb { position: relative; aspect-ratio: 4/5; background: var(--bg); display: grid; place-items: center; overflow: hidden; }
.thumb.video_landscape { aspect-ratio: 16/9; }
.thumb.video_portrait, .thumb.story { aspect-ratio: 9/16; max-height: 320px; width: 100%; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; }
.thumb .slide { position: absolute; inset: 0; }
.thumb .slide video { object-fit: contain; background: #000; }
.thumb .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgb(255 255 255 / .85); color: #111; font-size: 20px; line-height: 1; cursor: pointer; opacity: 0; transition: opacity .15s; box-shadow: 0 2px 8px rgb(0 0 0 / .2); }
.thumb .prev { left: 8px; } .thumb .next { right: 8px; }
.thumb .dots { position: absolute; bottom: 8px; left: 0; right: 0; display: flex; justify-content: center; gap: 5px; }
.thumb .dots span { width: 6px; height: 6px; border-radius: 50%; background: rgb(255 255 255 / .5); cursor: pointer; box-shadow: 0 0 2px rgb(0 0 0 / .4); }
.thumb .dots span.on { background: #fff; }
.thumb .del { position: absolute; top: 8px; left: 8px; width: 30px; height: 30px; border-radius: 8px; border: 0; background: rgb(0 0 0 / .55); color: #fff; cursor: pointer; opacity: 0; transition: opacity .15s; }
.thumb .del:hover { background: var(--danger); }
.tile:hover .nav, .tile:hover .del { opacity: 1; }
@media (hover: none) { .thumb .nav, .thumb .del { opacity: 1; } }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.stat { padding: 16px; display: grid; gap: 4px; }
.stat b { font-size: 20px; letter-spacing: -.02em; }
.bar { height: 6px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }
.thumb .count { position: absolute; top: 8px; right: 8px; background: rgb(0 0 0 / .6); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 99px; }
.tile-body { padding: 12px 14px; display: grid; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.brand { padding: 16px; display: grid; gap: 12px; cursor: pointer; }
.brand-logo { width: 40px; height: 40px; border-radius: 10px; object-fit: contain; background: var(--bg); }
.swatches { display: flex; gap: 6px; }
.swatches span { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); }

/* tables */
.table { overflow: hidden; }
.tr { display: grid; grid-template-columns: 1.3fr auto 1.5fr; align-items: center; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.tr:last-child { border-bottom: 0; }
.tr .badge { margin: 0; justify-self: start; }
.actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.models { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.models input { padding: 6px 9px; font-size: 12px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgb(10 10 15 / .45); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 24px; z-index: 10; }
.sheet { background: var(--panel); border-radius: 16px; width: min(560px, 100%); max-height: calc(100vh - 48px); overflow: auto; box-shadow: 0 20px 60px rgb(0 0 0 / .25); }
.sheet.wide { width: min(1180px, 100%); }
.sheet.narrow { width: min(440px, 100%); }
.sheet-head { position: sticky; top: 0; z-index: 1; background: var(--panel); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.sheet-head select { width: auto; }
.sheet-foot { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.title-input { font-size: 18px; font-weight: 600; border-color: transparent; padding-left: 4px; }
.editor { display: grid; grid-template-columns: 1fr 1fr; }
.editor .col { padding: 20px; display: grid; gap: 14px; align-content: start; }
.editor .col + .col { border-left: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 50%, var(--panel)); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 12px; padding: 5px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.preview-cap pre, .caption-box, .pre { white-space: pre-wrap; font: inherit; background: var(--bg); padding: 12px; border-radius: 8px; margin: 8px 0 0; }
.preview-cap summary { cursor: pointer; font-size: 13px; font-weight: 500; }

.drop { border: 1.5px dashed var(--line); border-radius: var(--r); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; font-weight: 400; }
.drop:hover { border-color: var(--accent); color: var(--accent); }
.drop.busy { opacity: .6; pointer-events: none; }
.media-list { display: grid; gap: 8px; }
.media-item { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.media-item img, .media-item video { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; background: var(--bg); }
.media-meta { min-width: 0; }
.media-meta b { display: block; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-actions { display: flex; }

.ai-box { display: grid; gap: 10px; padding: 16px; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line); }
.ai-box hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 4px 0; }
.ai-box select { width: 90px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--bg); padding: 3px; border-radius: 9px; }
.seg button { font: inherit; font-size: 12px; border: 0; background: none; color: var(--muted); padding: 6px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.ai-result { max-height: 360px; overflow: auto; font-size: 13px; border-top: 1px solid var(--line); padding-top: 8px; }
.ai-result p { margin: 0 0 10px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }
.job { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; padding: 8px 10px; border-radius: 8px; background: var(--soft); color: var(--accent); }
.job.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.steps { margin: 0; padding-left: 18px; display: grid; gap: 4px; }

.strip { display: grid; gap: 12px; }
.strip figure { margin: 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--panel); }
.strip img, .strip video { width: 100%; max-height: 520px; object-fit: contain; background: #000; display: block; }
.strip figcaption { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; font-size: 12px; color: var(--muted); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500; z-index: 20; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side nav { display: flex; flex-wrap: wrap; }
  .me { margin: 0 0 0 auto; grid-auto-flow: column; align-items: center; }
  .main { padding: 20px 16px; }
  .filters, .editor, .tr, .models, .stats { grid-template-columns: 1fr; }
  .editor .col + .col { border-left: 0; border-top: 1px solid var(--line); }
  .sheet-head { flex-wrap: wrap; }
  .modal { padding: 0; }
  .sheet { max-height: 100vh; border-radius: 0; }
}
