:root {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #22242a;
    background: #f4f5f8;
    --ink: #22242a;
    --muted: #6d727c;
    --line: #dfe2e8;
    --line-strong: #cfd3db;
    --surface: #fff;
    --surface-soft: #f8f9fb;
    --purple: #5c3f93;
    --purple-dark: #49316f;
    --purple-soft: #f3eefb;
    --danger: #a83232;
    --danger-soft: #fdecec;
    --success: #2f7a48;
    --success-soft: #eaf6ee;
    --warning: #9a6108;
    --warning-soft: #fff4dd;
    --sidebar: #20222a;
    --sidebar-2: #282b34;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20,22,28,.04), 0 6px 24px rgba(20,22,28,.04);
}
* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; background: #f4f5f8; color: var(--ink); }
a { color: var(--purple); }
button, input, textarea, select { font: inherit; }
button, .button { cursor: pointer; }

/* App shell */
.admin-app { min-height: 100vh; }
.admin-topbar { position: sticky; top: 0; z-index: 40; background: #17191f; border-bottom: 1px solid #30333c; }
.admin-topbar-inner { width: min(1440px, calc(100% - 32px)); margin: 0 auto; min-height: 60px; display: flex; align-items: center; gap: 20px; }
.admin-brand { display: inline-flex; align-items: baseline; gap: 8px; color: #fff; text-decoration: none; margin-right: auto; }
.admin-brand-name { font-size: 1.08rem; font-weight: 850; letter-spacing: .01em; }
.admin-brand-product { color: #bfc4cf; font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.admin-account { display: flex; align-items: center; gap: 14px; min-width: 0; }
.admin-user { color: #c9ced8; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-account-link, .logout-link { color: #f2f3f6; text-decoration: none; background: transparent; border: 0; padding: 5px 0; }
.admin-account-link:hover, .logout-link:hover { color: #fff; text-decoration: underline; }
.logout-form { margin: 0; padding: 0; background: transparent; display: inline; }

.admin-workspace { width: min(1440px, 100%); margin: 0 auto; display: grid; grid-template-columns: 238px minmax(0, 1fr); min-height: calc(100vh - 61px); }
.admin-sidebar { position: sticky; top: 61px; height: calc(100vh - 61px); overflow-y: auto; padding: 22px 14px 32px; background: var(--sidebar); border-right: 1px solid #30333c; }
.admin-nav-group { margin-top: 23px; }
.admin-nav-group-title { padding: 0 11px 7px; color: #858b98; font-size: .72rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.admin-nav-link { display: block; margin: 2px 0; padding: 9px 11px; color: #dfe2e8; border-radius: 7px; text-decoration: none; line-height: 1.3; }
.admin-nav-link:hover { background: #2e323c; color: #fff; }
.admin-nav-link.active { background: var(--purple); color: #fff; font-weight: 700; box-shadow: inset 3px 0 0 #bda8e5; }
.admin-content { min-width: 0; width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 34px 0 60px; }

/* Page structure */
h1, h2, h3 { color: #23252b; }
h1 { margin: 0; font-size: clamp(1.65rem, 2.4vw, 2.15rem); line-height: 1.15; }
h2 { font-size: 1.15rem; }
p { line-height: 1.55; }
.eyebrow { margin: 0 0 5px; color: var(--purple); font-size: .78rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 22px; margin-bottom: 22px; }
.page-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.page-subtitle { max-width: 780px; margin: 7px 0 0; color: var(--muted); line-height: 1.5; }
.page-meta { margin-top: 8px; color: var(--muted); font-size: .9rem; }

/* Buttons */
.button, button:not(.logout-link) { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 13px; border: 1px solid transparent; border-radius: 7px; background: var(--purple); color: #fff; text-decoration: none; font-weight: 700; line-height: 1.2; }
.button:hover, button:not(.logout-link):hover { background: var(--purple-dark); }
.button.secondary { background: #fff; color: #34373d; border-color: var(--line-strong); }
.button.secondary:hover { background: #f5f6f8; }
.button.ghost { background: transparent; color: var(--purple); border-color: transparent; }
.button.ghost:hover { background: var(--purple-soft); }
.button.danger, button.danger { background: #fff; color: var(--danger); border-color: #e8bcbc; }
.button.danger:hover, button.danger:hover { background: var(--danger-soft); }
.button.small, .actions .button, .actions button { min-height: 33px; padding: 6px 10px; font-size: .88rem; }
.actions, .form-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions { justify-content: flex-end; }
.actions form, .compact-form { margin: 0; padding: 0; background: transparent; display: inline-flex; }

/* Cards, alerts, empty states */
.form-card, .form-section, .security-card, .content-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form-card { padding: 22px; }
.form-section { padding: 22px; display: grid; gap: 17px; margin: 0; }
.form-section + .form-section { margin-top: 18px; }
.section-heading { padding-bottom: 12px; border-bottom: 1px solid #eceef2; }
.section-heading h2 { margin: 0 0 4px; }
.section-heading p { margin: 0; color: var(--muted); }
.settings-help { padding: 13px 15px; border-left: 4px solid var(--purple); border-radius: 0 7px 7px 0; background: var(--purple-soft); color: #493b5e; }
.alert { margin: 0 0 18px; padding: 12px 14px; border: 1px solid #ded7ea; border-radius: 8px; background: var(--purple-soft); color: #493b5e; }
.alert.success, .status-message { border-color: #bddfc8; background: var(--success-soft); color: #245d38; }
.alert.error, .validation { border-color: #edc0c0; background: var(--danger-soft); color: #8c2525; }
.validation { padding: 11px 13px; border-radius: 7px; }
.validation:empty { display: none; }
.validation-error { color: var(--danger); font-weight: 500; }
.empty-state { padding: 34px; text-align: center; border: 1px dashed #c9cdd5; border-radius: 10px; background: #fff; }
.empty-state h2 { margin-top: 0; }
.empty-state p { color: var(--muted); max-width: 650px; margin: 0 auto; }
.muted, .note, small { color: var(--muted); }

/* Forms */
form { display: grid; gap: 17px; }
.publication-form { background: transparent; padding: 0; gap: 18px; }
label, .field { display: grid; gap: 6px; color: #30333a; font-weight: 700; }
.field-label { font-weight: 700; }
.field-hint { display: block; margin-top: 1px; color: var(--muted); font-size: .86rem; line-height: 1.42; font-weight: 400; }
input:not([type=checkbox]):not([type=radio]), textarea, select { width: 100%; min-height: 40px; padding: 9px 10px; border: 1px solid #bfc4cd; border-radius: 6px; background: #fff; color: #24262b; outline: none; }
textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(92,63,147,.12); }
input[readonly] { background: #f1f2f4; color: #656a73; cursor: not-allowed; }
input::placeholder, textarea::placeholder { color: #9a9ea7; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.check { display: flex !important; flex-direction: row; align-items: flex-start; gap: 9px; font-weight: 600 !important; }
.check input { margin-top: 3px; }
fieldset { margin: 0; padding: 14px 16px 16px; border: 1px solid var(--line); border-radius: 8px; }
legend { padding: 0 6px; font-weight: 800; }
.form-actions { margin-top: 3px; }
.form-actions--sticky, .sticky-save-bar { position: sticky; bottom: 10px; z-index: 10; display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: 9px; background: rgba(255,255,255,.96); box-shadow: 0 7px 28px rgba(20,22,28,.12); backdrop-filter: blur(8px); }
.form-actions--sticky .save-note, .sticky-save-bar .muted { margin-right: auto; }
.advanced-block { border: 1px solid var(--line); border-radius: 8px; background: #fbfbfc; }
.advanced-block summary { cursor: pointer; padding: 12px 14px; font-weight: 800; color: #494d55; }
.advanced-content { display: grid; gap: 15px; padding: 0 14px 15px; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.admin-table, table { width: 100%; border-collapse: collapse; background: #fff; }
.admin-table th, .admin-table td, th, td { padding: 12px 14px; border-bottom: 1px solid #eceef1; text-align: left; vertical-align: top; }
.admin-table th, th { background: #fafbfc; color: #626872; font-size: .76rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover td { background: #fcfbff; }
.admin-table td:last-child { white-space: nowrap; }
.admin-table code { white-space: normal; word-break: break-all; }
.row-title { font-weight: 800; color: #26282d; }
.row-subtitle { margin-top: 3px; color: var(--muted); font-size: .88rem; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; background: var(--purple); color: #fff; font-size: .78rem; font-weight: 700; line-height: 1; margin: 2px; }
.badge.secondary { background: #747985; }
.badge.warning { background: var(--warning); }
.badge.success { background: var(--success); }
.badge.soft { background: #eceef2; color: #50545c; }

/* Dashboard */
.dashboard-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.dashboard-card { min-height: 145px; display: flex; flex-direction: column; gap: 8px; padding: 20px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); text-decoration: none; box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease; }
.dashboard-card strong { color: var(--purple); font-size: 1.05rem; }
.dashboard-card span { color: var(--muted); line-height: 1.5; }
.dashboard-card:hover { transform: translateY(-2px); border-color: #bba9d8; box-shadow: 0 8px 25px rgba(45,34,65,.09); }

/* Publishing */
.publish-mode-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.publish-mode-card { display: flex !important; flex-direction: row; gap: 10px; align-items: flex-start; padding: 14px; border: 1px solid #d7dae0; border-radius: 8px; background: #fafbfc; cursor: pointer; font-weight: 400 !important; }
.publish-mode-card:hover { border-color: #a996c8; background: #faf8ff; }
.publish-mode-card:has(input:checked) { border-color: var(--purple); box-shadow: 0 0 0 2px rgba(92,63,147,.11); background: #f7f3ff; }
.publish-mode-card input { margin-top: 3px; }
.publish-mode-card span { display: grid; gap: 3px; }
.publish-mode-card strong { color: #292333; }
.publish-mode-card small { line-height: 1.35; }
.schedule-summary { min-height: 20px; padding: 12px 14px; border-radius: 7px; background: var(--purple-soft); color: #49356f; }
.social-editor-grid > div { display: grid; gap: 12px; align-content: start; }
.social-status { max-width: 520px; word-break: break-word; }

/* Rich editor */
.editor-block { display: grid; gap: 6px; }
.rich-toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding: 8px; background: #eef0f3; border: 1px solid #cdd1d7; border-bottom: 0; border-radius: 7px 7px 0 0; }
.rich-toolbar button { min-height: 32px; padding: 5px 9px; background: #fff; color: #222; border: 1px solid #b9bec7; font-weight: 600; }
.rich-toolbar button:hover { background: #f7f4fc; color: #3f285f; }
.rich-toolbar .toolbar-separator { width: 1px; background: #c8ccd1; align-self: stretch; margin: 0 2px; }
.rich-toolbar .toolbar-document-select { width: auto; min-width: 190px; max-width: 320px; min-height: 32px; padding: 5px 8px; }
.rich-toolbar .insert-toolbar-document { background: #f8f4fc; border-color: #b99bc8; color: #4d3266; }
.rich-editor { min-height: 170px; padding: 13px; background: #fff; border: 1px solid #bfc4cd; border-radius: 0 0 7px 7px; outline: none; line-height: 1.55; }
.rich-editor:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(92,63,147,.12); }
.rich-source { display: none; }

/* Media and attachments */
.admin-preview { display: block; max-width: 360px; max-height: 240px; object-fit: contain; margin: 8px 0 16px; border: 1px solid var(--line); border-radius: 6px; padding: 5px; background: #fff; }
.document-picker-panel, .document-inline-insert { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc; }
.document-picker-panel h3, .document-inline-insert h3 { margin: 0 0 5px; font-size: 1rem; }
.document-inline-hint { background: #f8f4fc; border-color: #d9c9e2; }
.attachment-checklist { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.attachment-option { display: flex !important; flex-direction: row; align-items: flex-start; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; font-weight: 400 !important; }
.attachment-option input { margin-top: 3px; }
.attachment-option span { display: grid; gap: 2px; }
.attachment-option small { word-break: break-all; }
.document-insert-row { display: grid; grid-template-columns: minmax(220px,1fr) auto auto; gap: 8px; align-items: center; margin-top: 10px; }
.media-library-section { margin-top: 24px; }
.media-library-toolbar { display: grid; grid-template-columns: auto minmax(260px,1fr) minmax(170px,220px); gap: 14px; align-items: end; margin-bottom: 10px; padding: 14px; background: #f7f8fa; border: 1px solid var(--line); border-radius: 9px; }
.media-filter-buttons { display: flex; gap: 7px; flex-wrap: wrap; }
.media-filter-buttons .media-filter.active { background: var(--purple); color: #fff; border-color: var(--purple); }
.filter-count { margin-left: 4px; opacity: .75; }
.media-search-field, .media-sort-field { display: grid !important; gap: 5px !important; }
.media-search-field span, .media-sort-field span { font-size: 12px; color: var(--muted); font-weight: 700; }
.asset-library-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(260px,1fr)); gap: 16px; margin-top: 14px; }
.asset-card { background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 12px; display: grid; gap: 10px; align-content: start; box-shadow: var(--shadow); }
.asset-card[hidden] { display: none !important; }
.asset-preview-link { display: block; background: #f4f5f7; border-radius: 6px; overflow: hidden; }
.asset-preview-link img { display: block; width: 100%; height: 160px; object-fit: cover; }
.document-preview { min-height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; background: #f8f4fc; border: 1px solid #e3d8ea; border-radius: 6px; text-decoration: none; }
.document-icon { font-size: 34px; }
.asset-meta { display: grid; gap: 3px; min-width: 0; }
.asset-meta strong, .asset-meta small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-edit-form { display: grid; gap: 7px; padding: 0; background: transparent; }
.asset-public-url { display: grid; gap: 4px; }
.asset-public-url code { font-size: 11px; word-break: break-all; max-height: 48px; overflow: auto; }
.media-empty { padding: 25px; text-align: center; background: #fff; border: 1px dashed #c9cdd3; border-radius: 8px; color: var(--muted); margin-top: 14px; }

/* SEO preview */
.seo-preview { margin-top: 4px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.seo-preview-title { color: #1a0dab; font-size: 18px; margin-top: 8px; }
.seo-preview-url { color: #188038; font-size: 13px; margin: 3px 0 5px; }
.seo-checklist { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 4px; padding: 12px; border: 1px solid #e3e6e8; border-radius: 8px; background: #fafafa; font-size: 13px; }
.seo-checklist span { white-space: nowrap; }

/* Permissions */
.permission-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.permission { display: flex !important; flex-direction: row; gap: 10px; align-items: flex-start; padding: 11px; border: 1px solid var(--line); border-radius: 7px; background: #fafbfc; font-weight: 400 !important; }
.permission input { margin-top: 3px; }
.permission span { display: flex; flex-direction: column; }
.permission small { margin-top: 2px; line-height: 1.4; }

/* Security */
.security-card { max-width: 820px; padding: 28px; }
.security-card h1 { margin-top: 0; }
.two-factor-grid { display: grid; grid-template-columns: 260px 1fr; gap: 28px; align-items: center; margin: 24px 0; }
.qr-panel { display: flex; justify-content: center; align-items: center; min-height: 240px; }
.qr-code { padding: 10px; background: white; border: 1px solid var(--line); border-radius: 8px; }
.qr-code svg { display: block; width: 220px; height: 220px; max-width: 100%; }
.shared-key { display: inline-block; padding: 10px 12px; background: #f1f3f5; border-radius: 6px; font-size: 1.05rem; letter-spacing: .06em; word-break: break-all; }
.two-factor-form { margin-top: 24px; padding: 18px; border: 1px solid var(--line); border-radius: 8px; box-shadow: none; }
.two-factor-ok { margin: 18px 0; padding: 16px; background: #f4f8ff; border: 1px solid #cddcf7; border-radius: 6px; }
.recovery-panel { margin: 18px 0; padding: 18px; background: #fff8e5; border: 1px solid #ebd38a; border-radius: 6px; }
.recovery-panel h2 { margin-top: 0; }
.recovery-codes { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px 20px; }
.recovery-codes code { padding: 7px 10px; background: white; border: 1px solid #eadcae; border-radius: 4px; }

/* Login */
.auth-page { min-height: 100vh; background: #f4f5f8; display: flex; align-items: center; justify-content: center; margin: 0; }
.auth-shell { width: min(440px,calc(100% - 32px)); margin: auto; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 30px; box-shadow: 0 10px 35px rgba(0,0,0,.09); }
.auth-card h1 { margin-top: 0; }
.auth-card .button, .auth-card button { width: 100%; margin-top: 12px; }

@media (max-width: 1050px) {
    .admin-workspace { grid-template-columns: 205px minmax(0,1fr); }
    .dashboard-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .media-library-toolbar { grid-template-columns: 1fr 1fr; }
    .media-filter-buttons { grid-column: 1/-1; }
}

@media (max-width: 760px) {
    .admin-topbar-inner { width: min(100% - 22px, 1440px); min-height: 56px; }
    .admin-user { display: none; }
    .admin-account { gap: 9px; font-size: .9rem; }
    .admin-workspace { display: block; }
    .admin-sidebar { position: static; height: auto; display: flex; gap: 6px; overflow-x: auto; padding: 10px 11px; white-space: nowrap; border-right: 0; border-bottom: 1px solid #30333c; }
    .admin-nav-group { display: contents; }
    .admin-nav-group-title { display: none; }
    .admin-nav-link { flex: 0 0 auto; margin: 0; padding: 8px 10px; }
    .admin-content { width: min(100% - 24px, 1180px); padding: 24px 0 45px; }
    .page-header { align-items: stretch; flex-direction: column; gap: 14px; }
    .page-header-actions { justify-content: flex-start; }
    .grid, .grid-3, .publish-mode-grid, .permission-list, .dashboard-grid, .attachment-checklist { grid-template-columns: 1fr; }
    .table-wrap { border-radius: 8px; }
    .form-section, .form-card { padding: 17px; }
    .form-actions--sticky, .sticky-save-bar { position: static; align-items: stretch; flex-direction: column; }
    .form-actions--sticky .save-note, .sticky-save-bar .muted { margin-right: 0; }
    .form-actions--sticky .button, .form-actions--sticky button, .sticky-save-bar button { width: 100%; }
    .document-insert-row, .media-library-toolbar { grid-template-columns: 1fr; }
    .media-filter-buttons { grid-column: auto; }
    .rich-toolbar .toolbar-document-select { width: 100%; max-width: none; }
    .rich-toolbar .toolbar-separator { display: none; }
    .two-factor-grid { grid-template-columns: 1fr; }
    .recovery-codes { grid-template-columns: 1fr; }
}
.password-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; }
@media (max-width: 760px) { .password-row { grid-template-columns: 1fr; } }
