:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #172033;
    --muted: #687386;
    --border: #dfe4ec;
    --primary: #3157d5;
    --primary-hover: #2647ba;
    --primary-soft: #edf1ff;
    --danger: #c73545;
    --danger-soft: #fff0f1;
    --success: #18794e;
    --warning: #9a6700;
    --shadow: 0 12px 32px rgba(35, 47, 73, .08);
    --radius: 14px;
    --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
    --bg: #0f131c;
    --surface: #181e2a;
    --surface-2: #202736;
    --text: #edf1f7;
    --muted: #9ca7b9;
    --border: #303949;
    --primary: #7895ff;
    --primary-hover: #91a9ff;
    --primary-soft: #252f54;
    --danger: #ff7b87;
    --danger-soft: #40242a;
    --success: #5bd5a0;
    --warning: #f4c152;
    --shadow: 0 14px 35px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html { background: var(--bg); color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body { background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.5; margin: 0; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
input, select, textarea { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; }
input, select { min-height: 42px; padding: 9px 11px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 17%, transparent); }
label { color: var(--text); display: grid; font-size: .9rem; font-weight: 650; gap: 7px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.7rem, 3vw, 2.25rem); letter-spacing: -.035em; line-height: 1.15; margin-bottom: 8px; }
h2 { font-size: 1.2rem; letter-spacing: -.015em; }
.muted { color: var(--muted); }
.sr-only { clip: rect(0, 0, 0, 0); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; }
.inline-form { display: inline-flex; margin: 0; }
.full { width: 100%; }

.topbar { align-items: center; background: color-mix(in srgb, var(--surface) 92%, transparent); border-bottom: 1px solid var(--border); display: flex; height: 68px; justify-content: space-between; padding: 0 max(24px, calc((100vw - 1240px) / 2)); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px); }
.brand { align-items: center; color: var(--text); display: flex; font-size: 1.04rem; font-weight: 750; gap: 10px; }
.brand:hover { text-decoration: none; }
.brand-mark { align-items: center; background: var(--primary); border-radius: 9px; color: #fff; display: inline-flex; font-size: .86rem; height: 31px; justify-content: center; width: 31px; }
.topnav { align-items: center; display: flex; gap: 17px; }
.topnav > a { color: var(--muted); font-size: .9rem; font-weight: 600; }
.user-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; font-size: .85rem; padding: 6px 11px; }
.link-button { background: none; border: 0; color: var(--muted); padding: 4px; }
.theme-toggle { background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; color: var(--text); font-size: 1.1rem; height: 37px; width: 37px; }

.page-shell { margin: 0 auto; max-width: 1288px; padding: 38px 24px 60px; }
.hero-row { align-items: flex-end; display: flex; gap: 24px; justify-content: space-between; margin: 4px 0 28px; }
.hero-row p { margin-bottom: 0; }
.eyebrow { color: var(--primary); font-size: .72rem; font-weight: 800; letter-spacing: .12em; margin-bottom: 7px; text-transform: uppercase; }

