/* Admin. Mobile first; tables turn into cards below 768px. */
:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1c1f24; --ink-2: #454b55; --muted: #5d6470; --line: #dde0e5;
  --primary: #1f4fd1; --primary-ink: #fff; --danger: #b42318; --ok: #117a3a; --warn: #9a6200;
  --focus: #1a5fd0; --radius: 8px; --gutter: 16px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); overflow-x: hidden; }
a { color: var(--primary); }
img { max-width: 100%; height: auto; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; background: #000; color: #fff; padding: 10px; z-index: 100; }
.skip:focus { top: 8px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .block { display: block; }
.mono, code, pre { font-family: var(--mono); font-size: .9em; }
.break { word-break: break-all; }
pre.code { background: #111; color: #eee; padding: 10px; border-radius: 6px; overflow-x: auto; }

/* Top bar and navigation */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; background: #111827; color: #fff; padding: 0 var(--gutter); min-height: 56px; }
.topbar a { color: #fff; }
.topbar-brand { font-weight: 700; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.topbar-view { font-size: .85rem; white-space: nowrap; }
.site-switch select { background: #1f2937; color: #fff; border: 1px solid #374151; border-radius: 6px; min-height: 40px; max-width: 42vw; padding: 0 8px; }
.nav-toggle { background: none; border: 1px solid #374151; color: #fff; border-radius: 6px; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.bars, .bars::before, .bars::after { content: ""; display: block; width: 18px; height: 2px; background: currentColor; position: relative; }
.bars::before { position: absolute; top: -6px; } .bars::after { position: absolute; top: 6px; }
.shell { display: block; }
.sidenav { background: #1f2937; }
.sidenav ul { list-style: none; margin: 0; padding: 6px 0; display: flex; flex-wrap: wrap; }
.sidenav a { display: block; color: #e5e7eb; text-decoration: none; padding: 10px 14px; min-height: 44px; }
.sidenav a[aria-current] { background: #374151; color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #60a5fa; }
.sidenav a:hover { background: #374151; }
.sidenav-user { border-top: 1px solid #374151; padding: 12px 14px; color: #e5e7eb; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: .9rem; }
.sidenav-user a { padding: 0; min-height: 0; display: inline; color: #fff; }
.sidenav-user .muted { color: #9ca3af; }
.linkish { background: none; border: 0; color: #93c5fd; text-decoration: underline; cursor: pointer; padding: 8px 0; font: inherit; }
/* With JS on small screens the navigation is a drawer. */
@media (max-width: 1023px) {
  .js .sidenav { display: none; }
  .js .sidenav.is-open { display: block; position: fixed; inset: 56px 0 0 0; overflow-y: auto; z-index: 25; }
  .js .sidenav ul { display: block; }
}
@media (min-width: 1024px) {
  .nav-toggle { display: none !important; }
  .shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 56px); }
  .sidenav { position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; display: flex; flex-direction: column; justify-content: space-between; }
  .sidenav ul { display: block; }
}
.content { padding: 18px var(--gutter) 96px; min-width: 0; outline: none; max-width: 1400px; }
@media (min-width: 768px) { :root { --gutter: 24px; } .content { padding-top: 24px; } }

/* Page head, panels */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.crumb { margin: 0 0 4px; font-size: .9rem; }
.status-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.danger-zone { border-color: #f1c6c2; }
.stack > * + * { margin-top: 14px; }
.narrow { max-width: 680px; }
.cols { display: grid; gap: 16px; }
@media (min-width: 900px) { .cols { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (min-width: 768px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; }
.stat strong { font-size: 1.6rem; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; }
.plain-list li:last-child { border-bottom: 0; }
.side-links li { flex-direction: row; }
details.collapsible > summary { cursor: pointer; list-style: none; display: flex; align-items: center; min-height: 44px; }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::before { content: "▸"; margin-right: 8px; transition: transform .15s; }
details.collapsible[open] > summary::before { transform: rotate(90deg); }
details.collapsible > summary h2 { margin: 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field, .field + .check, .check + .field, .fieldset + .field { margin-top: 14px; }
label, .label { font-weight: 600; font-size: .92rem; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=url], input[type=number],
input[type=date], input[type=datetime-local], input:not([type]), select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid #b8bec8; border-radius: 6px; background: #fff; color: var(--ink); font: inherit;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
input[type=color] { width: 64px; height: 44px; padding: 2px; border: 1px solid #b8bec8; border-radius: 6px; background: #fff; }
input[type=file] { max-width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
[aria-invalid=true] { border-color: var(--danger) !important; }
.input-title { font-size: 1.25rem; font-weight: 700; }
.input-prefix { display: flex; align-items: stretch; min-width: 0; }
.input-prefix span { display: flex; align-items: center; padding: 0 8px; background: #eef0f3; border: 1px solid #b8bec8; border-right: 0; border-radius: 6px 0 0 6px; color: var(--muted); font-size: .88rem; white-space: nowrap; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
.input-prefix input { border-radius: 0 6px 6px 0; min-width: 0; }
.hint { font-size: .84rem; color: var(--muted); margin: 0; font-weight: 400; }
.field-error { color: var(--danger); font-size: .88rem; margin: 0; font-weight: 600; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 400; min-height: 44px; }
.check input { width: 22px; height: 22px; flex-shrink: 0; }
.check-list { display: flex; flex-direction: column; max-height: 260px; overflow-y: auto; margin-bottom: 10px; }
.check-list .check { padding-left: calc(var(--depth, 0) * 18px); min-height: 40px; }
.fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 12px; margin: 0; min-width: 0; }
.fieldset legend { font-weight: 600; padding: 0 6px; }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-row .field + .field { margin-top: 0; }
.copy-field { font-family: var(--mono); font-size: .85rem; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 160px; }
form.inline { display: inline; }
.grid-form { display: grid; gap: 12px; }
.grid-form .field + .field { margin-top: 0; }
@media (min-width: 768px) { .grid-form { grid-template-columns: 1fr 1fr 220px auto; align-items: end; } }
.filters { display: grid; gap: 10px; margin-bottom: 8px; }
.filters .field + .field, .filters .check { margin-top: 0; }
@media (min-width: 640px) { .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .filters { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; } }
.more-filters > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--primary); }
.more-filters-grid { display: grid; gap: 10px; padding-top: 4px; }
.more-filters-grid .field + .field { margin-top: 0; }
@media (min-width: 640px) { .more-filters-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .more-filters { grid-column: 1 / -1; } .more-filters-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.filter-actions { display: flex; gap: 8px; align-items: flex-end; }
.view-switch { margin: 6px 0 12px; font-size: .9rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 6px;
  border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .88rem; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #173eaa; }
.btn-secondary { background: #fff; color: var(--ink); border-color: #b8bec8; }
.btn-secondary:hover { background: #f1f3f6; }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: #e9ecf0; }
.btn-danger { background: #fff; color: var(--danger); border-color: #e3a5a0; }
.btn-danger:hover { background: #fdecea; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row form { margin: 0; }
.upload-btn { position: relative; }

/* Flash and badges */
.flash { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; border: 1px solid; }
.flash p:last-child { margin-bottom: 0; }
.flash-success { background: #ecfdf3; border-color: #a6e3bf; color: #0b5129; }
.flash-error { background: #fef3f2; border-color: #f4b8b2; color: #8a1c12; }
.flash-info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #eef0f3; color: #374151; vertical-align: middle; }
.badge-published { background: #dcfce7; color: #14532d; }
.badge-draft { background: #eef0f3; color: #374151; }
.badge-scheduled { background: #e0e7ff; color: #312e81; }
.badge-archived { background: #f3f4f6; color: #6b7280; }
.badge-info { background: #dbeafe; color: #1e3a8a; }
.badge-warn { background: #fef3c7; color: #78350f; }

/* Tables: cards on phones, scrollable table on larger screens */
.table-wrap { width: 100%; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: #fafbfc; }
.cell-title a { font-weight: 600; }
.cell-actions { white-space: nowrap; }
.cell-actions > * { display: inline-flex; margin: 2px; }
@media (max-width: 767px) {
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table.responsive { background: none; }
  .table.responsive tr { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 8px 12px; }
  .table.responsive td { border: 0; padding: 4px 0; display: flex; gap: 10px; }
  .table.responsive td[data-label]::before { content: attr(data-label); flex: 0 0 96px; color: var(--muted); font-size: .8rem; font-weight: 600; padding-top: 2px; }
  .table.responsive td.cell-title { display: block; font-size: 1.02rem; }
  .table.responsive td.cell-title::before { display: none; }
  .table.responsive td.cell-actions { padding-top: 8px; white-space: normal; flex-wrap: wrap; }
}
@media (min-width: 768px) { .table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); } .table tr:last-child td { border-bottom: 0; } }
.pager { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-top: 14px; font-size: .9rem; }

/* Post editor */
.editor-grid { display: grid; gap: 16px; }
.editor-main > .field, .editor-main > .panel { margin-top: 0; margin-bottom: 16px; }
.editor-main { min-width: 0; }
.editor-side { min-width: 0; }
@media (min-width: 1100px) { .editor-grid { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; } .editor-side { position: sticky; top: 72px; } }
.action-bar { position: sticky; bottom: 0; z-index: 20; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line); padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  margin: 16px calc(-1 * var(--gutter)) 16px; backdrop-filter: blur(4px); }
.action-bar .btn { flex: 1 1 140px; max-width: 240px; }
@media (min-width: 768px) { .action-bar .btn { flex: 0 0 auto; } }
.repeater-row { border: 1px dashed #c7ccd4; border-radius: 6px; padding: 12px; margin-bottom: 12px; }
.row-tools { margin-top: 10px; }
.menu-row { display: grid; gap: 10px; }
.menu-row .field + .field { margin-top: 0; }
@media (min-width: 900px) { .menu-row { grid-template-columns: repeat(4, minmax(0, 1fr)); } .menu-row .row-tools { grid-column: 1 / -1; } }
.meta-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; }
.meta-list dt { font-weight: 600; } .meta-list dd { margin: 0; }
.revision-body { border: 1px solid var(--line); padding: 12px; border-radius: 6px; overflow-x: auto; }

/* Jodit on small screens */
.jodit-container:not(.jodit_inline) { border-radius: 6px !important; max-width: 100%; }
.jodit-toolbar__box { position: sticky; top: 56px; z-index: 5; }
.jodit-wysiwyg { font-size: 17px; line-height: 1.65; }
.jodit-wysiwyg img { max-width: 100%; height: auto; }

/* Media */
.media-grid { list-style: none; padding: 0; margin: 12px 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .media-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .media-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.media-grid a { display: flex; flex-direction: column; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; text-decoration: none; color: var(--ink); height: 100%; }
.media-grid img { aspect-ratio: 4 / 3; object-fit: cover; width: 100%; border-radius: 4px; background: #eef0f3; }
.media-name { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-form { display: grid; gap: 12px; }
.upload-form .field + .field { margin-top: 0; }
@media (min-width: 900px) { .upload-form { grid-template-columns: 1.2fr 1fr 1fr 1fr auto; align-items: end; } }
.media-edit { display: grid; gap: 16px; }
@media (min-width: 900px) { .media-edit { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: start; } }
.media-edit-preview { margin: 0 0 16px; }
.media-edit-preview img { display: block; margin: 0 auto 10px; max-height: 60vh; width: auto; }
.media-preview { border: 1px dashed #c7ccd4; border-radius: 6px; min-height: 90px; display: flex; align-items: center; justify-content: center; padding: 6px; background: #fafbfc; }
.media-preview img { max-height: 180px; width: auto; border-radius: 4px; }
.js .media-id-manual { display: none; }
.tag-admin-list { list-style: none; margin: 0; padding: 0; }
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 10px 12px; margin-bottom: 8px; }
.tag-row .inline-form { flex: 1 1 280px; }

/* Media picker modal */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal-box { background: #fff; width: 100%; max-width: 960px; max-height: 92vh; display: flex; flex-direction: column; border-radius: 12px 12px 0 0; padding: 14px var(--gutter); }
@media (min-width: 768px) { .modal { align-items: center; padding: 24px; } .modal-box { border-radius: 12px; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.modal-head h2 { margin: 0; }
.modal-tools { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.modal-tools input[type=search] { flex: 1 1 200px; width: auto; }
.mp-grid { overflow-y: auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 2px; }
@media (min-width: 640px) { .mp-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 900px) { .mp-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.mp-grid button { border: 2px solid transparent; padding: 0; background: #eef0f3; border-radius: 6px; cursor: pointer; aspect-ratio: 1; overflow: hidden; }
.mp-grid button:hover, .mp-grid button:focus-visible { border-color: var(--primary); }
.mp-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mp-more { text-align: center; padding-top: 10px; }

/* Sign-in */
.auth-body { display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: 100%; max-width: 400px; }
.auth-brand { font-weight: 800; font-size: 1.2rem; margin-bottom: 16px; }
.auth-alt { margin-top: 16px; font-size: .9rem; }
.translation-row { flex-direction: row !important; justify-content: space-between; align-items: center; gap: 8px; }
.badge-error { background: #fee4e2; color: #912018; }
.badge-warning { background: #fef3c7; color: #78350f; }
.badge-info { background: #e0f2fe; color: #075985; }
.issue-list { list-style: none; margin: 0 0 12px; padding: 0; }
.issue { padding: 8px 0; border-bottom: 1px solid var(--line); }
.cols-2 { display: grid; gap: 16px; }
@media (min-width: 900px) { .cols-2 { grid-template-columns: 1fr 1fr; } }
.chart-bars { display: flex; align-items: flex-end; gap: 2px; height: 140px; padding-top: 8px; }
.chart-bar { flex: 1; min-width: 2px; height: var(--h); background: var(--primary); border-radius: 2px 2px 0 0; min-height: 2px; }
.stat-alert { border-color: #f4b8b2; background: #fef3f2; }
/* Tool placeholders inside the editor */
.jodit-wysiwyg [data-tool] { display: block; margin: 12px 0; padding: 18px; border: 2px dashed #94a3b8; border-radius: 8px; background: #f8fafc; text-align: center; font: 600 14px/1.4 var(--sans); color: #475569; user-select: none; }
.jodit-wysiwyg [data-tool]::before { content: "Tool: " attr(data-tool) " (shown to readers here)"; }
.revision-body [data-tool]::before, .prose-admin [data-tool]::before { content: "[Tool: " attr(data-tool) "]"; }
