:root {
    --theme-maroon: #9a2a2a;
    --theme-maroon-deep: #4a1414;
    --chrome: #0b0909;
    --pane: #12100f;
    --sidebar: #0e0c0b;
    --paper: #161210;
    --paper-elevated: #1b1614;
    --line: rgba(232, 214, 188, 0.1);
    --line-strong: rgba(232, 214, 188, 0.18);
    --ink: #f4ece0;
    --muted: #9d9184;
    --rule: rgba(212, 175, 55, 0.07);
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.28);
    --tab-radius: 11px 11px 0 0;
    --accent: #d4af37;
    --accent-soft: rgba(212, 175, 55, 0.14);
    --maroon: #8e2323;
    --maroon-hot: #b43333;
    --code-bg: #100d0c;
    --danger: #f87171;
    --ok: #6ee7a8;
    --warn: #f0c14b;
    --radius: 12px;
    --radius-sm: 8px;
    --font-ui: "Outfit", "Segoe UI", system-ui, sans-serif;
    --font-display: "Instrument Serif", "Palatino Linotype", Georgia, serif;
    --font-editor: "Source Serif 4", "Palatino Linotype", Georgia, serif;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
}

body.app-shell {
    font-family: var(--font-ui);
    color: var(--ink);
    background: var(--chrome);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ── Login ─────────────────────────────────────────────────────────── */

body.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background:
        radial-gradient(900px 480px at 50% -12%, rgba(158, 42, 42, 0.32), transparent 58%),
        radial-gradient(520px 360px at 92% 108%, rgba(212, 175, 55, 0.1), transparent 55%),
        var(--chrome);
}

.login-atmosphere {
    pointer-events: none;
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
    opacity: 0.07;
}

.login-card {
    position: relative;
    width: min(420px, calc(100% - 32px));
    background: linear-gradient(180deg, #1a1513 0%, #14100f 100%);
    border: 1px solid var(--line-strong);
    border-radius: 22px;
    box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    padding: 36px 32px 28px;
}

.login-card::before {
    content: "";
    position: absolute;
    left: 28px;
    right: 28px;
    top: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.55;
}

.login-card h1 {
    margin: 22px 0 8px;
    font-family: var(--font-display);
    font-size: 38px;
    font-weight: 400;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.login-card p {
    margin: 0 0 22px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.login-card label {
    display: block;
    margin-bottom: 14px;
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 500;
}

.login-card input {
    display: block;
    width: 100%;
    margin-top: 7px;
    border: 1px solid var(--line-strong);
    background: rgba(8, 6, 6, 0.72);
    color: var(--ink);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 15px;
    font-family: var(--font-ui);
    text-transform: none;
    letter-spacing: 0;
    transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}

.login-card input:focus {
    outline: none;
    border-color: rgba(212, 175, 55, 0.55);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.login-card button[type="submit"] {
    width: 100%;
    margin-top: 10px;
    border: 0;
    border-radius: 10px;
    background: linear-gradient(180deg, #b43333 0%, #8e2323 100%);
    color: #fff;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 13px 14px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(142, 35, 35, 0.35);
    transition: transform 160ms var(--ease), filter 160ms var(--ease);
}

.login-card button[type="submit"]:hover { filter: brightness(1.08); transform: translateY(-1px); }

.login-error {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.32);
    color: #fca5a5;
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 16px;
    font-size: 13px;
}

/* ── Brand ─────────────────────────────────────────────────────────── */

.brand-mark {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, #2a1616 0%, #1a1010 100%);
    border: 1px solid rgba(212, 175, 55, 0.28);
    color: var(--accent);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
    flex: 0 0 auto;
}

.brand-icon i { font-size: 17px; }

.brand-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.15;
}

.brand-name {
    font-family: var(--font-display);
    font-size: 22px;
    letter-spacing: 0.01em;
    text-transform: none;
    font-weight: 400;
}

.login-card .brand-name {
    font-size: 15px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-family: var(--font-ui);
    font-weight: 600;
    color: #e8d7b0;
}

.brand-sub {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(244, 236, 224, 0.48);
    font-weight: 500;
}

/* ── Shell ─────────────────────────────────────────────────────────── */

.app-frame {
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.top-chrome {
    flex: 0 0 auto;
    background:
        linear-gradient(180deg, #1c1212 0%, #120d0d 100%);
    color: #fff;
    padding: 12px 18px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
    z-index: 5;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 10px;
}

.brand-cluster {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.app-switch {
    display: inline-flex;
    align-items: stretch;
    gap: 2px;
    padding: 3px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.28);
    flex: 0 0 auto;
}

.app-switch-btn,
a.app-switch-btn {
    appearance: none;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 11px;
    border-radius: 7px;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.58);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    transition: background 140ms var(--ease), color 140ms var(--ease);
}

.app-switch-btn:hover,
a.app-switch-btn:hover {
    color: #f3e6c0;
    background: rgba(212, 175, 55, 0.1);
}

.app-switch-btn.is-active,
a.app-switch-btn.is-active {
    background: rgba(212, 175, 55, 0.2);
    color: #f6e7bc;
    box-shadow: inset 0 0 0 1px rgba(212, 175, 55, 0.28);
}

.app-switch-login {
    position: fixed;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
}

.chrome-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chrome-btn,
a.chrome-btn {
    appearance: none;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    padding: 0 11px;
    border-radius: 9px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.88);
    font-family: var(--font-ui);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 140ms var(--ease), border-color 140ms var(--ease), color 140ms var(--ease);
}

.chrome-btn:hover,
a.chrome-btn:hover {
    background: rgba(212, 175, 55, 0.12);
    border-color: rgba(212, 175, 55, 0.32);
    color: #f3e6c0;
}

.chrome-btn-quiet {
    background: transparent;
    border-color: transparent;
    color: rgba(255, 255, 255, 0.62);
}

.chrome-btn-quiet:hover { color: #fff; }

.binder-tabs {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px 2px 0;
    scrollbar-width: thin;
    scrollbar-color: #3a2a2a transparent;
}

.binder-tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 128px;
    max-width: 220px;
    height: 34px;
    padding: 0 6px 0 12px;
    border: 1px solid transparent;
    border-bottom: 0;
    border-radius: var(--tab-radius);
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.72);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transform: translateY(4px);
    transition: transform 180ms var(--ease), background 180ms var(--ease), color 180ms var(--ease);
    white-space: nowrap;
}

.binder-tab .tab-menu {
    color: inherit;
    width: 22px;
    height: 22px;
    opacity: 0.55;
}

.binder-tab.active .tab-menu { color: var(--muted); opacity: 1; }

.binder-tab::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tab-color, var(--accent));
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--tab-color, var(--accent)) 28%, transparent);
    flex: 0 0 auto;
}

