:root {
  --bg: #f6f7fb; --surface: #fff; --surface-2: #f1f3f9; --border: #e3e6ef; --text: #171a2b; --muted: #636b86;
  --brand: #4f46e5; --brand-ink: #fff; --brand-soft: #eef0ff; --ok: #0e9f6e; --ok-soft: #e3f7ef; --warn: #b7791f; --warn-soft: #fdf3dc;
  --danger: #d1344a; --danger-soft: #fdeaed; --shadow: 0 1px 2px rgba(20,24,50,.06), 0 4px 16px rgba(20,24,50,.04);
  --radius: 12px; --sidebar: 248px; --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1020; --surface: #161a2e; --surface-2: #1d2238; --border: #2a3050; --text: #e9ecf8; --muted: #9aa3c4;
    --brand: #7c78ff; --brand-ink: #0e1020; --brand-soft: #23284a; --ok: #3ccf91; --ok-soft: #12332a; --warn: #f0b84a; --warn-soft: #3a2f14;
    --danger: #ff6b81; --danger-soft: #3b1a22; --shadow: 0 1px 2px rgba(0,0,0,.4); }
}
* { box-sizing: border-box; }
html { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 15px; color: var(--text); background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
h1,h2,h3 { margin: 0; line-height: 1.25; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; } small, .muted { color: var(--muted); } code, .mono { font-family: var(--mono); font-size: .88em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.icon { width: 18px; height: 18px; flex: none; }

.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--text); padding: 4px 8px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); }
.brand-mark .icon { width: 15px; height: 15px; fill: currentColor; }
.project-switch select { width: 100%; font-weight: 600; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a, .nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover, .nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active, .nav-link.active { background: var(--brand-soft); color: var(--brand); }
.nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 14px 10px 4px; font-weight: 600; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.me { display: flex; align-items: center; gap: 10px; }
.me form { margin-left: auto; }
.me-text { min-width: 0; display: flex; flex-direction: column; } .me-text strong, .me-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 18px 28px 0; }
.topbar h1 { font-size: 1.5rem; }
.menu-btn { display: none; }
.page { padding: 18px 28px 48px; max-width: 1280px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card > h2 { margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 18px; } .grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stat { display: flex; flex-direction: column; gap: 2px; } .stat b { font-size: 1.8rem; letter-spacing: -.02em; } .stat span { color: var(--muted); font-size: .85rem; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; } .toolbar .grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .spread { justify-content: space-between; }

.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; line-height: 1.2; }
.btn:hover { background: var(--surface-2); text-decoration: none; } .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); } .btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-danger { color: var(--danger); } .btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: .85rem; } .btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--muted); cursor: pointer; display: grid; place-items: center; } .icon-btn:hover { background: var(--surface-2); color: var(--text); }

label { font-weight: 600; font-size: .88rem; display: block; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=search], input[type=datetime-local], input[type=date], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit; }
textarea { min-height: 84px; resize: vertical; } textarea.mono { font-family: var(--mono); font-size: .85rem; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); }
.field { margin-bottom: 14px; } .field .help { color: var(--muted); font-size: .8rem; margin-top: 3px; }
.field-error { color: var(--danger); font-size: .82rem; margin: 4px 0 0; } .has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; } .check label { margin: 0; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 18px; }
.req::after { content: " *"; color: var(--danger); }

table { width: 100%; border-collapse: collapse; } th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); } td.actions { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; } td .title { font-weight: 600; color: var(--text); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge-published, .badge-released, .badge-ready, .badge-reviewed, .badge-none { background: var(--ok-soft); color: var(--ok); }
.badge-draft, .badge-soft_update, .badge-machine { background: var(--warn-soft); color: var(--warn); }
.badge-archived, .badge-withdrawn, .badge-force_update, .badge-failed, .badge-maintenance { background: var(--danger-soft); color: var(--danger); }
.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; border: 1px solid; }
.flash-success { background: var(--ok-soft); color: var(--ok); border-color: transparent; } .flash-error { background: var(--danger-soft); color: var(--danger); border-color: transparent; } .flash-info { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); } .empty .icon { width: 36px; height: 36px; opacity: .5; margin-bottom: 8px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding-top: 14px; color: var(--muted); font-size: .88rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab { padding: 8px 14px; border: 0; border-bottom: 2px solid transparent; background: none; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; margin-bottom: -1px; }
.tab[aria-selected=true] { color: var(--brand); border-color: var(--brand); }
.js .tab-panel[hidden] { display: none; } html:not(.js) .tab-panel + .tab-panel { margin-top: 18px; }
.secret { font-family: var(--mono); background: var(--surface-2); padding: 10px 12px; border-radius: 9px; word-break: break-all; display: flex; gap: 10px; align-items: center; justify-content: space-between; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.media-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; color: var(--text); cursor: pointer; text-align: left; padding: 0; font: inherit; }
.media-card:hover { border-color: var(--brand); text-decoration: none; } .media-card.selected { outline: 2px solid var(--brand); }
.thumb { aspect-ratio: 16/10; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); overflow: hidden; position: relative; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; } .thumb .icon { width: 34px; height: 34px; }
.thumb .pill { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: .72rem; padding: 2px 7px; border-radius: 99px; }
.media-meta { padding: 9px 11px; } .media-meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .media-meta small { font-size: .78rem; }
.dropzone { border: 2px dashed var(--border); border-radius: 12px; padding: 26px; text-align: center; color: var(--muted); transition: .15s; margin-bottom: 18px; }
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); } .dropzone input { display: none; }
.uploads { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; } .upload { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; } .progress > i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .15s; }
.media-field { display: flex; gap: 12px; align-items: center; } .media-field .preview { width: 96px; height: 60px; border-radius: 8px; background: var(--surface-2); overflow: hidden; display: grid; place-items: center; color: var(--muted); flex: none; }
.media-field .preview img { width: 100%; height: 100%; object-fit: cover; }
dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 0; width: min(860px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10,12,28,.55); } .dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); } .dialog-body { padding: 18px; max-height: 70vh; overflow: auto; }

