:root {
    --ink: #111;
    --muted: #555;
    --line: #d0d0d0;
    --surface: #ffffff;
    --canvas: #f6f6f6;
    --brand: #111;
    --brand-dark: #000;
    --accent: #1db9e8;
    --danger: #9b1c1c;
    --shadow: 0 0 12px rgba(0, 0, 0, 0.1);
    --radius: 18px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--canvas); }

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background: var(--canvas);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a { color: inherit; }

button, input, select { font: inherit; }

.page-shell { min-height: 100vh; }

.home-layout,
.login-layout,
.public-layout {
    background: #f6f6f6;
}

.home-layout .page-shell,
.public-layout .page-shell {
    display: grid;
    place-items: center;
    padding: 32px;
}

.home-card,
.message-card {
    width: min(620px, 100%);
    padding: clamp(32px, 7vw, 72px);
    border: 1px solid #dedede;
    border-radius: 28px;
    background: #fff;
    box-shadow: var(--shadow);
}

.home-logo { width: 92px; height: 92px; object-fit: contain; margin-bottom: 28px; }

.eyebrow {
    margin: 0 0 8px;
    color: var(--brand);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

h1 { margin-bottom: 14px; font-size: clamp(2.2rem, 5vw, 4.3rem); line-height: 0.98; letter-spacing: -0.05em; }
h2 { margin-bottom: 8px; font-size: 1.1rem; }

.home-copy { max-width: 48ch; margin-bottom: 30px; color: var(--muted); font-size: 1.08rem; }

.button {
    display: inline-flex;
    min-height: 46px;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    border: 1px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 750;
    text-decoration: none;
    transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.button:hover { transform: translateY(-1px); }
.button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #004466; outline-offset: 2px; }
.button-primary { background: var(--brand); color: #fff; }
.button-primary:hover { background: var(--brand-dark); }
.button-secondary { border-color: var(--line); background: #eee; color: var(--ink); }

.login-layout .page-shell { display: grid; place-items: center; padding: 28px; }

.auth-shell {
    display: grid;
    width: min(980px, 100%);
    grid-template-columns: minmax(0, 0.9fr) minmax(380px, 1.1fr);
    overflow: hidden;
    border: 1px solid #dedede;
    border-radius: 28px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-brand {
    display: flex;
    min-height: 640px;
    flex-direction: column;
    justify-content: flex-end;
    padding: clamp(36px, 6vw, 70px);
    background: #eaeaea;
    color: #111;
}

.auth-brand img { display: block; width: 100%; height: auto; margin: 0 0 auto; object-fit: contain; }
.auth-brand .eyebrow { color: #555; }
.auth-brand h1 { font-size: clamp(2.4rem, 5vw, 4.2rem); }
.auth-brand p:last-child { max-width: 35ch; margin-bottom: 0; color: #555; }

.auth-panel { align-self: center; padding: clamp(34px, 7vw, 72px); }
.form-stack { display: grid; gap: 10px; }
.form-stack label { margin-top: 5px; color: #333; font-size: 0.86rem; font-weight: 750; }

.form-stack input,
.sidebar-language select {
    width: 100%;
    min-height: 48px;
    padding: 0 14px;
    border: 1px solid #ccc;
    border-radius: 11px;
    background: #fff;
    color: var(--ink);
}

.form-stack .button { margin-top: 12px; }

.auth-divider { display: flex; align-items: center; gap: 12px; margin: 30px 0 22px; color: var(--muted); font-size: 0.8rem; }
.auth-divider::before, .auth-divider::after { height: 1px; flex: 1; background: var(--line); content: ""; }
.auth-divider span { max-width: 210px; text-align: center; }

.flash {
    position: fixed;
    z-index: 20;
    top: 20px;
    left: 50%;
    width: min(560px, calc(100% - 32px));
    padding: 14px 18px;
    transform: translateX(-50%);
    border-radius: 12px;
    background: #f3f8ff;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.12);
    color: #0f3263;
}

.flash-error { background: #fbe9e8; color: var(--danger); }

.admin-layout { background: var(--canvas); }
.admin-layout .page-shell { min-height: 100vh; margin-left: 250px; padding: clamp(30px, 5vw, 64px); }

.app-sidebar {
    position: fixed;
    z-index: 10;
    inset: 0 auto 0 0;
    display: flex;
    width: 250px;
    height: 100vh;
    flex-direction: column;
    padding: 16px;
    overflow-y: auto;
    background: #eaeaea;
    color: #000;
    border-right: 1px solid #d0d0d0;
}

.sidebar-logo { display: block; margin-bottom: 22px; color: #000; text-decoration: none; }
.sidebar-logo-mark { display: grid; width: 100%; min-height: 0; margin-bottom: 8px; place-items: center; overflow: hidden; }
.sidebar-logo-mark img { display: block; width: 100%; height: auto; object-fit: contain; }
.sidebar-brand-name { display: block; font-size: 1.05rem; font-weight: 700; text-align: center; }

.module-nav { display: grid; gap: 7px; }
.module-nav a, .sidebar-logout { display: flex; align-items: center; gap: 11px; padding: 11px 12px; border-radius: 10px; color: #111; text-decoration: none; }
.module-nav a:hover, .module-nav a.active, .sidebar-logout:hover { background: #f7f7f7; color: #000; }
.module-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: currentColor; }
.module-nav a.active .module-dot { background: #111; box-shadow: none; }
.sidebar-spacer { flex: 1; }
.sidebar-user { display: grid; gap: 2px; margin: 0 10px 18px; }
.sidebar-user strong { overflow: hidden; text-overflow: ellipsis; }
.sidebar-user span { color: #555; font-size: .78rem; }
.sidebar-language { margin: 0 8px 16px; }
.sidebar-language label { display: block; margin-bottom: 6px; color: #555; font-size: .75rem; }
.sidebar-language select { min-height: 39px; border-color: #c9c9c9; background: #f7f7f7; color: #111; }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 30px; }
.page-heading h1 { margin-bottom: 10px; font-size: clamp(2.2rem, 4vw, 3.8rem); }
.page-heading p:last-child { color: var(--muted); }

.message-card h1 { font-size: clamp(2rem, 4vw, 3.1rem); }
.message-card p:not(.eyebrow) { color: var(--muted); }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.cms-page-header,
.cms-editor-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin: 0 auto 32px;
    max-width: 1240px;
}

.cms-page-header h1,
.cms-editor-header h1 {
    margin-bottom: 8px;
    font-size: clamp(2.3rem, 5vw, 4.5rem);
}

.cms-page-header p:last-child,
.cms-editor-header p:last-child { margin-bottom: 0; color: var(--muted); }

.cms-back-link {
    display: inline-block;
    margin-bottom: 22px;
    color: var(--muted);
    font-size: .9rem;
    font-weight: 700;
    text-decoration: none;
}

.cms-back-link:hover { color: var(--ink); }

.cms-search,
.entity-search {
    display: flex;
    gap: 10px;
    width: min(760px, 100%);
}

.cms-search { margin: 0 auto 24px; max-width: 1240px; }

.cms-search input,
.entity-search input,
.cms-form input,
.cms-form select,
.cms-version-form input,
.cms-version-form select {
    width: 100%;
    min-height: 46px;
    padding: 0 13px;
    border: 1px solid #cfd4da;
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
}

.button-quiet { background: transparent; color: var(--muted); }
.button-danger { border-color: #e4b8b8; background: #fff5f5; color: var(--danger); }
.button-danger:hover { background: #feecec; }

.cms-table-wrap {
    max-width: 1240px;
    margin: 0 auto;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
}

.cms-table { width: 100%; border-collapse: collapse; }
.cms-table th { padding: 14px 18px; border-bottom: 1px solid var(--line); background: #f7f7f7; color: var(--muted); font-size: .74rem; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
.cms-table td { padding: 18px; border-bottom: 1px solid #ececec; vertical-align: middle; font-size: .9rem; }
.cms-table tr:last-child td { border-bottom: 0; }
.cms-table td > span:not(.status-pill) { display: block; margin-top: 3px; color: var(--muted); font-size: .8rem; }
.cms-title-link { display: inline-block; max-width: 30ch; font-weight: 800; text-decoration: none; }
.cms-title-link:hover { text-decoration: underline; }
.cms-row-id { color: #8b8b8b !important; font-size: .72rem !important; }

.locale-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.locale-chips span,
.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eee;
    color: #444;
    font-size: .72rem;
    font-weight: 750;
}

.locale-chips .muted-chip { color: #999; }
.status-pill.status-published { background: #dcf6e7; color: #17663a; }

.cms-empty-state,
.cms-empty-inline {
    max-width: 720px;
    margin: 56px auto;
    padding: 44px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    text-align: center;
}

.cms-empty-state p,
.cms-empty-inline p { color: var(--muted); }

.cms-panel,
.cms-danger-zone {
    max-width: 1120px;
    margin: 0 auto 22px;
    padding: clamp(24px, 4vw, 42px);
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
}

.cms-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 30px;
}

.cms-section-heading > div { display: flex; align-items: center; gap: 12px; }
.cms-section-heading h2 { margin: 0; font-size: 1.25rem; }
.cms-section-heading p { margin: 0; color: var(--muted); font-size: .86rem; }
.section-number { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 50%; background: #111; color: #fff; font-size: .78rem; font-weight: 800; }

.cms-form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.cms-form label,
.cms-version-form label { display: grid; align-content: start; gap: 7px; color: #333; font-size: .84rem; font-weight: 750; }
.cms-form small,
.cms-version-form small { color: var(--muted); font-size: .73rem; font-weight: 500; }
.cms-form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 26px; }

.language-tabs { display: flex; gap: 8px; margin: 0 0 24px; overflow-x: auto; }
.language-tabs a { display: grid; min-width: 116px; gap: 2px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 11px; background: #f8f8f8; text-decoration: none; }
.language-tabs a.active { border-color: #111; background: #111; color: #fff; }
.language-tabs span { font-weight: 800; }
.language-tabs small { color: inherit; opacity: .68; font-size: .7rem; }

.version-meta-grid { grid-template-columns: .65fr 1.8fr 1.15fr; margin-bottom: 22px; }

.markdown-editor-shell { overflow: visible; border: 1px solid #cfd4da; border-radius: 14px; background: #fff; }
.markdown-toolbar { display: flex; align-items: center; justify-content: space-between; min-height: 54px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #f7f7f7; border-radius: 14px 14px 0 0; }
.editor-tabs { display: flex; padding: 3px; border-radius: 9px; background: #e8e8e8; }
.editor-tabs button { padding: 7px 12px; border: 0; border-radius: 7px; background: transparent; color: #666; cursor: pointer; font-weight: 750; }
.editor-tabs button.active { background: #fff; color: #111; box-shadow: 0 1px 4px rgba(0,0,0,.12); }

.block-picker { position: relative; }
.block-picker summary { padding: 7px 12px; border: 1px solid #d0d0d0; border-radius: 9px; background: #fff; cursor: pointer; font-size: .82rem; font-weight: 750; list-style: none; }
.block-picker summary::-webkit-details-marker { display: none; }
.block-picker > div { position: absolute; z-index: 5; top: calc(100% + 8px); right: 0; display: grid; width: 180px; padding: 7px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 14px 38px rgba(0,0,0,.14); }
.block-picker button { padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; color: #222; cursor: pointer; text-align: left; }
.block-picker button:hover { background: #f1f1f1; }

.editor-pane textarea {
    display: block;
    width: 100%;
    min-height: 520px;
    padding: 28px;
    resize: vertical;
    border: 0;
    border-radius: 0 0 14px 14px;
    outline: 0;
    background: #fff;
    color: #202020;
    font: 1rem/1.75 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.markdown-preview { min-height: 520px; padding: clamp(30px, 6vw, 70px); border-radius: 0 0 14px 14px; background: #fbfbfb; }
.markdown-preview > div { max-width: 720px; margin: 0 auto; color: #202020; font-size: 1.03rem; line-height: 1.75; }
.markdown-preview h1 { margin: 0 0 1.2rem; font-size: 2.5rem; line-height: 1.08; }
.markdown-preview h2 { margin: 2.2rem 0 .9rem; font-size: 1.75rem; }
.markdown-preview h3 { margin: 1.8rem 0 .7rem; font-size: 1.3rem; }
.markdown-preview blockquote { margin: 1.5rem 0; padding: 4px 0 4px 20px; border-left: 3px solid #1db9e8; color: #555; }
.markdown-preview hr { margin: 2.5rem 0; border: 0; border-top: 1px solid #d8d8d8; }
.markdown-preview code { padding: 2px 5px; border-radius: 5px; background: #ececec; }
.preview-placeholder { color: #888; }

.publication-row { display: grid; grid-template-columns: minmax(180px, .7fr) minmax(280px, 1.3fr); gap: 24px; align-items: start; margin-top: 22px; padding: 20px; border-radius: 13px; background: #f7f7f7; }
.publish-toggle { display: flex !important; align-items: center !important; grid-template-columns: auto 1fr; gap: 10px !important; min-height: 46px; }
.publish-toggle input { width: 20px; height: 20px; min-height: 0; }

.cms-inline-danger { display: flex; justify-content: flex-end; margin-top: 16px; }
.entity-search { margin-bottom: 18px; }
.entity-choice-list { display: grid; gap: 8px; }
.entity-choice-list label { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid #dedede; border-radius: 11px; background: #fafafa; cursor: pointer; }
.entity-choice-list input { width: 18px; height: 18px; }
.entity-choice-list span { display: grid; gap: 2px; }
.entity-choice-list small { color: var(--muted); font-size: .73rem; }
.cms-muted { color: var(--muted); }

.cms-danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 22px; border-color: #e6c7c7; background: #fffafa; }
.cms-danger-zone h2 { margin-bottom: 5px; font-size: 1rem; }
.cms-danger-zone p { margin: 0; color: var(--muted); font-size: .86rem; }

@media (max-width: 820px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand { min-height: 300px; }
    .auth-brand img { margin-bottom: 70px; }
    .app-sidebar { position: static; width: 100%; min-height: auto; }
    .admin-layout .page-shell { margin-left: 0; }
    .sidebar-spacer, .sidebar-user, .sidebar-language { display: none; }
}

@media (max-width: 520px) {
    .home-layout .page-shell, .login-layout .page-shell, .public-layout .page-shell { padding: 14px; }
    .home-card, .message-card, .auth-shell { border-radius: 20px; }
    .auth-brand, .auth-panel { padding: 30px; }
    .auth-brand { min-height: 250px; }
    .admin-layout .page-shell { padding: 28px 20px; }
}

@media (max-width: 900px) {
    .cms-form-grid,
    .version-meta-grid,
    .publication-row { grid-template-columns: 1fr; }
    .cms-table-wrap { overflow-x: auto; }
    .cms-table { min-width: 900px; }
}

@media (max-width: 620px) {
    .cms-page-header,
    .cms-editor-header,
    .cms-section-heading,
    .cms-danger-zone { align-items: stretch; flex-direction: column; }
    .cms-search,
    .entity-search { flex-direction: column; }
    .cms-panel,
    .cms-danger-zone { padding: 22px; border-radius: 14px; }
    .markdown-toolbar { align-items: stretch; gap: 10px; flex-direction: column; }
    .block-picker > div { right: auto; left: 0; }
    .editor-pane textarea { min-height: 440px; padding: 20px; }
    .markdown-preview { min-height: 440px; padding: 26px 20px; }
}