.binder-tab span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.binder-tab:hover {
    background: rgba(255, 255, 255, 0.09);
    color: #fff;
    transform: translateY(2px);
}

.binder-tab.active {
    background: var(--pane);
    color: var(--ink);
    transform: translateY(1px);
    z-index: 2;
    border-color: var(--line);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
}

.binder-tab.active::before {
    background: var(--tab-color, var(--accent));
    box-shadow: none;
}

.tab-add {
    height: 30px;
    min-width: auto;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed rgba(255, 255, 255, 0.22);
    color: rgba(255, 255, 255, 0.78);
    transform: translateY(4px);
    font-weight: 500;
}

.tab-add::before { display: none; }

/* ── Workspace ─────────────────────────────────────────────────────── */

.workspace {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: 292px minmax(0, 1fr);
    background: var(--pane);
    overflow: hidden;
}

.sidebar {
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 80px),
        var(--sidebar);
    border-right: 1px solid var(--line);
    overflow: hidden;
}

.search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 14px 14px 10px;
    flex: 0 0 auto;
}

.search-wrap input {
    width: 100%;
    flex: 1;
    min-width: 0;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
    color: var(--ink);
    border-radius: 10px;
    padding: 9px 12px 9px 36px;
    font-size: 13px;
    font-family: var(--font-ui);
    outline: none;
    transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}

.search-wrap input::placeholder { color: #7d7168; }
.search-wrap input:focus {
    border-color: rgba(212, 175, 55, 0.45);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-wrap > i {
    position: absolute;
    left: 26px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 13px;
    pointer-events: none;
}

.tree-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 2px 10px 20px;
    scrollbar-width: thin;
    scrollbar-color: #3a2a2a transparent;
}

.tree-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 8px 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.tree-heading-actions { display: flex; align-items: center; gap: 2px; }

.icon-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    width: 28px;
    height: 28px;
    border-radius: 7px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 140ms var(--ease), color 140ms var(--ease);
}