.tgrid th:first-child, .tgrid td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 230px; }
.tgrid textarea { min-height: 38px; height: 38px; padding: 6px 9px; font-size: .88rem; min-width: 220px; } .tgrid textarea.saving { border-color: var(--warn); } .tgrid textarea.saved { border-color: var(--ok); } .tgrid textarea.failed { border-color: var(--danger); }
.tgrid td.keycell code { font-weight: 600; } .progress-bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 90px; } .progress-bar > i { display: block; height: 100%; background: var(--ok); }
.schema-row { display: grid; grid-template-columns: 1.1fr 1.1fr 1fr 1.4fr auto; gap: 8px; align-items: start; padding: 10px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--surface-2); }
.schema-row .check { margin-top: 6px; } .schema-row .more { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.rule { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: var(--surface-2); } .rule-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 12px; }
.spark { width: 100%; height: 60px; } .spark-line { fill: none; stroke: var(--brand); stroke-width: 2; vector-effect: non-scaling-stroke; } .spark-fill { fill: var(--brand-soft); opacity: .8; }
.bars { width: 100%; height: auto; } .bar { fill: var(--brand); } .bar:hover { opacity: .8; } .bar-label { fill: var(--muted); font-size: 10px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); animation: pop .2s; } .toast.error { background: var(--danger); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.share-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #0b0d1a; color: #eef0ff; }
.share-view .stage { width: min(960px, 100%); } .share-view video, .share-view img { width: 100%; max-height: 70vh; border-radius: 14px; background: #000; }
.share-view h1 { margin: 16px 0 6px; } .share-view .muted { color: #9aa3c4; }
.bare .auth-card { width: min(400px, 92vw); margin: 12vh auto 0; } .bare .auth-card .brand { justify-content: center; margin-bottom: 18px; font-size: 1.4rem; }
.bare:not(.share) { display: block; }
.draggable { cursor: grab; } .dragging { opacity: .4; } .grip { color: var(--muted); cursor: grab; }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; } .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; width: var(--sidebar); transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 60px rgba(0,0,0,.4); } .menu-btn { display: grid; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } .topbar, .page { padding-left: 16px; padding-right: 16px; } .schema-row { grid-template-columns: 1fr 1fr; }
}

.dot { display:inline-block; width:9px; height:9px; border-radius:50%; background:var(--muted); vertical-align:middle; }
.dot[data-s=reviewed], .tgrid textarea[data-status=reviewed] { --st: var(--ok); } .dot[data-s=reviewed] { background: var(--ok); }
.dot[data-s=machine] { background: #3b82f6; } .dot[data-s=draft] { background: var(--warn); }
.tgrid textarea { border-left: 4px solid var(--border); }
.tgrid textarea[data-status=reviewed] { border-left-color: var(--ok); } .tgrid textarea[data-status=machine] { border-left-color: #3b82f6; }
.tgrid textarea[data-status=draft], .tgrid textarea[data-status=needs_review] { border-left-color: var(--warn); }
.tgrid textarea.issue { border-color: var(--danger); background: var(--danger-soft); }

.group-rows { display: flex; flex-direction: column; gap: 10px; }
.group-row { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.group-grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 14px; min-width: 0; }
.group-tools { display: flex; flex-direction: column; gap: 2px; }
.gf label { font-size: .8rem; margin-bottom: 3px; } .gf .group-rows { grid-column: 1 / -1; }
.gf textarea { min-height: 54px; }
.reflist .ref-item { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--surface-2); }
.reflist .ref-title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
input[type=color] { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
