/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:         #f5f5f0;
    --surface:    #ffffff;
    --sidebar-bg: #1a1a2e;
    --sidebar-fg: #c8c8d4;
    --sidebar-hover: rgba(255,255,255,.07);
    --sidebar-active: rgba(255,255,255,.14);
    --accent:     #00b96b;
    --accent-dark:#009958;
    --danger:     #e53935;
    --text:       #1c1c1e;
    --muted:      #8e8e93;
    --border:     #e0e0e0;
    --radius:     8px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); }

/* ── Auth pages ───────────────────────────────────────────────────────── */
.auth-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: var(--bg);
}
.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0,0,0,.10);
    padding: 2.5rem;
    width: 100%; max-width: 400px;
}
.auth-logo { font-size: 1.5rem; font-weight: 700; margin-bottom: .5rem; display: block; }
.auth-card h1 { font-size: 1.4rem; margin-bottom: 1.5rem; color: var(--text); }
.auth-footer { margin-top: 1.25rem; font-size: .9rem; color: var(--muted); text-align: center; }
.auth-footer a { color: var(--accent); text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }
.hint { font-size: .78rem; color: var(--muted); font-weight: 400; }

/* ── Forms ────────────────────────────────────────────────────────────── */
label {
    display: flex; flex-direction: column; gap: .35rem;
    font-size: .85rem; font-weight: 600; color: var(--text);
    margin-bottom: 1rem;
}
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
    padding: .6rem .75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: .95rem; font-family: var(--font);
    background: var(--bg); color: var(--text);
    transition: border-color .15s;
    width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,185,107,.15);
}
textarea { resize: vertical; min-height: 80px; }
.modal-lg { min-width: min(480px, calc(100vw - 2rem)); }
.modal textarea { min-height: 100px; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: .55rem 1.1rem; border-radius: var(--radius);
    font-size: .9rem; font-weight: 600; font-family: var(--font);
    cursor: pointer; border: 1.5px solid var(--border);
    background: var(--surface); color: var(--text);
    transition: background .15s, border-color .15s;
    text-decoration: none;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-full { width: 100%; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-icon {
    background: none; border: none; cursor: pointer; font-size: 1rem;
    color: var(--sidebar-fg); padding: .2rem .4rem; border-radius: 4px;
    line-height: 1;
}
.btn-icon:hover { background: var(--sidebar-hover); }

/* ── Alerts ───────────────────────────────────────────────────────────── */
.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-error   { background: #fdecea; color: #b71c1c; border: 1px solid #ef9a9a; }
.alert-success { background: #e8f5e9; color: #1b5e20; border: 1px solid #a5d6a7; }

/* ── App layout (3-pane) ─────────────────────────────────────────────── */
body.app {
    display: grid;
    grid-template-columns: 220px 280px 1fr;
    grid-template-rows: 100vh;
    overflow: hidden;
}

/* Panel collapse */
body.app {
    transition: grid-template-columns .3s cubic-bezier(.4, 0, .2, 1);
}
body.app.sidebar-collapsed               { grid-template-columns: 0 280px 1fr; }
body.app.notes-collapsed                 { grid-template-columns: 220px 0 1fr; }
body.app.sidebar-collapsed.notes-collapsed { grid-template-columns: 0 0 1fr; }

.sidebar   { overflow-x: hidden; transition: opacity .25s ease; }
.notes-list { overflow-x: hidden; transition: opacity .25s ease; }
body.app.sidebar-collapsed .sidebar,
body.app.notes-collapsed .notes-list { opacity: 0; pointer-events: none; }

/* Toggle buttons — fixed so they're never clipped by collapsing panels */
.col-toggle-btn {
    position: fixed; top: 50%; transform: translateY(-50%);
    border-left: none; border-radius: 0 6px 6px 0;
    width: 14px; height: 48px; padding: 0;
    cursor: pointer; z-index: 99;
    display: flex; align-items: center; justify-content: center;
    transition: left .3s cubic-bezier(.4,0,.2,1),
                top  .3s cubic-bezier(.4,0,.2,1),
                transform .3s cubic-bezier(.4,0,.2,1),
                background .15s, color .15s, border-color .15s;
}
.col-toggle-btn .arrow {
    font-size: .55rem; display: inline-block;
    transition: transform .3s cubic-bezier(.4,0,.2,1);
}

/* Sidebar toggle — dark blue, sits at sidebar/notes boundary */
#toggle-sidebar-btn {
    left: 220px;
    background: var(--sidebar-bg); color: rgba(255,255,255,.45);
    border: 1px solid rgba(255,255,255,.12); border-left: none;
}
#toggle-sidebar-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
body.app.sidebar-collapsed #toggle-sidebar-btn { left: 0; }
body.app.sidebar-collapsed #toggle-sidebar-btn .arrow { transform: rotate(180deg); }

/* Notes toggle — light, sits at notes/editor boundary */
#toggle-notes-btn {
    left: 500px;
    background: var(--bg); color: var(--muted);
    border: 1px solid var(--border); border-left: none;
}
#toggle-notes-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
body.app.sidebar-collapsed #toggle-notes-btn { left: 280px; }
body.app.notes-collapsed   #toggle-notes-btn { left: 220px; }
body.app.notes-collapsed   #toggle-notes-btn .arrow { transform: rotate(180deg); }

/* Both collapsed — stack vertically at top-left */
body.app.sidebar-collapsed.notes-collapsed #toggle-sidebar-btn { left: 0; top: 1rem;           transform: translateY(0); }
body.app.sidebar-collapsed.notes-collapsed #toggle-notes-btn   { left: 0; top: calc(1rem + 56px); transform: translateY(0); }
body.app.sidebar-collapsed.notes-collapsed #toggle-notes-btn .arrow { transform: rotate(180deg); }

@media (max-width: 768px) { .col-toggle-btn { display: none; } }

/* Sidebar */
.sidebar {
    background: var(--sidebar-bg); color: var(--sidebar-fg);
    display: flex; flex-direction: column;
    overflow-y: auto;
}
.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1rem .75rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.app-logo { font-size: 1.1rem; font-weight: 700; color: #fff; }
.sidebar-search { padding: .75rem 1rem; }
.sidebar-search input {
    background: rgba(255,255,255,.08); border: none; color: #fff;
    border-radius: 20px; padding: .4rem .85rem; font-size: .85rem;
}
.sidebar-search input::placeholder { color: rgba(255,255,255,.4); }
.sidebar-search input:focus { background: rgba(255,255,255,.14); box-shadow: none; }
.sidebar-section { flex: 1; padding: .5rem 0; }
.sidebar-label {
    display: flex; align-items: center; justify-content: space-between;
    padding: .3rem 1rem .3rem 1.1rem;
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .08em; color: rgba(255,255,255,.35);
}
.notebook-list { list-style: none; }
.notebook-item {
    display: flex; align-items: center; gap: .5rem;
    padding: .45rem 1rem; cursor: pointer; font-size: .88rem;
    border-radius: 6px; margin: 0 .5rem;
    transition: background .12s;
    position: relative;
}
.notebook-item:hover { background: var(--sidebar-hover); }
.notebook-item.active { background: var(--sidebar-active); color: #fff; }
.nb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-delete-notebook, .btn-rename-notebook {
    opacity: 0; font-size: .85rem; color: rgba(255,255,255,.5);
    max-width: 0; overflow: hidden;
    transition: opacity .15s, max-width .15s;
}
.notebook-item:hover .btn-delete-notebook,
.notebook-item:hover .btn-rename-notebook { opacity: 1; max-width: 1.5rem; }
.sidebar-footer {
    padding: .65rem 1rem;
    font-size: .8rem; color: rgba(255,255,255,.35);
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex; flex-direction: column; gap: .35rem;
}
.sidebar-user-info {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
#sidebar-username { color: rgba(255,255,255,.55); font-size: .82rem; }
.session-timer {
    font-size: .75rem; font-variant-numeric: tabular-nums;
    color: rgba(255,255,255,.35); letter-spacing: .03em;
}
.session-timer-warn { color: #ff8a65 !important; }
.sidebar-user-actions {
    display: flex; gap: .4rem;
}
.sidebar-action-btn {
    flex: 1; display: flex; align-items: center; justify-content: center;
    gap: .3rem; padding: .32rem .5rem;
    border-radius: 6px; border: 1px solid rgba(255,255,255,.12);
    background: rgba(255,255,255,.05); color: rgba(255,255,255,.5);
    font-family: var(--font); font-size: .78rem; font-weight: 500;
    cursor: pointer; text-decoration: none;
    transition: background .15s, color .15s, border-color .15s;
}
.sidebar-action-btn:hover {
    background: rgba(255,255,255,.11); color: #fff;
    border-color: rgba(255,255,255,.22);
}
.sidebar-action-btn--danger:hover {
    background: rgba(229,57,53,.25); color: #ff8a80;
    border-color: rgba(229,57,53,.4);
}
.modal hr { border: none; border-top: 1px solid rgba(0,0,0,.1); margin: 1rem 0; }
.profile-name-row { display: flex; gap: .5rem; }
.profile-name-row input { flex: 1; }
.modal h3 { font-size: .95rem; margin: 0 0 .75rem; color: var(--text); }

/* Notes list */
.notes-list {
    background: #f0ede8;
    display: flex; flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}
.notes-list-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1rem .75rem;
    font-weight: 700; font-size: .9rem;
    border-bottom: 1px solid var(--border);
    background: #f0ede8;
    flex-shrink: 0;
}
#note-items {
    list-style: none; overflow-y: auto; flex: 1;
}
.note-item {
    padding: .85rem 1rem; cursor: pointer;
    border-bottom: 1px solid rgba(0,0,0,.06);
    transition: background .1s;
}
.note-item-ghost { opacity: .35; background: rgba(0,0,0,.04); }
.note-item-drag  { box-shadow: 0 4px 16px rgba(0,0,0,.12); background: #fff; opacity: 1 !important; }
.note-item:hover { background: rgba(0,0,0,.04); }
.note-item.active { background: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.note-item-title {
    font-weight: 600; font-size: .88rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.note-item-meta { font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.no-notes { padding: 2rem 1rem; text-align: center; color: var(--muted); font-size: .88rem; }

/* Editor pane */
.editor-pane {
    background: var(--surface);
    display: flex; flex-direction: column;
    overflow: hidden; position: relative;
}
.editor-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; gap: 1rem; color: var(--muted);
}
.editor-content { display: flex; flex-direction: column; height: 100%; }
.editor-toolbar {
    padding: .75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: .5rem;
    flex-shrink: 0;
}
.note-title-input {
    font-size: 1.3rem; font-weight: 700; border: none; background: transparent;
    color: var(--text); width: 100%; padding: 0;
}
.note-title-input:focus { outline: none; box-shadow: none; border: none; }
.editor-meta {
    display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.notebook-select {
    font-size: .8rem; padding: .25rem .5rem;
    border-radius: 20px; border-color: var(--border);
    background: var(--bg); color: var(--muted);
    width: auto;
}
.btn-save {
    font-size: .78rem; padding: .25rem .65rem; border-radius: 20px; margin-left: auto;
    background: var(--surface); border-color: var(--border); color: var(--muted);
    cursor: default; pointer-events: none;
}
.btn-save.dirty {
    background: var(--accent); border-color: var(--accent); color: #fff;
    cursor: pointer; pointer-events: auto;
}
.btn-save.dirty:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-save.error {
    background: transparent; border-color: var(--danger); color: var(--danger);
    cursor: pointer; pointer-events: auto;
}

/* Quill overrides */
#quill-editor { flex: 1; overflow-y: auto; }
.ql-container { font-size: .95rem; font-family: var(--font); border: none !important; }
.ql-toolbar { border: none !important; border-bottom: 1px solid var(--border) !important; }
.ql-editor { min-height: 300px; padding: 1.25rem 1.5rem; }

/* ── Code block (Quill 1.3.7 uses pre.ql-syntax) ─────────────────────────── */
.ql-editor pre.ql-syntax {
    border-radius: var(--radius);
    margin: .75rem 0;
    font-family: 'Menlo', 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: .87rem;
    line-height: 1.6;
    padding: .75rem 1.25rem;
    overflow-x: auto;
}

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
    background: var(--surface); border-radius: var(--radius);
    padding: 1.75rem 2rem; min-width: 320px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.modal h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.modal input { margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: .75rem; justify-content: flex-end; }

/* ── Utility ──────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.mobile-only { display: none !important; }

/* ── Editor title row (back btn + title input) ───────────────────────── */
.editor-title-row { display: flex; align-items: center; gap: .5rem; }
.note-title-input { flex: 1; min-width: 0; }

/* Icon buttons on light backgrounds (notes list, editor) */
.notes-list-header .btn-icon,
.editor-toolbar .btn-icon {
    color: var(--muted);
}
.notes-list-header .btn-icon:hover,
.editor-toolbar .btn-icon:hover {
    background: rgba(0,0,0,.06);
    color: var(--text);
}

/* ── Encrypted block ─────────────────────────────────────────────────────── */
.ql-editor .enc-block {
    border-radius: 3px;
    margin: .1rem 0;
    cursor: default;
    font-size: .95rem; line-height: 1.6;
}

/* Locked: looks like a normal dim line with a lock */
.enc-locked {
    display: flex; align-items: center; gap: .45rem;
    padding: .15rem .35rem;
    background: rgba(200, 200, 240, 0.18);
    color: var(--muted); font-style: italic;
}
.enc-lock-icon   { font-style: normal; font-size: .9rem; }
.enc-locked-label { flex: 1; font-size: .9rem; }
.enc-decrypt-btn { font-style: normal; }

/* Unlocked: editable text with subtle green left border */
.enc-unlocked {
    padding: .25rem .5rem .25rem .75rem;
    background: rgba(0, 185, 107, 0.06);
    border-left: 2px solid var(--accent);
}
.enc-plaintext {
    font-family: var(--font); font-size: .95rem; line-height: 1.6;
    color: var(--text); min-height: 1.6em;
    white-space: pre-wrap; word-break: break-word; cursor: text;
}
.enc-plaintext:focus { outline: none; }
.enc-unlocked-controls {
    margin-top: .3rem;
    display: flex; gap: .4rem;
}

/* Encrypt/decrypt modal helpers */
.enc-modal-note { font-size: .85rem; color: var(--muted); margin-bottom: 1rem; }
.enc-modal-hint { font-size: .88rem; color: var(--muted); margin-bottom: .75rem; font-style: italic; }

/* Custom toolbar buttons — Quill Snow handles sizing/colour via .ql-stroke */
.ql-encrypt-btn svg,
.ql-table-btn svg { float: left; height: 100%; }

/* Quill colour-picker: compact swatch size */
.ql-snow .ql-color-picker .ql-picker-options { padding: 4px 6px; width: 192px; }
.ql-snow .ql-color-picker .ql-picker-item   { width: 20px; height: 20px; border-radius: 3px; }

/* Custom table blot */
.ql-editor .ql-table-wrap { margin: .5rem 0; overflow-x: auto; cursor: default; }
.ql-custom-table { border-collapse: collapse; width: 100%; font-size: .93rem; }
.ql-custom-table td {
    border: 1.5px solid var(--border);
    padding: .4rem .65rem; min-width: 80px;
    vertical-align: top; cursor: text;
}
.ql-custom-table td:focus {
    outline: none;
    background: rgba(0,185,107,.06);
    border-color: var(--accent);
}
/* Floating table controls panel */
.ql-table-panel {
    position: fixed; z-index: 500;
    display: none; align-items: center; gap: .3rem;
    padding: .3rem .45rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 3px 14px rgba(0,0,0,.12);
    user-select: none;
}
.ql-table-panel.ql-tp-visible { display: flex; }
.ql-tc-sep { width: 1px; height: 13px; background: var(--border); margin: 0 .1rem; flex-shrink: 0; }
.ql-tc-btn {
    background: none; border: 1px solid transparent; border-radius: 4px;
    padding: .18rem .5rem; font-size: .72rem; font-family: var(--font);
    color: var(--muted); cursor: pointer; line-height: 1.5;
    transition: background .12s, color .12s, border-color .12s;
}
.ql-tc-btn:hover { background: var(--bg); color: var(--text); border-color: var(--border); }
.ql-tc-btn--danger:hover { border-color: var(--danger); color: var(--danger); background: #fdecea; }

/* Insert table modal row/col inputs */
.table-modal-size {
    display: flex; gap: 1rem; margin-bottom: 1.25rem;
}
.table-modal-size label { flex: 1; margin-bottom: 0; }

/* ── Mobile (≤ 768 px) ────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .mobile-only { display: flex !important; }

    /* Auth pages – add breathing room on small screens */
    .auth-page { padding: 1rem; align-items: flex-start; padding-top: 3rem; }
    .auth-card  { padding: 1.5rem; }

    /* 3-pane → single-pane with slide transitions */
    body.app {
        display: block;
        position: relative;
        height: 100vh;
        overflow: hidden;
    }
    .sidebar, .notes-list, .editor-pane {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        transition: transform .25s ease;
    }
    /* default: notes list visible */
    .sidebar     { transform: translateX(-100%); }
    .notes-list  { transform: translateX(0); }
    .editor-pane { transform: translateX(100%); }

    /* show-sidebar state */
    body.app.show-sidebar .sidebar     { transform: translateX(0); }
    body.app.show-sidebar .notes-list  { transform: translateX(100%); }
    body.app.show-sidebar .editor-pane { transform: translateX(200%); }

    /* show-editor state */
    body.app.show-editor .sidebar     { transform: translateX(-200%); }
    body.app.show-editor .notes-list  { transform: translateX(-100%); }
    body.app.show-editor .editor-pane { transform: translateX(0); }

    /* Quill toolbar – scroll horizontally instead of wrapping */
    .ql-toolbar { overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
    .ql-toolbar .ql-formats { display: inline-flex !important; }

    /* Modal – full width with edge margin */
    .modal { min-width: unset; width: calc(100% - 2rem); }
}