.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

.tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 7px 8px;
    border-radius: 9px;
    cursor: pointer;
    color: var(--ink);
    font-size: 13.5px;
    position: relative;
    transition: background 140ms var(--ease);
}

.tree-item .dropdown {
    opacity: 0;
    transition: opacity 140ms var(--ease);
}

.tree-item:hover .dropdown,
.tree-item.active .dropdown,
.tree-item .dropdown:focus-within { opacity: 1; }

.tree-item:hover { background: rgba(255, 255, 255, 0.035); }

.tree-item.active {
    background: rgba(212, 175, 55, 0.08);
    box-shadow: inset 3px 0 0 var(--item-color, var(--accent));
}

.tree-item .title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.section-swatch,
.section-icon {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    flex: 0 0 auto;
    display: inline-grid;
    place-items: center;
    color: rgba(255, 255, 255, 0.92);
    font-size: 10px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.page-dot,
.page-icon {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.04);
    color: #8a7f74;
    flex: 0 0 auto;
    display: inline-grid;
    place-items: center;
    font-size: 11px;
}

.tree-item.pinned .page-icon,
.tree-item.pinned .page-dot {
    color: #e4c36a;
    background: rgba(228, 195, 106, 0.12);
}

.tree-children {
    margin-left: 14px;
    border-left: 1px solid rgba(232, 214, 188, 0.08);
    padding-left: 6px;
}

.tree-item.drag-over { outline: 1px dashed var(--accent); outline-offset: -1px; }

.empty-hint {
    padding: 12px 10px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

/* ── Editor canvas ─────────────────────────────────────────────────── */

.canvas {
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    padding: 0;
    overflow: hidden;
}

.canvas.is-empty #editor-pane { display: none !important; }
.canvas.has-page #editor-empty { display: none !important; }

#editor-pane {
    display: none;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
}

.canvas.has-page #editor-pane { display: flex; }

.editor-stage {
    width: 100%;
    margin: 0;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.page-meta {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 0;
    padding: 16px 28px 12px;
    flex: 0 0 auto;
    background:
        radial-gradient(900px 420px at 50% -8%, rgba(158, 42, 42, 0.12), transparent 55%),
        var(--pane);
    border-bottom: 1px solid var(--line);
}

#page-title {
    width: 100%;
    border: 0;
    background: transparent;
    font-family: var(--font-display);
    font-size: clamp(28px, 3.4vw, 40px);
    font-weight: 400;
    letter-spacing: -0.02em;
    color: var(--ink);
    outline: none;
    padding: 2px 2px 0;
    line-height: 1.15;
}

#page-title::placeholder { color: #6d635a; }

.meta-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex: 0 0 auto;
    padding-top: 6px;
}

.save-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 10px 4px 8px;
    font-weight: 600;
}

.save-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.save-pill.saving { color: var(--warn); }
.save-pill.saving .save-dot { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
.save-pill.saved { color: var(--ok); }
.save-pill.saved .save-dot { background: var(--ok); }
.save-pill.error { color: var(--danger); }
.save-pill.error .save-dot { background: var(--danger); }

@keyframes pulse {
    50% { opacity: 0.35; }
}

.timestamp { font-size: 12px; color: var(--muted); white-space: nowrap; }

.toolbar-extras {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 0;
}

.tool-btn,
.ghost-btn,
a.ghost-btn {
    appearance: none;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
    color: var(--ink);
    border-radius: 8px;
    padding: 6px 10px;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 140ms var(--ease), background 140ms var(--ease), color 140ms var(--ease);
}

.tool-btn { height: 32px; }

.tool-btn:hover,
.ghost-btn:hover {
    border-color: rgba(212, 175, 55, 0.4);
    color: var(--accent);
    background: var(--accent-soft);
}

.primary-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 10px;
    background: linear-gradient(180deg, #b43333 0%, #8e2323 100%);
    color: #fff;
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    padding: 10px 16px;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(142, 35, 35, 0.28);
    transition: transform 160ms var(--ease), filter 160ms var(--ease);
}

.primary-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* ── Paper / Quill ─────────────────────────────────────────────────── */

.paper-wrap {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 40px),
        var(--paper);
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    position: relative;
}

