:root {
    --onenote-purple: #8b5cf6;
    --onenote-purple-deep: #3b2466;
    --chrome: #16121f;
    --pane: #1a1624;
    --sidebar: #14111c;
    --paper: #1c1826;
    --line: #2e283c;
    --ink: #ece8f4;
    --muted: #9a93a8;
    --rule: #2a2436;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
    --tab-radius: 10px 10px 0 0;
    --accent: #a78bfa;
    --code-bg: #121018;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
}

body.app-shell {
    font-family: "Segoe UI", "Candara", "Calibri", system-ui, sans-serif;
    color: var(--ink);
    background: var(--chrome);
    overflow: hidden;
}

body.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(900px 420px at 50% -10%, rgba(139, 92, 246, 0.22), transparent 55%),
        var(--chrome);
}

.login-card {
    width: min(400px, calc(100% - 32px));
    background: #1c1828;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 28px 26px 24px;
}

.login-card h1 {
    margin: 16px 0 6px;
    font-size: 26px;
    font-weight: 650;
}

.login-card p {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 13px;
}

.login-card label {
    display: block;
    margin-bottom: 12px;
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.login-card input {
    display: block;
    width: 100%;
    margin-top: 6px;
    border: 1px solid var(--line);
    background: #14111c;
    color: var(--ink);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 15px;
    text-transform: none;
    letter-spacing: 0;
}

.login-card input:focus {
    outline: none;
    border-color: #6d4c9a;
}

.login-card button[type="submit"] {
    width: 100%;
    margin-top: 8px;
    border: 0;
    border-radius: 8px;
    background: #5c2d91;
    color: #fff;
    font-size: 14px;
    font-weight: 650;
    padding: 11px 14px;
    cursor: pointer;
}

.login-card button[type="submit"]:hover { filter: brightness(1.08); }

.login-error {
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: #f87171;
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 14px;
    font-size: 13px;
}

a.ghost-btn {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.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, #2a1d44 0%, #1d1530 100%);
    color: #fff;
    padding: 10px 16px 0;
    box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.06);
    z-index: 5;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 8px;
}

.brand-mark {
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 700;
}

.brand-mark i { font-size: 18px; }

.binder-tabs {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 4px;
    scrollbar-width: thin;
    scrollbar-color: #3d3450 transparent;
}

.binder-tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
    max-width: 220px;
    height: 36px;
    padding: 0 8px 0 14px;
    border: 0;
    border-radius: var(--tab-radius);
    background: color-mix(in srgb, var(--tab-color, #7719aa) 55%, #0e0b14);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.12);
    transform: translateY(4px);
    transition: transform 160ms ease, filter 160ms ease, box-shadow 160ms ease;
    white-space: nowrap;
}

.binder-tab .tab-menu {
    color: inherit;
    width: 22px;
    height: 22px;
    opacity: 0.75;
}

.binder-tab.active .tab-menu { color: var(--muted); }

.binder-tab::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.2);
    flex: 0 0 auto;
}

.binder-tab span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.binder-tab:hover { filter: brightness(1.12); transform: translateY(2px); }

.binder-tab.active {
    background: var(--pane);
    color: var(--ink);
    transform: translateY(1px);
    z-index: 2;
    box-shadow: none;
}

.binder-tab.active::before {
    background: var(--tab-color, var(--accent));
    box-shadow: none;
}

.tab-add {
    height: 32px;
    min-width: auto;
    background: rgba(255,255,255,0.08);
    border: 1px dashed rgba(255,255,255,0.28);
    color: #fff;
    transform: translateY(4px);
}

.tab-add::before { display: none; }

.workspace {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    background: var(--pane);
    overflow: hidden;
}

.sidebar {
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--sidebar);
    border-right: 1px solid var(--line);
    overflow: hidden;
}

.search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 12px 8px;
    flex: 0 0 auto;
}

.search-wrap input {
    width: 100%;
    flex: 1;
    min-width: 0;
    border: 1px solid var(--line);
    background: #1c1828;
    color: var(--ink);
    border-radius: 8px;
    padding: 8px 12px 8px 34px;
    font-size: 13px;
    outline: none;
}

.search-wrap input::placeholder { color: #6f687c; }
.search-wrap input:focus { border-color: #6d4c9a; }

.search-wrap i {
    position: absolute;
    left: 22px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 14px;
}

.tree-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 4px 8px 16px;
    scrollbar-width: thin;
    scrollbar-color: #3d3450 transparent;
}

.tree-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 8px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.icon-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover { background: rgba(167, 139, 250, 0.12); color: var(--accent); }

.tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 7px 8px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--ink);
    font-size: 13.5px;
    position: relative;
}

.tree-item:hover,
.tree-item.active {
    background: #221c30;
    box-shadow: inset 0 0 0 1px var(--line);
}