.button { align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; color: var(--text); display: inline-flex; font-size: .89rem; font-weight: 700; justify-content: center; min-height: 42px; padding: 9px 15px; transition: background .15s, border-color .15s, transform .1s; }
.button:hover { text-decoration: none; }
.button:active { transform: translateY(1px); }
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
:root[data-theme="dark"] .button.primary { color: #101522; }
.button.secondary { background: var(--surface); }
.button.secondary:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--border) 60%, var(--muted)); }
.button.dark { background: #172033; border-color: #172033; color: #fff; }
.button.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 25%, var(--border)); color: var(--danger); }
.button.compact { min-height: 35px; padding: 6px 11px; }
.button:disabled { cursor: not-allowed; opacity: .5; }
.icon-button { align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--muted); display: inline-flex; font-size: .74rem; font-weight: 800; height: 35px; justify-content: center; min-width: 37px; padding: 0 8px; }
.icon-button:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.icon-button.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.alert { border: 1px solid; border-radius: 10px; font-size: .9rem; margin-bottom: 18px; padding: 11px 14px; }
.alert-success { background: color-mix(in srgb, var(--success) 10%, var(--surface)); border-color: color-mix(in srgb, var(--success) 32%, var(--border)); color: var(--success); }
.alert-error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); color: var(--danger); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { align-items: center; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; min-height: 77px; padding: 16px 20px; }
.panel-head > div { align-items: center; display: flex; gap: 9px; }
.panel-head h2 { margin: 0; }
.count-badge { background: var(--primary-soft); border-radius: 999px; color: var(--primary); font-size: .72rem; font-weight: 800; padding: 3px 8px; }
.filter-bar { align-items: center; display: flex; gap: 8px; }
.filter-bar input { min-width: 220px; }
.filter-bar select { max-width: 190px; }
.document-list { display: grid; }
.document-row { align-items: center; border-bottom: 1px solid var(--border); display: grid; gap: 15px; grid-template-columns: auto minmax(220px, 1fr) auto; padding: 18px 20px; }
.document-row:last-child { border-bottom: 0; }
.document-row:hover { background: color-mix(in srgb, var(--surface-2) 64%, transparent); }
.document-icon { align-items: center; background: var(--primary-soft); border-radius: 10px; color: var(--primary); display: flex; font-size: .69rem; font-weight: 850; height: 43px; justify-content: center; letter-spacing: .03em; width: 43px; }
.document-info h3 { font-size: 1rem; margin: 0 0 4px; }
.document-info h3 a { color: var(--text); }
.document-info p, .document-info small { color: var(--muted); font-size: .79rem; margin: 0; }
.document-info small { display: none; }
.document-participants { align-items: center; display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.document-participants-label { color: var(--muted); font-size: .69rem; font-weight: 700; margin-right: 1px; }
.document-participant { align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; display: inline-flex; font-size: .69rem; font-weight: 750; gap: 5px; line-height: 1; padding: 4px 8px 4px 6px; white-space: nowrap; }
.document-participant .author-swatch { flex: 0 0 auto; height: 8px; width: 8px; }
.document-participant.historical { color: var(--muted); opacity: .7; }
.document-actions { align-items: center; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.empty-state { color: var(--muted); padding: 55px 20px; text-align: center; }
.empty-state.slim { padding: 28px 20px; }
.empty-state.slim p { margin: 0; }
.empty-state h3 { color: var(--text); margin-bottom: 5px; }
.empty-icon { color: var(--primary); font-size: 2rem; margin-bottom: 8px; }

.templates-section { margin-top: 38px; }
.section-heading { align-items: flex-end; display: flex; justify-content: space-between; margin-bottom: 16px; }
.section-heading h2 { font-size: 1.35rem; margin: 0; }
.section-heading > span { color: var(--muted); font-size: .82rem; }
.template-grid { display: grid; gap: 13px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.template-card { align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; color: var(--text); display: grid; gap: 13px; grid-template-columns: auto minmax(0, 1fr) auto; padding: 17px; text-align: left; transition: border .15s, box-shadow .15s, transform .15s; }
.template-card:hover { border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-2px); }
.template-symbol { align-items: center; background: var(--primary-soft); border-radius: 9px; color: var(--primary); display: flex; font-size: 1.2rem; font-weight: 800; height: 40px; justify-content: center; width: 40px; }
.template-card strong, .template-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-card strong { font-size: .92rem; }
.template-card small { color: var(--muted); font-size: .72rem; margin-top: 3px; }
.template-card .arrow { color: var(--muted); }

.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 24px 80px rgba(0, 0, 0, .27); color: var(--text); max-width: min(480px, calc(100vw - 32px)); padding: 0; width: 100%; }
.modal::backdrop { background: rgba(9, 14, 24, .56); backdrop-filter: blur(3px); }
.modal > form { padding: 24px; }
.modal-head { align-items: flex-start; display: flex; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { font-size: 1.35rem; margin: 0; }
.modal-close { background: var(--surface-2); border: 0; border-radius: 8px; color: var(--muted); font-size: 1.3rem; height: 33px; line-height: 1; width: 33px; }
.modal label input, .modal label select { width: 100%; }
.modal-fields { margin-top: 0; }
.modal-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 24px; }
.collaborators-modal { max-width: min(560px, calc(100vw - 32px)); }
.collaborators-help { font-size: .86rem; margin: -5px 0 17px; }
.collaborator-options { border: 1px solid var(--border); border-radius: 11px; display: grid; max-height: 330px; overflow-x: hidden; overflow-y: auto; }
.collaborator-option { align-items: center; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; gap: 12px; padding: 13px 14px; }
.collaborator-option:last-child { border-bottom: 0; }
.collaborator-option:hover { background: var(--surface-2); }
.collaborators-modal .collaborator-option input[type="checkbox"] { accent-color: var(--primary); flex: 0 0 19px; height: 19px; margin: 0; min-height: 0; padding: 0; width: 19px; }
.collaborator-option span { display: grid; flex: 1 1 auto; gap: 2px; min-width: 0; }
.collaborator-option strong { font-size: .88rem; }
.collaborator-option small { color: var(--muted); font-size: .74rem; font-weight: 500; }
.collaborator-option strong, .collaborator-option small { overflow-wrap: anywhere; }

.auth-page .topbar { position: static; }
.auth-page .page-shell { align-items: center; display: flex; justify-content: center; min-height: calc(100vh - 68px); padding-bottom: 48px; padding-top: 48px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 17px; box-shadow: var(--shadow); max-width: 430px; padding: 34px; width: 100%; }
.auth-card h1 { font-size: 1.75rem; }
.stack-form { display: grid; gap: 16px; margin-top: 22px; }
.stack-form input, .stack-form select { width: 100%; }
.auth-foot { border-top: 1px solid var(--border); color: var(--muted); font-size: .88rem; margin: 24px 0 0; padding-top: 20px; text-align: center; }
.install-card { max-width: 520px; }
.requirement-list { display: grid; gap: 7px; list-style: none; margin: 22px 0; padding: 0; }
.requirement-list li { align-items: center; color: var(--muted); display: flex; font-size: .88rem; gap: 9px; }
.requirement-list li span { align-items: center; border-radius: 50%; display: inline-flex; font-weight: 800; height: 22px; justify-content: center; width: 22px; }
.requirement-list .ok span { background: color-mix(in srgb, var(--success) 12%, var(--surface)); color: var(--success); }
.requirement-list .fail span { background: var(--danger-soft); color: var(--danger); }
.path-note { background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; padding: 10px 12px; }

.editor-page .page-shell { max-width: none; padding: 22px 24px 30px; }
.editor-header { align-items: center; display: flex; gap: 20px; justify-content: space-between; margin-bottom: 18px; }
.editor-title { align-items: center; display: flex; min-width: 0; }
.editor-title h1 { font-size: 1.25rem; margin: 0 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-title p { color: var(--muted); font-size: .76rem; margin: 0; }
.back-link { align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; color: var(--text); display: flex; flex: 0 0 auto; height: 38px; justify-content: center; margin-right: 12px; width: 38px; }
.back-link:hover { text-decoration: none; }
.editor-actions { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.save-status { color: var(--muted); font-size: .78rem; margin-right: 5px; min-width: 90px; text-align: right; }
.save-status[data-state="saving"] { color: var(--warning); }
.save-status[data-state="saved"] { color: var(--success); }
.save-status[data-state="error"] { color: var(--danger); }
.save-status[data-state="sync"] { color: var(--primary); }
.collaboration-legend { align-items: center; display: flex; flex-wrap: wrap; gap: 7px 9px; margin: -7px auto 11px; max-width: 1060px; }
.collaboration-legend > strong { color: var(--muted); font-size: .72rem; }
.legend-user { align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; display: inline-flex; font-size: .72rem; font-weight: 700; gap: 6px; padding: 4px 9px 4px 6px; }
.legend-user.historical { color: var(--muted); opacity: .78; }
.author-swatch { background: var(--author-color); border-radius: 50%; height: 10px; width: 10px; }
.author-color-0 { --author-color: #18a66a; }
.author-color-1 { --author-color: #3977e8; }
.author-color-2 { --author-color: #8b5cf6; }
.author-color-3 { --author-color: #e77817; }
.author-color-4 { --author-color: #db4f91; }
.author-color-5 { --author-color: #0b9fa5; }
.author-color-6 { --author-color: #c29312; }
.author-color-7 { --author-color: #dc4c4c; }
.editor-workspace { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); display: grid; grid-template-rows: auto minmax(0, 1fr); height: calc(100vh - 215px); margin: 0 auto; max-width: 1060px; min-height: 540px; overflow: hidden; }
.visual-toolbar { align-items: center; background: var(--surface-2); border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 5px; min-height: 50px; padding: 7px 12px; }
.visual-toolbar button { background: transparent; border: 1px solid transparent; border-radius: 7px; color: var(--muted); font-size: .78rem; height: 33px; min-width: 34px; padding: 5px 9px; }
.visual-toolbar button:hover { background: var(--surface); border-color: var(--border); color: var(--text); }
.visual-toolbar .task-command { color: var(--primary); font-weight: 750; }
.visual-toolbar select { background: transparent; border-color: transparent; box-shadow: none; font-size: .79rem; font-weight: 650; min-height: 33px; padding: 4px 28px 4px 8px; }
.visual-toolbar select:hover, .visual-toolbar select:focus { background: var(--surface); border-color: var(--border); box-shadow: none; }
.visual-toolbar-help { color: var(--muted); font-size: .72rem; margin-left: auto; padding: 0 5px; }
.live-dot { background: var(--success); border-radius: 50%; display: inline-block; height: 7px; margin-right: 3px; width: 7px; }
.toolbar-separator { background: var(--border); height: 22px; margin: 0 3px; width: 1px; }
.markdown-body { background: var(--surface); color: var(--text); overflow: auto; padding: 30px clamp(24px, 4vw, 54px) 60px; }
.visual-editor { cursor: text; min-height: 100%; outline: none; padding: 46px clamp(30px, 7vw, 88px) 90px; scroll-padding: 45px; }
.visual-editor:empty::before { color: var(--muted); content: "Empieza a escribir…"; pointer-events: none; }
.visual-editor .task-list { list-style: none; padding-left: 0; }
.visual-editor .task-list .task-list { padding-left: 30px; }
.visual-editor .task-list-item { list-style: none; margin: .75em 0; padding-left: 29px; position: relative; }
.visual-editor .task-list-item > input[type="checkbox"] { accent-color: var(--primary); cursor: pointer; height: 18px; left: 2px; margin: 0; min-height: 0; padding: 0; position: absolute; top: .22em; width: 18px; }
.visual-editor .task-list-item.is-checked { color: var(--muted); }
.visual-editor .task-list-item.is-checked > table { color: var(--text); }
.visual-editor td, .visual-editor th { min-width: 120px; }
.visual-editor td:focus, .visual-editor th:focus { background: color-mix(in srgb, var(--primary) 6%, var(--surface)); }
.visual-editor .authored-block { background-color: color-mix(in srgb, var(--author-color) 7%, transparent); box-shadow: inset 3px 0 var(--author-color); }
.visual-editor p.authored-block, .visual-editor h1.authored-block, .visual-editor h2.authored-block, .visual-editor h3.authored-block, .visual-editor h4.authored-block, .visual-editor h5.authored-block, .visual-editor h6.authored-block, .visual-editor pre.authored-block, .visual-editor blockquote.authored-block { border-radius: 4px; padding-left: 12px; padding-right: 8px; }
.visual-editor li.authored-block { border-radius: 4px; }
.visual-editor tr.authored-block > th, .visual-editor tr.authored-block > td { background-color: color-mix(in srgb, var(--author-color) 9%, var(--surface)); }
.sync-conflict { align-items: center; background: var(--surface); border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--border)); border-radius: 13px; bottom: 20px; box-shadow: 0 18px 55px rgba(0, 0, 0, .22); display: flex; gap: 20px; justify-content: space-between; left: 50%; max-width: min(760px, calc(100vw - 30px)); padding: 14px 16px; position: fixed; transform: translateX(-50%); width: 100%; z-index: 50; }
.sync-conflict[hidden] { display: none; }
.sync-conflict > div:first-child { display: grid; gap: 2px; }
.sync-conflict strong { font-size: .88rem; }
.sync-conflict span { color: var(--muted); font-size: .78rem; }
.sync-conflict-actions { display: flex; flex: 0 0 auto; gap: 7px; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { line-height: 1.3; margin: 1.4em 0 .65em; }
.markdown-body h1 { border-bottom: 2px solid var(--primary); font-size: 2rem; padding-bottom: .32em; }
.markdown-body h2 { border-bottom: 1px solid var(--border); font-size: 1.45rem; padding-bottom: .25em; }
.markdown-body h3 { font-size: 1.16rem; }
.markdown-body p { margin-bottom: 1em; }
.markdown-body a { text-decoration: underline; }
.markdown-body blockquote { background: var(--surface-2); border-left: 4px solid var(--primary); color: var(--muted); margin: 1em 0; padding: 10px 16px; }
.markdown-body blockquote > :last-child { margin-bottom: 0; }
.markdown-body table { border-collapse: collapse; display: block; margin: 1em 0; max-width: 100%; overflow-x: auto; width: max-content; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 8px 11px; }
.markdown-body th { background: var(--surface-2); }
.markdown-body code { background: var(--surface-2); border-radius: 4px; color: color-mix(in srgb, var(--danger) 80%, var(--text)); font: .87em "Cascadia Code", Consolas, monospace; padding: 2px 5px; }
.markdown-body pre { background: #172033; border-radius: 8px; color: #e9eef7; line-height: 1.55; overflow: auto; padding: 16px; }
.markdown-body pre code { background: transparent; color: inherit; padding: 0; }
.markdown-body img { height: auto; max-width: 100%; }
.markdown-body hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.preview-loading, .preview-error { color: var(--muted); font-size: .9rem; }

.reader-page .page-shell { max-width: 1060px; }
.reader-header { align-items: center; display: flex; gap: 20px; justify-content: space-between; margin-bottom: 16px; }
.readonly-badge { background: color-mix(in srgb, var(--primary) 11%, var(--surface)); border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border)); border-radius: 20px; color: var(--primary); font-size: .76rem; font-weight: 750; padding: 7px 12px; white-space: nowrap; }
.reader-meta { color: var(--muted); display: flex; flex-wrap: wrap; font-size: .78rem; gap: 8px 22px; margin: 0 0 14px 50px; }
.readonly-document { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-height: 540px; overflow: visible; padding: 46px clamp(30px, 7vw, 88px) 80px; }
.readonly-document input[type="checkbox"] { accent-color: var(--primary); height: 17px; min-height: 0; pointer-events: none; width: 17px; }

.admin-tabs { border-bottom: 1px solid var(--border); display: flex; gap: 25px; margin: -5px 0 24px; }
.admin-tabs a { border-bottom: 2px solid transparent; color: var(--muted); font-size: .88rem; font-weight: 700; padding: 12px 2px; }
.admin-tabs a.active { border-color: var(--primary); color: var(--primary); }
.admin-tabs a:hover { text-decoration: none; }
.stats-grid { display: grid; gap: 14px; grid-template-columns: repeat(3, 1fr); margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: grid; min-height: 150px; padding: 21px; }
.stat-card > span { color: var(--muted); font-size: .83rem; font-weight: 650; }
.stat-card > strong { font-size: 2.25rem; letter-spacing: -.04em; }
.stat-card > a, .stat-card > small { align-self: end; color: var(--muted); font-size: .79rem; }
.admin-panel { margin-top: 18px; }
.simple-table-wrap { overflow-x: auto; }
.simple-table { border-collapse: collapse; font-size: .86rem; width: 100%; }
.simple-table th, .simple-table td { border-bottom: 1px solid var(--border); padding: 14px 18px; text-align: left; vertical-align: middle; }
.simple-table th { background: var(--surface-2); color: var(--muted); font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; }
.simple-table tbody tr:last-child td { border-bottom: 0; }
.inline-controls, .table-actions { align-items: center; display: flex; gap: 7px; }
.inline-controls select { min-height: 35px; padding: 5px 8px; }
.settings-grid { align-items: start; display: grid; gap: 18px; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.settings-form { display: grid; gap: 25px; padding: 26px; }
.settings-form h2 { margin-bottom: 4px; }
.settings-form > label:not(.switch-row) { max-width: 560px; }
.switch-row { align-items: center; border: 1px solid var(--border); border-radius: 11px; display: flex; justify-content: space-between; max-width: 660px; padding: 15px; }
.switch-row span { display: grid; gap: 3px; }
.switch-row small { color: var(--muted); font-weight: 400; }
.switch-row input { accent-color: var(--primary); height: 21px; min-height: 0; width: 21px; }
.info-panel { padding: 24px; }
.info-panel dl { margin: 0; }
.info-panel dl div { border-bottom: 1px solid var(--border); display: flex; font-size: .85rem; justify-content: space-between; padding: 12px 0; }
.info-panel dl div:last-child { border-bottom: 0; }
.info-panel dt { color: var(--muted); }
.info-panel dd { font-weight: 650; margin: 0; }
.template-admin-grid { align-items: start; display: grid; gap: 18px; grid-template-columns: minmax(280px, .8fr) minmax(0, 1.6fr); }
.upload-panel { display: grid; gap: 22px; padding: 25px; }
.upload-panel h2 { margin-bottom: 5px; }
.file-drop { background: var(--surface-2); border: 1px dashed color-mix(in srgb, var(--primary) 45%, var(--border)); border-radius: 11px; padding: 17px; }
.file-drop input { border: 0; box-shadow: none; min-height: 0; padding: 0; width: 100%; }
.file-drop span { color: var(--muted); display: block; font-size: .78rem; font-weight: 500; margin-top: 8px; }
.template-management { min-width: 0; }
.managed-template-list { display: grid; }
.managed-template-row { align-items: center; border-bottom: 1px solid var(--border); display: grid; gap: 12px; grid-template-columns: auto minmax(0, 1fr) auto; padding: 15px 18px; }
.managed-template-row:last-child { border-bottom: 0; }
.managed-template-row strong, .managed-template-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.managed-template-row small { color: var(--muted); font-size: .74rem; margin-top: 3px; }

@media (max-width: 1000px) {
    .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .document-row { align-items: start; grid-template-columns: auto 1fr; }
    .document-actions { grid-column: 2; justify-content: flex-start; }
    .editor-header { align-items: flex-start; }
    .editor-actions { max-width: 55%; }
    .editor-workspace { height: calc(100vh - 258px); }
    .user-table { min-width: 850px; }
}

@media (max-width: 720px) {
    .topbar { height: 60px; padding: 0 16px; }
    .brand { font-size: .94rem; }
    .brand-mark { height: 28px; width: 28px; }
    .topnav { gap: 9px; }
    .topnav > a, .user-chip { display: none; }
    .page-shell { padding: 26px 15px 45px; }
    .hero-row { align-items: stretch; flex-direction: column; margin-bottom: 22px; }
    .hero-row .button { align-self: flex-start; }
    .panel-head { align-items: stretch; flex-direction: column; gap: 13px; }
    .filter-bar { align-items: stretch; flex-wrap: wrap; }
    .filter-bar .search-field { flex: 1 1 100%; }
    .filter-bar input { min-width: 0; width: 100%; }
    .filter-bar select { max-width: none; }
    .document-row { gap: 11px; padding: 15px; }
    .document-info p { display: none; }
    .document-info small { display: block; }
    .document-actions { grid-column: 1 / -1; }
    .document-actions > .button { flex: 1; }
    .template-grid { grid-template-columns: 1fr; }
    .section-heading { align-items: flex-start; }
    .section-heading > span { display: none; }
    .auth-page .page-shell { min-height: calc(100vh - 60px); padding: 22px 15px; }
    .auth-card { padding: 25px 20px; }

    .editor-page .page-shell { padding: 14px 10px 20px; }
    .editor-header { display: grid; gap: 12px; }
    .editor-actions { max-width: none; }
    .editor-actions .save-status { margin-left: 49px; order: -1; text-align: left; width: calc(100% - 49px); }
    .editor-actions .button { flex: 1; font-size: .78rem; padding: 7px 8px; }
    .collaboration-legend { margin-top: -3px; }
    .editor-workspace { height: calc(100vh - 300px); min-height: 430px; }
    .visual-toolbar { flex-wrap: nowrap; overflow-x: auto; padding: 6px 8px; }
    .visual-toolbar-help { display: none; }
    .visual-editor { padding: 28px 20px 55px; }
    .sync-conflict { align-items: stretch; bottom: 10px; display: grid; gap: 11px; }
    .sync-conflict[hidden] { display: none; }
    .sync-conflict-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .reader-header { align-items: flex-start; }
    .reader-meta { display: grid; gap: 3px; margin-left: 0; }
    .readonly-document { min-height: 430px; padding: 28px 20px 55px; }
    .stats-grid { grid-template-columns: 1fr; }
    .stat-card { min-height: 125px; }
    .settings-grid { grid-template-columns: 1fr; }
    .template-admin-grid { grid-template-columns: 1fr; }
    .admin-tabs { gap: 15px; overflow-x: auto; }
}

@media print {
    .topbar, .editor-header, .visual-toolbar { display: none !important; }
    .page-shell, .editor-page .page-shell { margin: 0; max-width: none; padding: 0; }
    .editor-workspace { border: 0; display: block; height: auto; }
    .visual-editor { overflow: visible; padding: 0; }
}