.ql-toolbar.ql-snow {
    border: 0 !important;
    border-bottom: 1px solid var(--line) !important;
    background: rgba(10, 8, 8, 0.55);
    padding: 8px 12px 8px 14px !important;
    flex: 0 0 auto;
    z-index: 3;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 4px;
}

.ql-toolbar.ql-snow .ql-formats {
    margin-right: 10px;
    padding-right: 10px;
    border-right: 1px solid var(--line);
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.ql-toolbar.ql-snow .ql-formats:last-child {
    border-right: 0;
    margin-right: 0;
    padding-right: 0;
}

.ql-snow.ql-toolbar button,
.ql-snow .ql-toolbar button {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ql-snow.ql-toolbar button:hover,
.ql-snow .ql-toolbar button:hover,
.ql-snow.ql-toolbar button.ql-active,
.ql-snow .ql-toolbar button.ql-active,
.ql-snow.ql-toolbar .ql-picker-label:hover,
.ql-snow.ql-toolbar .ql-picker-label.ql-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.ql-container.ql-snow {
    border: 0 !important;
    flex: 1 1 auto;
    min-height: 0;
    height: auto !important;
    overflow: hidden;
    font-family: var(--font-editor);
    font-size: 17.5px;
    position: relative;
}

.ql-editor {
    height: 100% !important;
    min-height: 100% !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 28px 28px 80vh !important;
    line-height: 1.75;
    color: var(--ink);
    scrollbar-width: thin;
    scrollbar-color: #463030 transparent;
}

.ql-editor.ql-blank::before {
    color: #7a6f66;
    font-style: italic;
    font-family: var(--font-editor);
    position: absolute;
    top: 28px;
    left: 28px;
    right: 28px;
    pointer-events: none;
}

.ql-editor h1,
.ql-editor h2,
.ql-editor h3 {
    font-family: var(--font-display);
    font-weight: 400;
    letter-spacing: -0.02em;
    line-height: 1.25;
    color: #fff8ec;
}

.ql-editor h1 { font-size: 2rem; margin: 0.4em 0 0.45em; }
.ql-editor h2 { font-size: 1.5rem; margin: 1em 0 0.4em; }
.ql-editor h3 { font-size: 1.2rem; margin: 1em 0 0.35em; }

.ql-editor p { margin-bottom: 0.15em; }

.ql-editor blockquote {
    border-left: 3px solid var(--accent);
    background: rgba(212, 175, 55, 0.05);
    margin: 16px 0;
    padding: 10px 16px;
    border-radius: 0 10px 10px 0;
    color: #efe4d2;
}

.ql-editor ul,
.ql-editor ol { padding-left: 0.4em; }

.ql-editor li { padding: 2px 0; }

.ql-editor a { color: #e4c36a; }

.ql-editor ::selection {
    background: rgba(212, 175, 55, 0.28);
    color: #fff8ec;
}

.ql-editor .ql-ui {
    position: absolute;
}

.ql-editor li[data-list="checked"] > .ql-ui,
.ql-editor li[data-list="unchecked"] > .ql-ui {
    margin-top: 0.35em;
}

.paper-lined .ql-editor {
    background-image: repeating-linear-gradient(
        transparent,
        transparent 30px,
        var(--rule) 31px
    );
    background-attachment: local;
}

.paper-grid .ql-editor {
    background-image:
        linear-gradient(var(--rule) 1px, transparent 1px),
        linear-gradient(90deg, var(--rule) 1px, transparent 1px);
    background-size: 28px 28px;
    background-attachment: local;
}

.paper-blank .ql-editor { background-image: none; }

.paper-lined .ql-editor table,
.paper-lined .ql-editor pre,
.paper-lined .ql-editor blockquote,
.paper-grid .ql-editor table,
.paper-grid .ql-editor pre,
.paper-grid .ql-editor blockquote {
    background-color: #181310;
}

.ql-snow .ql-stroke { stroke: #d6cabb; }
.ql-snow .ql-fill { fill: #d6cabb; }
.ql-snow .ql-picker { color: #d6cabb; }
.ql-snow .ql-picker-label { border-radius: 7px; padding: 2px 8px; }
.ql-snow .ql-picker-options {
    background: #1a1513;
    border-color: var(--line-strong);
    color: var(--ink);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 6px;
}
.ql-snow .ql-picker-item { border-radius: 6px; }
.ql-snow .ql-picker-item:hover { color: var(--accent); }

.ql-snow .ql-tooltip {
    background: #1a1513;
    border-color: var(--line-strong);
    color: var(--ink);
    box-shadow: var(--shadow);
    border-radius: 10px;
}
.ql-snow .ql-tooltip input[type="text"] {
    background: #0d0b0b;
    color: var(--ink);
    border-color: var(--line);
    border-radius: 6px;
}

.ql-editor pre.ql-syntax,
.ql-editor pre {
    background: var(--code-bg);
    color: #efe6d6;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 14px;
}

.ql-editor img,
.ql-editor .note-image {
    max-width: 100%;
    height: auto;
    display: inline-block;
    vertical-align: middle;
    border-radius: 8px;
    cursor: grab;
    box-shadow: 0 0 0 1px rgba(212, 175, 55, 0.22);
    -webkit-user-drag: none;
    user-select: none;
    touch-action: none;
}

.ql-editor img.is-selected {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    cursor: grab;
}

.ql-editor img.is-dragging {
    opacity: 0.45;
    cursor: grabbing;
}

.ql-editor .ql-swap-target {
    outline: 1px dashed var(--accent);
    background: rgba(128, 0, 0, 0.22);
}

#img-frame {
    position: fixed;
    z-index: 40;
    pointer-events: auto;
    touch-action: none;
    border: 2px solid var(--accent);
    box-sizing: border-box;
    border-radius: 8px;
}

#img-frame .img-handle,
#img-frame .img-delete {
    pointer-events: auto;
    touch-action: none;
}

.img-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    padding: 0;
    border: 2px solid #171112;
    background: var(--accent);
    border-radius: 4px;
    z-index: 2;
}

.img-handle::after {
    content: '';
    position: absolute;
    inset: -14px;
}

.img-handle[data-handle="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.img-handle[data-handle="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.img-handle[data-handle="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.img-handle[data-handle="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }

.img-delete {
    position: absolute;
    top: -36px;
    right: 0;
    border: 1px solid var(--line);
    background: #171112;
    color: #f87171;
    border-radius: 8px;
    width: 30px;
    height: 28px;
    cursor: pointer;
}

.img-delete:hover { background: #2b1717; }

#img-caret {
    position: fixed;
    z-index: 41;
    width: 2px;
    background: var(--accent);
    pointer-events: none;
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.6);
}

.empty-canvas {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(900px 420px at 50% -8%, rgba(158, 42, 42, 0.12), transparent 55%),
        var(--pane);
}

.empty-card {
    width: min(420px, 100%);
    text-align: center;
    padding: 36px 28px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
}

.empty-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, #2a1616, #1a1010);
    border: 1px solid rgba(212, 175, 55, 0.28);
    color: var(--accent);
    font-size: 28px;
}

.empty-card h2 {
    margin: 0 0 8px;
    font-family: var(--font-display);
    font-size: 30px;
    font-weight: 400;
}

.empty-card p {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.55;
}

.dropdown { position: relative; display: inline-block; }

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 200px;
    background: #1a1513;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 6px;
    z-index: 30;
}

.dropdown-menu.show { display: block; }

.tab-menu-pop {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 95;
    min-width: 180px;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 8px 10px;
    border-radius: 8px;
    font-family: var(--font-ui);
    font-size: 13px;
    color: var(--ink);
    cursor: pointer;
}

.dropdown-item:hover { background: var(--accent-soft); color: var(--accent); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: rgba(248, 113, 113, 0.1); color: #fca5a5; }
.dropdown-item.is-active { color: var(--accent); background: var(--accent-soft); }
.dropdown-divider {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 5px 6px;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    padding: 10px 2px 4px;
}

.color-swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid #171112;
    box-shadow: 0 0 0 1px #463030;
    cursor: pointer;
}

.color-swatch.is-selected {
    box-shadow: 0 0 0 2px var(--accent);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(5, 3, 3, 0.72);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 80;
    padding: 20px;
}

.modal-backdrop.open { display: flex; }

.modal-card {
    width: min(440px, 100%);
    background: linear-gradient(180deg, #1c1715 0%, #14110f 100%);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 24px;
}

.modal-card h3 {
    margin: 0 0 12px;
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 400;
}

.modal-card input[type="text"] {
    width: 100%;
    border: 1px solid var(--line-strong);
    background: #0d0b0b;
    color: var(--ink);
    border-radius: 10px;
    padding: 11px 12px;
    font-size: 14px;
    font-family: var(--font-ui);
}

.modal-card input[type="text"]:focus {
    outline: none;
    border-color: rgba(212, 175, 55, 0.5);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.confirm-message {
    margin: 0 0 14px;
    font-size: 14px;
    line-height: 1.62;
    color: #cdc0c2;
}
.confirm-message:empty { display: none; }

.ghost-btn.danger-btn,
.primary-btn.danger-btn {
    background: #61171e;
    color: #ffd9d9;
    border: 1px solid #8c2b2b;
    box-shadow: none;
}

.ghost-btn.danger-btn:hover,
.primary-btn.danger-btn:hover {
    background: #7f1d1d;
    color: #ffffff;
    border-color: #a54444;
}

.search-results {
    margin: 0 14px 8px;
    background: #171112;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}

.search-hit {
    display: block;
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: #171112;
    color: var(--ink);
    text-align: left;
    padding: 11px 13px;
    cursor: pointer;
    font-family: var(--font-ui);
}

.search-hit:hover { background: #241818; }
.search-hit strong { display: block; font-size: 13px; font-weight: 600; }
.search-hit em { display: block; font-size: 12px; color: var(--muted); font-style: normal; margin-top: 3px; }

.tree-item input.rename-input {
    flex: 1;
    min-width: 0;
    border: 1px solid rgba(212, 175, 55, 0.45);
    background: #0d0b0b;
    color: var(--ink);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 13px;
    font-family: var(--font-ui);
}

/* ── Tables ────────────────────────────────────────────────────────── */

.ql-editor table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 18px 0 28px !important;
    font-size: 14.5px !important;
    font-family: var(--font-ui) !important;
    border: 1px solid var(--line-strong) !important;
    border-radius: 10px !important;
    overflow: visible !important;
    table-layout: auto !important;
    background: rgba(255, 255, 255, 0.015);
}

.ql-editor table tr:first-child td,
.ql-editor table tr:first-child th {
    padding: 11px 14px !important;
    font-weight: 650 !important;
    font-size: 13px !important;
    letter-spacing: 0.01em !important;
    text-transform: none;
    border-bottom: 1px solid var(--line-strong) !important;
    background: rgba(212, 175, 55, 0.07) !important;
    white-space: normal !important;
    vertical-align: middle !important;
    cursor: text;
}

.ql-editor table tr:first-child td:focus-within,
.ql-editor table tr:first-child th:focus-within {
    background: rgba(212, 175, 55, 0.16) !important;
    box-shadow: inset 0 0 0 1px rgba(212, 175, 55, 0.55);
}

.ql-editor table tr:first-child td:not([style*="color"]),
.ql-editor table tr:first-child th:not([style*="color"]) {
    color: #f3e6c0 !important;
}

.ql-editor table tr:first-child td span,
.ql-editor table tr:first-child th span {
    font-weight: 650 !important;
}

.ql-editor table tbody tr:not(:first-child) td {
    padding: 10px 14px !important;
    border-bottom: 1px solid var(--line) !important;
    vertical-align: top !important;
    line-height: 1.5 !important;
}

.ql-editor table tbody tr:not(:first-child) td:not([style*="color"]),
.ql-editor table tbody tr:not(:first-child) th:not([style*="color"]) {
    color: var(--ink) !important;
}

.ql-editor table tbody tr:last-child td { border-bottom: none !important; }
.ql-editor table td,
.ql-editor table th {
    display: table-cell !important;
    min-width: 5.5rem;
    min-height: 2.25em;
}
.ql-editor table tr { display: table-row !important; }

#table-chrome {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 40;
}

#table-chrome[hidden] { display: none !important; }

.table-chrome-bar,
.table-edge,
.table-axis-btn {
    pointer-events: auto;
    position: fixed;
}

.table-axis-btn {
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--line-strong);
    background: #171211;
    color: var(--danger);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-soft);
}

.table-axis-btn:hover {
    background: var(--danger);
    color: #1a1208;
    border-color: var(--danger);
}

.table-chrome-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    background: #171211;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    box-shadow: var(--shadow-soft);
}

