:root {
  --bg: #f6f7f9; --card: #fff; --line: #e4e7ec; --text: #1d2433; --muted: #6b7385;
  --accent: #2f5bea; --accent-2: #2448c2; --ok: #127a46; --ok-bg: #e5f6ec; --warn: #8a5a00; --warn-bg: #fff4d6;
  --err: #b42318; --err-bg: #fdecea; --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; }
.err-text { color: var(--err); }
.pad { display: block; padding: .3rem .75rem; }

.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: #141a29; color: #c9cfdd; display: flex; flex-direction: column; padding: 1rem .6rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { color: #fff; font-weight: 700; font-size: 1.15rem; padding: .25rem .75rem 1rem; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a { color: #c9cfdd; padding: .45rem .75rem; border-radius: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side nav a:hover { background: #222a3d; text-decoration: none; }
.side nav a.active { background: var(--accent); color: #fff; }
.navhead { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: #7c859b; padding: 1rem .75rem .3rem; display: flex; justify-content: space-between; }
.navhead a { color: #c9cfdd; padding: 0 !important; }
.me { border-top: 1px solid #2a3247; padding: .75rem .75rem 0; display: flex; justify-content: space-between; align-items: center; }
.me a { color: #fff; }
.main { padding: 1.75rem 2rem 3rem; max-width: 1200px; width: 100%; }

.head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.card.danger { border-color: #f3c4bf; }
.empty { text-align: center; padding: 2rem 1rem; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row > input[type=search], .row > input[name=name] { flex: 1; min-width: 200px; width: auto; }
.row > select { width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.narrow-form { max-width: 640px; }
.inline { display: inline; margin: 0; }

label { display: flex; flex-direction: column; gap: .3rem; font-weight: 550; font-size: .9rem; }
label.check { flex-direction: row; align-items: flex-start; gap: .5rem; font-weight: 400; }
label.check input { margin-top: .25rem; }
input, select, textarea { font: inherit; padding: .55rem .7rem; border: 1px solid #cfd4dd; border-radius: 8px; background: #fff; color: inherit; width: 100%; }
label.check input { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d4fb; border-color: var(--accent); }
textarea { resize: vertical; }
#content { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92rem; line-height: 1.6; min-height: 420px; }
.title-input { font-size: 1.4rem; font-weight: 650; border: 0; padding: .3rem 0; border-bottom: 1px solid var(--line); border-radius: 0; }
.title-input:focus { outline: none; border-color: var(--accent); }

.btn { display: inline-flex; align-items: center; gap: .3rem; font: inherit; font-weight: 550; padding: .5rem .95rem; border-radius: 8px; border: 1px solid #cfd4dd; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f1f3f7; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--err); background: var(--err-bg); }
.btn.small { padding: .3rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; color: #9aa3b8; cursor: pointer; font: inherit; padding: 0; }
button.link:hover { color: #fff; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
td { padding: .65rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.actions { display: flex; gap: .35rem; justify-content: flex-end; flex-wrap: wrap; }
table.kv th { width: 140px; text-transform: none; font-size: .9rem; letter-spacing: 0; border: 0; }
table.kv td { border: 0; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .12rem .5rem; border-radius: 99px; background: #eef0f4; color: #4a5266; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #b5e3c8; }
.flash.err { background: var(--err-bg); color: var(--err); border-color: #f3c4bf; }
.flash.warn { background: var(--warn-bg); color: var(--warn); border-color: #f0dc9e; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; }
.stat b { display: block; font-size: 1.7rem; }
.stat span { color: var(--muted); font-size: .85rem; }

.filters { display: flex; gap: .6rem; margin-bottom: 1rem; }
.filters input { max-width: 320px; } .filters select { max-width: 180px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; padding-top: 1rem; }

.editor { display: grid; grid-template-columns: 1fr 300px; gap: 1.25rem; align-items: start; }
.editor-side { position: sticky; top: 1rem; }
.tabs { display: flex; gap: .25rem; align-items: center; border-bottom: 1px solid var(--line); }
.tab { background: none; border: 0; padding: .45rem .8rem; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--text); border-color: var(--accent); font-weight: 600; }
.hint { margin-left: auto; }
.preview { min-height: 420px; border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.25rem; }
.cover-preview { width: 100%; border-radius: 8px; }
.upload { cursor: pointer; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem; }
.media-grid.small { grid-template-columns: repeat(3, 1fr); gap: .4rem; max-height: 300px; overflow-y: auto; }
.media-item { padding: 0; overflow: hidden; margin: 0; }
.media-item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #eef0f4; }
.media-item figcaption { padding: .6rem .75rem; display: flex; flex-direction: column; gap: .3rem; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb { padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer; background: #eef0f4; aspect-ratio: 1; }
.thumb:hover { border-color: var(--accent); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.flash-ok { border-color: var(--ok); }
ul.log { padding-left: 1.2rem; white-space: pre-wrap; }
ul.log li { margin-bottom: .3rem; }

.prose { line-height: 1.7; }
.prose img { max-width: 100%; border-radius: 8px; }
.prose pre { background: #141a29; color: #e6e9f0; padding: 1rem; border-radius: 8px; overflow-x: auto; }
.prose code { background: #eef0f4; padding: .1rem .3rem; border-radius: 4px; font-size: .9em; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { border-left: 3px solid var(--line); margin: 0; padding-left: 1rem; color: var(--muted); }

body.center { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.card.narrow { width: 100%; max-width: 400px; }
.card.narrow h1 { margin-bottom: 1rem; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .main { padding: 1rem; }
  .editor { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  table { display: block; overflow-x: auto; }
}