.tree-item.active {
    box-shadow: inset 3px 0 0 var(--item-color, var(--accent)), inset 0 0 0 1px var(--line);
}

.tree-item .title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.section-swatch {
    width: 10px;
    height: 18px;
    border-radius: 2px;
    flex: 0 0 auto;
}

.page-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6a6278;
    flex: 0 0 auto;
}

.tree-item.pinned .page-dot { background: #e4c36a; box-shadow: 0 0 0 3px rgba(228, 195, 106, 0.15); }

.tree-children { margin-left: 14px; border-left: 1px dashed #3a3348; padding-left: 6px; }

.tree-item.drag-over { outline: 2px dashed var(--onenote-purple); }

.empty-hint {
    padding: 16px 12px;
    color: var(--muted);
    font-size: 13px;
    font-style: italic;
}

.canvas {
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--pane);
    padding: 16px 20px 16px;
    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; }

.page-meta {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
    flex: 0 0 auto;
}

#page-title {
    width: 100%;
    border: 0;
    background: transparent;
    font-size: 28px;
    font-weight: 650;
    color: var(--ink);
    outline: none;
    padding: 0;
}

#page-title::placeholder { color: #6f687c; }

.meta-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex: 0 0 auto;
}

.save-pill {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    background: #221c30;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 10px;
}