.table-chrome-bar button {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 6px 8px;
    border-radius: 7px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.table-chrome-bar button:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.table-chrome-bar button.danger:hover {
    background: rgba(248, 113, 113, 0.14);
    color: var(--danger);
}

.table-chrome-sep {
    width: 1px;
    height: 18px;
    background: var(--line);
    margin: 0 2px;
}

.table-edge {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--line-strong);
    background: #171211;
    color: var(--accent);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
}

.table-edge:hover {
    background: var(--accent);
    color: #1a1208;
    border-color: var(--accent);
}

.table-designer-card { width: min(520px, 100%); }

.table-designer-lead {
    margin: -4px 0 16px;
    font-size: 13px;
    color: var(--muted);
}

.table-size-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.table-size-meta label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

.table-size-meta input[type="number"] {
    width: 64px;
    border: 1px solid var(--line-strong);
    background: #0d0b0b;
    color: var(--ink);
    border-radius: 8px;
    padding: 7px 8px;
    font-size: 13px;
    font-family: var(--font-ui);
}

.table-size-label {
    margin-left: auto;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}

.table-size-grid {
    display: grid;
    grid-template-columns: repeat(8, 22px);
    gap: 4px;
    margin: 0 0 18px;
}

.table-size-cell {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--line-strong);
    background: #0d0b0b;
    border-radius: 4px;
    cursor: pointer;
}

