:root {
    --admin-wine: #64140a;
    --admin-wine-dark: #481007;
    --admin-ink: #252525;
    --admin-muted: #6b6b6b;
    --admin-line: #dedede;
    --admin-bg: #f4f3f1;
    --admin-paper: #ffffff;
    --admin-success: #2f6a42;
    --admin-warning: #986815;
    --admin-error: #992f2f;
    --admin-sidebar: 270px;
    --admin-radius: 8px;
    --admin-shadow: 0 12px 34px rgba(31, 28, 25, .08);
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--admin-ink); background: var(--admin-bg); line-height: 1.5; }
a { color: var(--admin-wine); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
code { padding: .12rem .35rem; border-radius: 4px; background: #eeeae6; color: #5e5852; font-size: .78rem; }

.auth-body, .install-body { min-height: 100vh; padding: 3rem 1rem; background: radial-gradient(circle at 15% 10%, #8f2c20 0, var(--admin-wine) 24%, #32100c 100%); }
.auth-body { display: grid; place-items: center; }
.auth-card { width: min(480px, 100%); padding: 3rem; border-radius: 14px; background: #fff; box-shadow: 0 25px 70px rgba(0,0,0,.28); }
.auth-card h1, .install-header h1 { margin: 0 0 1rem; font-family: Georgia, serif; font-size: clamp(2rem, 5vw, 3rem); font-weight: 400; color: var(--admin-wine); }
.auth-kicker, .admin-kicker { margin: 0 0 .4rem; color: var(--admin-wine); font-size: .72rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.auth-intro { color: var(--admin-muted); margin-bottom: 2rem; }
.auth-form { display: grid; gap: 1.15rem; }
.auth-form label, .account-form label { display: grid; gap: .4rem; font-size: .85rem; font-weight: 700; }
.auth-form input, .account-form input { width: 100%; min-height: 48px; border: 1px solid #cfcac5; border-radius: 6px; padding: .7rem .85rem; }
.auth-form input:focus, .account-form input:focus { border-color: var(--admin-wine); outline: 3px solid rgba(100,20,10,.13); }
.auth-back { display: inline-block; margin-top: 1.5rem; color: var(--admin-muted); font-size: .85rem; text-decoration: none; }

.install-shell { width: min(980px, 100%); margin: 0 auto; }
.install-header { padding: 2.5rem 3rem; border-radius: 14px 14px 0 0; background: #fff; }
.install-header p:last-child { margin-bottom: 0; color: var(--admin-muted); }
.install-shell > .panel, .install-shell > .alert, .install-shell > form { border-radius: 0; margin: 0; border-top: 1px solid var(--admin-line); box-shadow: none; }
.install-shell > :last-child { border-radius: 0 0 14px 14px; }
.requirements-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
.requirement { display: flex; gap: .65rem; align-items: center; padding: .75rem; border: 1px solid var(--admin-line); border-radius: 6px; font-size: .85rem; }
.requirement > span:first-child { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; color: #fff; font-weight: 800; }
.requirement.is-ok > span:first-child { background: var(--admin-success); }
.requirement.is-error > span:first-child { background: var(--admin-error); }
.install-form fieldset { margin: 0 0 2rem; padding: 0; border: 0; }
.install-form legend { margin-bottom: 1.15rem; color: var(--admin-wine); font-family: Georgia, serif; font-size: 1.45rem; }
.install-success { min-height: 320px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 40px; border: 1px solid transparent; border-radius: 6px; padding: .55rem .9rem; font-weight: 750; text-decoration: none; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--admin-wine); color: #fff; border-color: var(--admin-wine); }
.button-primary:hover { background: var(--admin-wine-dark); }
.button-secondary { background: #fff; color: var(--admin-wine); border-color: #c9b7b3; }
.button-secondary:hover { border-color: var(--admin-wine); }
.button-muted { background: #ebe9e7; color: #4b4845; border-color: #d4d0cc; }
.button-danger { background: #8e2020; color: #fff; border-color: #8e2020; }
.button-danger:hover { background: #6f1717; border-color: #6f1717; }
.button-large { min-height: 48px; padding-inline: 1.25rem; }
.button[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.button-row, .form-actions, .message-actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }

.alert { margin: 0 0 1.25rem; padding: 1rem 1.15rem; border: 1px solid; border-radius: 7px; }
.alert ul { margin-bottom: 0; }
.alert-error { color: #751e1e; border-color: #e7b2b2; background: #fff2f2; }
.alert-success { color: #235132; border-color: #b8d8c2; background: #eff9f2; }
.alert-warning { color: #68470d; border-color: #e2c890; background: #fff8e8; }
.alert-info { color: #344f68; border-color: #bdd1e0; background: #f0f7fc; }

.admin-body { min-height: 100vh; }
.admin-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; width: var(--admin-sidebar); display: flex; flex-direction: column; background: #24211f; color: #fff; overflow-y: auto; }
.admin-brand { display: grid; gap: .2rem; padding: 2rem 1.6rem 1.5rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.admin-brand > span { color: #d9a69b; font-size: .7rem; font-weight: 800; letter-spacing: .16em; }
.admin-brand strong { font-family: Georgia, serif; font-size: 1.25rem; }
.admin-brand small { color: #aaa39e; }
.admin-nav { display: grid; padding: 1rem .75rem; }
.admin-nav a { display: flex; align-items: center; justify-content: space-between; gap: .6rem; min-height: 44px; padding: .65rem .85rem; border-radius: 6px; color: #d9d5d2; text-decoration: none; font-size: .9rem; }
.admin-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.admin-nav a.active { background: var(--admin-wine); color: #fff; }
.nav-badge { display: inline-flex; min-width: 22px; height: 22px; align-items: center; justify-content: center; border-radius: 11px; background: #fff; color: var(--admin-wine); font-size: .72rem; font-weight: 800; }
.nav-badge-warn { background: #f0bd57; color: #4a3100; }
.admin-sidebar-footer { margin-top: auto; padding: 1.3rem 1.6rem; border-top: 1px solid rgba(255,255,255,.1); color: #c0bab5; font-size: .8rem; }
.admin-sidebar-footer p { margin-top: 0; }
.sidebar-logout { border: 0; padding: 0; background: transparent; color: #fff; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.admin-mobile-header { display: none; }
.admin-main { width: calc(100% - var(--admin-sidebar)); min-height: 100vh; margin-left: var(--admin-sidebar); padding: 2.5rem clamp(1.25rem, 3vw, 3.5rem) 5rem; }
.admin-topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 2rem; }
.admin-topbar h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(2rem, 4vw, 3rem); font-weight: 400; color: var(--admin-ink); }

.panel { margin-bottom: 1.5rem; padding: 1.6rem; border: 1px solid #e3e0dd; border-radius: var(--admin-radius); background: var(--admin-paper); box-shadow: var(--admin-shadow); }
.panel h2 { color: var(--admin-ink); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.panel-heading h2 { margin: 0; font-family: Georgia, serif; font-size: 1.75rem; font-weight: 400; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { display: grid; min-height: 150px; padding: 1.35rem; border: 1px solid #e3e0dd; border-radius: var(--admin-radius); background: #fff; color: var(--admin-ink); text-decoration: none; box-shadow: var(--admin-shadow); }
.stat-card > span { color: var(--admin-muted); font-size: .78rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.stat-card strong { align-self: center; color: var(--admin-wine); font-family: Georgia, serif; font-size: 2.65rem; font-weight: 400; }
.stat-card small { align-self: end; color: var(--admin-muted); }
.stat-card:hover { border-color: #b9a19c; }

.editor-layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.editor-stack { min-width: 0; }
.record-list { position: sticky; top: 1.25rem; max-height: calc(100vh - 2.5rem); overflow-y: auto; border: 1px solid #ddd9d5; border-radius: var(--admin-radius); background: #fff; box-shadow: var(--admin-shadow); }
.record-list > a { display: grid; min-width: 0; gap: .15rem; padding: .85rem 1rem; border-bottom: 1px solid #ece9e6; color: var(--admin-ink); text-decoration: none; }
.record-list > a:last-child { border-bottom: 0; }
.record-list > a:hover { background: #f8f5f3; }
.record-list > a.active { background: #f5e9e6; border-left: 4px solid var(--admin-wine); padding-left: calc(1rem - 4px); }
.record-list strong { min-width: 0; overflow-wrap: anywhere; font-size: .9rem; }
.record-list small { min-width: 0; overflow-wrap: anywhere; color: var(--admin-muted); font-size: .73rem; }
.record-list .record-new { color: var(--admin-wine); font-weight: 800; }
.editor-form { min-width: 0; }

.form-grid { display: grid; gap: 1rem; }
.form-grid-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid label, .editor-label, .setting-field { display: grid; align-content: start; gap: .38rem; color: #4e4b48; font-size: .82rem; font-weight: 750; }
.form-grid input, .form-grid select, .form-grid textarea, .setting-field input, .setting-field textarea, .setting-field select { width: 100%; min-height: 42px; border: 1px solid #cbc6c1; border-radius: 5px; background: #fff; color: var(--admin-ink); padding: .62rem .72rem; }
.form-grid textarea, .setting-field textarea { resize: vertical; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus, .setting-field input:focus, .setting-field textarea:focus { outline: 3px solid rgba(100,20,10,.12); border-color: var(--admin-wine); }
.form-grid small, .setting-field small, .field-help { color: var(--admin-muted); font-size: .73rem; font-weight: 400; }
.span-two { grid-column: 1 / -1; }
.editor-label { margin-top: 1.25rem; }
.wysiwyg-shell { font-weight: 400; }
.wysiwyg-input { width: 100%; min-height: 180px; border: 1px solid #cbc6c1; padding: .75rem; }
.ql-toolbar.ql-snow { border-color: #cbc6c1 !important; border-radius: 5px 5px 0 0; background: #faf9f8; }
.ql-container.ql-snow { min-height: 200px; border-color: #cbc6c1 !important; border-radius: 0 0 5px 5px; background: #fff; font-size: 15px; }
.ql-editor { min-height: 200px; line-height: 1.6; }
.check-row { display: flex; flex-wrap: wrap; gap: 1.2rem; margin: 1.25rem 0; }
.check-row label, .switch-field { display: inline-flex; align-items: center; gap: .5rem; font-size: .85rem; font-weight: 700; }
.check-row input, .switch-field input { width: 18px; height: 18px; accent-color: var(--admin-wine); }
.form-actions { margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--admin-line); }

.table-scroll { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.admin-table th, .admin-table td { padding: .8rem .7rem; border-bottom: 1px solid #e9e6e3; text-align: left; vertical-align: top; }
.admin-table th { color: var(--admin-muted); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; }
.admin-table a { font-weight: 750; }
.settings-form { padding-bottom: 5rem; }
.settings-group { margin-bottom: 1.25rem; }
.settings-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.setting-field > span:first-child { color: #4e4b48; }
.setting-field code { justify-self: start; font-weight: 400; }
.sticky-save { position: sticky; bottom: 1rem; z-index: 20; display: flex; justify-content: flex-end; padding: .8rem; border: 1px solid #d8d3cf; border-radius: 8px; background: rgba(255,255,255,.94); box-shadow: 0 10px 32px rgba(0,0,0,.15); backdrop-filter: blur(8px); }

.status-badge { display: inline-flex; align-items: center; min-height: 28px; padding: .25rem .65rem; border-radius: 99px; background: #e9e7e4; color: #5b5754; font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.status-good, .status-read { background: #e3f2e8; color: #28583a; }
.status-warning, .status-new { background: #fff0cc; color: #73500b; }
.status-archived { background: #ececec; color: #555; }
.migration-list { display: grid; gap: .6rem; padding: 0; margin: 1.5rem 0; list-style: none; }
.migration-list li { display: flex; gap: 1rem; padding: .9rem; border: 1px solid #e3dfdb; border-radius: 6px; }
.migration-list strong { color: var(--admin-wine); }
.message-item.status-new { border-left: 4px solid #d69520; }
.message-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin: 0 0 1.5rem; }
.message-meta div { padding: .85rem; background: #f7f5f3; }
.message-meta dt { color: var(--admin-muted); font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.message-meta dd { min-width: 0; margin: .2rem 0 0; overflow-wrap: anywhere; }
.message-body { min-width: 0; min-height: 180px; padding: 1.4rem; border: 1px solid #e1ddda; background: #fff; overflow-wrap: anywhere; white-space: normal; }
.message-actions { margin-top: 1.25rem; }
.message-actions form { display: flex; flex-wrap: wrap; gap: .75rem; }
.empty-state { padding: 1rem; color: var(--admin-muted); }
.account-panel { max-width: 700px; }
.account-form { display: grid; gap: 1rem; max-width: 500px; }

@media (max-width: 1250px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .editor-layout { grid-template-columns: 230px minmax(0, 1fr); }
}

@media (max-width: 980px) {
    .admin-mobile-header { position: sticky; top: 0; z-index: 60; display: flex; align-items: center; justify-content: space-between; min-height: 58px; padding: .6rem 1rem; background: #24211f; color: #fff; }
    .admin-mobile-header a { color: #fff; font-size: .78rem; }
    .admin-menu-button { border: 0; background: transparent; color: #fff; font-size: 1.4rem; }
    .admin-sidebar { top: 58px; visibility: hidden; transform: translateX(-105%); transition: transform .22s ease, visibility .22s; box-shadow: 14px 0 34px rgba(0,0,0,.28); }
    .admin-sidebar.is-open { visibility: visible; transform: translateX(0); }
    .admin-main { width: 100%; margin-left: 0; padding: 1.5rem 1rem 4rem; }
    .admin-topbar { align-items: flex-end; }
    .editor-layout { grid-template-columns: 1fr; }
    .record-list { position: static; max-height: 330px; }
}

@media (max-width: 700px) {
    .auth-card { padding: 2rem 1.35rem; }
    .install-body { padding: 1rem .5rem; }
    .install-header, .panel, .install-form { padding: 1.25rem; }
    .requirements-grid, .form-grid-two, .settings-fields, .message-meta { grid-template-columns: 1fr; }
    .span-two { grid-column: auto; }
    .stats-grid { grid-template-columns: 1fr; }
    .admin-topbar { align-items: flex-start; flex-direction: column; }
    .panel-heading { align-items: flex-start; flex-direction: column; }
    .sticky-save { justify-content: stretch; }
    .sticky-save .button { width: 100%; }
    .message-actions form, .message-actions .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: .01ms !important; }
}