.save-pill.saving { color: #f0c14b; }
.save-pill.saved { color: #6ee7a8; }
.save-pill.error { color: #f87171; }

.timestamp { font-size: 12px; color: var(--muted); white-space: nowrap; }

.paper-wrap {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    border-radius: 2px 10px 10px 10px;
    box-shadow: var(--shadow), inset 0 0 0 1px #2c2638;
    overflow: hidden;
    position: relative;
}

.paper-wrap::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 28px;
    background: repeating-linear-gradient(
        180deg,
        transparent 0 18px,
        rgba(220, 80, 80, 0.12) 18px 19px
    );
    border-right: 1px solid #5a3038;
    pointer-events: none;
    z-index: 2;
}

.ql-toolbar.ql-snow {
    border: 0 !important;
    border-bottom: 1px solid var(--line) !important;
    background: #16121f;
    padding-left: 40px !important;
    flex: 0 0 auto;
    z-index: 3;
}

.ql-container.ql-snow {
    border: 0 !important;
    flex: 1 1 auto;
    min-height: 0;
    height: auto !important;
    overflow: hidden;
    font-family: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
    font-size: 16px;
}

.ql-editor {
    height: 100% !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    padding: 28px 48px 48px 56px !important;
    line-height: 1.7;
    color: var(--ink);
    scrollbar-width: thin;
    scrollbar-color: #4a425c transparent;
}

.ql-editor.ql-blank::before {
    color: #6f687c;
    font-style: italic;
}

.paper-lined .ql-editor {
    background-image: repeating-linear-gradient(
        transparent,
        transparent 27px,
        var(--rule) 28px
    );
    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: 24px 24px;
    background-attachment: local;
}

.paper-blank .ql-editor { background-image: none; }

.ql-snow .ql-stroke { stroke: #c8c0d8; }
.ql-snow .ql-fill { fill: #c8c0d8; }
.ql-snow .ql-picker { color: #c8c0d8; }
.ql-snow .ql-picker-options {
    background: #1c1828;
    border-color: var(--line);
    color: var(--ink);
}
.ql-snow .ql-picker-item:hover { color: var(--accent); }
.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 {
    background: #2a2340;
    border-radius: 4px;
}
.ql-snow .ql-tooltip {
    background: #1c1828;
    border-color: var(--line);
    color: var(--ink);
    box-shadow: var(--shadow);
}
.ql-snow .ql-tooltip input[type="text"] {
    background: #14111c;
    color: var(--ink);
    border-color: var(--line);
}
.ql-editor pre.ql-syntax,
.ql-editor pre {
    background: var(--code-bg);
    color: #e8e2f4;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.ql-editor img,
.ql-editor .note-image {
    max-width: 100%;
    height: auto;
    display: inline-block;
    vertical-align: middle;
    border-radius: 4px;
    cursor: grab;
    box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.25);
    -webkit-user-drag: none;
    user-select: none;
    touch-action: none;
}

.ql-editor img.is-selected {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    cursor: grab;
}

.ql-editor img.is-dragging {
    opacity: 0.45;
    cursor: grabbing;
}

.ql-editor .ql-swap-target {
    outline: 1px dashed var(--accent);
    background: rgba(92, 45, 145, 0.14);
}

#img-frame {
    position: fixed;
    z-index: 40;
    pointer-events: auto;
    touch-action: none;
    border: 2px solid var(--accent);
    box-sizing: border-box;
}

#img-frame .img-handle,
#img-frame .img-delete {
    pointer-events: auto;
    touch-action: none;
}

.img-handle {
    position: absolute;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 2px solid #1c1828;
    background: var(--accent);
    border-radius: 4px;
    z-index: 2;
}

.img-handle::after {
    content: '';
    position: absolute;
    inset: -14px;
}

.img-handle[data-handle="nw"] { left: -9px; top: -9px; cursor: nwse-resize; }
.img-handle[data-handle="ne"] { right: -9px; top: -9px; cursor: nesw-resize; }
.img-handle[data-handle="sw"] { left: -9px; bottom: -9px; cursor: nesw-resize; }
.img-handle[data-handle="se"] { right: -9px; bottom: -9px; cursor: nwse-resize; }

.img-delete {
    position: absolute;
    top: -34px;
    right: 0;
    border: 1px solid var(--line);
    background: #1c1828;
    color: #f87171;
    border-radius: 8px;
    width: 30px;
    height: 28px;
    cursor: pointer;
}

.img-delete:hover { background: #2a2340; }

#img-caret {
    position: fixed;
    z-index: 41;
    width: 2px;
    background: var(--accent);
    pointer-events: none;
    box-shadow: 0 0 8px rgba(167, 139, 250, 0.6);
}

.empty-canvas {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-style: italic;
}

.toolbar-extras {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 0;
}

.ghost-btn {
    border: 1px solid var(--line);
    background: #221c30;
    color: var(--ink);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
}

.ghost-btn:hover { border-color: #6d4c9a; color: var(--accent); }

.dropdown { position: relative; display: inline-block; }

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    min-width: 180px;
    background: #1c1828;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 6px;
    z-index: 30;
}

.dropdown-menu.show { display: block; }

.dropdown-item {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 8px 10px;
    border-radius: 7px;
    font-size: 13px;
    color: var(--ink);
    cursor: pointer;
}

.dropdown-item:hover { background: #2a2340; color: var(--accent); }
.dropdown-item.danger { color: #f87171; }

.color-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    padding: 8px;
}

.color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #1c1828;
    box-shadow: 0 0 0 1px #4a425c;
    cursor: pointer;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 6, 14, 0.72);
    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: #1c1828;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.modal-card h3 { margin: 0 0 12px; font-size: 18px; }
.modal-card input[type="text"] {
    width: 100%;
    border: 1px solid var(--line);
    background: #14111c;
    color: var(--ink);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 14px;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.search-results {
    margin: 0 8px 8px;
    background: #1c1828;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}

.search-hit {
    display: block;
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: #1c1828;
    color: var(--ink);
    text-align: left;
    padding: 10px 12px;
    cursor: pointer;
}

.search-hit:hover { background: #2a2340; }
.search-hit strong { display: block; font-size: 13px; }
.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 #6d4c9a;
    background: #14111c;
    color: var(--ink);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 13px;
}


/* ===== QUILL TABLE FORMAT STYLES ===== */
.ql-editor table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 16px 0 !important;
    font-size: 14px !important;
    border: 1px solid var(--line) !important;
    border-radius: 8px !important;
    overflow: hidden !important;
    table-layout: auto !important;
}

/* Quill tables use <td data-row="N"> — style first row as header.
   Do NOT force color with !important — let inline styles on each td win. */
.ql-editor table tbody tr:first-child td {
    padding: 10px 14px !important;
    font-weight: 700 !important;
    font-size: 13px !important;
    letter-spacing: 0.02em !important;
    border-bottom: 2px solid #4a425c !important;
    white-space: nowrap !important;
    vertical-align: middle !important;
}

/* Only set color if no inline color is present */
.ql-editor table tbody tr:first-child td:not([style*="color"]) {
    color: #fff !important;
}

/* Spans inside header cells should inherit color, not be forced white */
.ql-editor table tbody tr:first-child td span {
    font-weight: 700 !important;
}

.ql-editor table tbody tr:not(:first-child) td {
    padding: 8px 14px !important;
    border-bottom: 1px solid var(--line) !important;
    vertical-align: top !important;
    line-height: 1.5 !important;
}

/* Only set default ink color if no inline color is present */
.ql-editor table tbody tr:not(:first-child) td:not([style*="color"]) {
    color: var(--ink) !important;
}

.ql-editor table tbody tr:last-child td {
    border-bottom: none !important;
}

/* Ensure cells display as table-cell */
.ql-editor table td {
    display: table-cell !important;
}

.ql-editor table tr {
    display: table-row !important;
}

@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 { display: none !important; }
    .workspace { display: block; background: #fff; overflow: visible; }
    .canvas { padding: 0; background: #fff; overflow: visible; height: auto; }
    .paper-wrap, .paper-wrap::before { box-shadow: none; background: #fff; }
    .paper-wrap::before { display: none; }
    .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(8, 6, 12, 0.55);
    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; }
    .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; }
}