.table-size-cell.is-on {
    background: rgba(212, 175, 55, 0.28);
    border-color: rgba(212, 175, 55, 0.7);
}

.table-header-fields label {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

#table-header-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    max-height: 180px;
    overflow: auto;
}

#table-header-inputs input {
    width: 100%;
    border: 1px solid var(--line-strong);
    background: #0d0b0b;
    color: var(--ink);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: var(--font-ui);
}

#table-header-inputs input:focus {
    outline: none;
    border-color: rgba(212, 175, 55, 0.5);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

@media print {
    html, body, .app-frame { height: auto; overflow: visible; }
    body.app-shell { background: #fff; color: #111; overflow: visible; }
    .top-chrome, .sidebar, .page-meta .meta-right, .ql-toolbar, .toolbar-extras,
    #table-chrome, #table-designer { display: none !important; }
    .workspace { display: block; background: #fff; overflow: visible; }
    .canvas { padding: 0; background: #fff; overflow: visible; height: auto; }
    .editor-stage { width: 100%; }
    .paper-wrap { box-shadow: none; background: #fff; }
    .ql-container.ql-snow, .ql-editor { overflow: visible !important; height: auto !important; }
    .ql-editor { padding: 0 !important; background: none !important; color: #111; }
    #page-title { font-size: 32px; margin-bottom: 16px; color: #111; }
}

#toggle-sidebar { display: none; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(5, 3, 3, 0.6);
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-backdrop::before {
    content: "";
    position: absolute;
    inset: 0;
}

.sidebar-close { display: none; }

@media (max-width: 900px) {
    .workspace {
        grid-template-columns: 1fr;
        position: relative;
    }
    #toggle-sidebar { display: inline-flex; }
    .chrome-btn span { display: none; }
    .sidebar { display: none; }
    .sidebar.mobile-open {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        right: auto;
        z-index: 51;
        width: min(320px, 86vw);
        box-shadow: 16px 0 40px rgba(0, 0, 0, 0.45);
    }
    .sidebar-backdrop.open { display: block !important; }
    body.sidebar-open .canvas,
    body.sidebar-open .ql-editor { pointer-events: none; }
    .sidebar-close { display: inline-flex; }
    .canvas { padding: 0; }
    .ql-editor { padding: 20px 16px 60vh !important; }
    .ql-editor.ql-blank::before { left: 16px; right: 16px; top: 20px; }
    .page-meta { flex-direction: column; gap: 10px; padding: 12px 16px 10px; }
    .meta-right { align-items: flex-start; width: 100%; flex-direction: row; flex-wrap: wrap; }
    .binder-tab { min-width: 108px; height: 32px; font-size: 12.5px; }
    #page-title { font-size: 30px; }
}

@media (max-width: 640px) {
    .login-card { padding: 28px 20px 22px; }
    .login-card h1 { font-size: 30px; }
    .brand-sub { display: none; }
    .app-switch-btn i { display: none; }
    .app-switch-btn,
    a.app-switch-btn { padding: 0 9px; }
}
