/* ── CSS Variables ──────────────────────────────────────────────── */
:root {
    --color-bg:           #ffffff;
    --color-bg-secondary: #f4f4f5;
    --color-bg-hover:     #f0f0f1;
    --color-sidebar:      #18181b;
    --color-sidebar-text: #e4e4e7;
    --color-sidebar-muted:#a1a1aa;
    --color-sidebar-hover:#27272a;
    --color-accent:       #6366f1;
    --color-accent-hover: #4f46e5;
    --color-accent-light: #eef2ff;
    --color-text:         #18181b;
    --color-text-muted:   #71717a;
    --color-border:       #e4e4e7;
    --color-danger:       #ef4444;
    --color-success:      #22c55e;
    --color-warning:      #f59e0b;
    --color-shadow:       rgba(0,0,0,0.08);

    --sidebar-width:    240px;
    --list-panel-width: 300px;
    --radius:           8px;
    --radius-lg:        12px;
    --transition:       150ms ease;
    --font:             'Inter', system-ui, sans-serif;
}

[data-theme="dark"] {
    --color-bg:           #09090b;
    --color-bg-secondary: #18181b;
    --color-bg-hover:     #27272a;
    --color-sidebar:      #09090b;
    --color-sidebar-text: #e4e4e7;
    --color-sidebar-muted:#71717a;
    --color-sidebar-hover:#18181b;
    --color-text:         #fafafa;
    --color-text-muted:   #a1a1aa;
    --color-border:       #27272a;
    --color-shadow:       rgba(0,0,0,0.3);
    --color-accent-light: #1e1b4b;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    height: 100%;
    overflow: hidden;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, textarea, select { font: inherit; }
ul, ol { list-style: none; }

/* ── Layout ──────────────────────────────────────────────────────── */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}
.main-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
}
.view {
    display: flex;
    height: 100%;
    overflow: hidden;
}
.hidden { display: none !important; }

/* ── List / Detail panels ────────────────────────────────────────── */
.list-panel {
    width: var(--list-panel-width);
    min-width: var(--list-panel-width);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-bg-secondary);
}
.list-panel-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.list-panel-header h2 {
    font-size: 16px;
    font-weight: 600;
}
.list-panel-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.detail-panel {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.detail-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    gap: 12px;
}
.detail-empty i { width: 48px; height: 48px; opacity: 0.3; }
.item-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition), opacity var(--transition);
    white-space: nowrap;
}
.btn-primary {
    background: var(--color-accent);
    color: #fff;
}
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}
.btn-ghost:hover, .btn-ghost.active {
    background: var(--color-bg-hover);
    color: var(--color-text);
}
.btn-danger {
    background: var(--color-danger);
    color: #fff;
}
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    color: var(--color-text-muted);
    transition: background var(--transition), color var(--transition);
}
.icon-btn:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}
.icon-btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    color: var(--color-text-muted);
    font-size: 12px;
}
.icon-btn-sm:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}
.icon-btn i, .icon-btn-sm i { width: 16px; height: 16px; }

/* ── Form elements ───────────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 14px;
}
.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
}
.form-group input,
.form-group textarea,
.form-group select {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.select-sm {
    padding: 4px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 12px;
    outline: none;
    cursor: pointer;
}

/* ── Auth screen ─────────────────────────────────────────────────── */
.auth-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-secondary);
    z-index: 1000;
}
.auth-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 4px 24px var(--color-shadow);
}
.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 700;
    color: var(--color-accent);
    margin-bottom: 32px;
    justify-content: center;
}
.auth-logo i { width: 28px; height: 28px; }
.auth-form h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}
.auth-subtitle {
    color: var(--color-text-muted);
    margin-bottom: 24px;
    font-size: 13px;
}
.auth-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: var(--radius);
    padding: 8px 12px;
    color: var(--color-danger);
    font-size: 13px;
    margin-bottom: 14px;
}
[data-theme="dark"] .auth-error {
    background: #450a0a;
    border-color: #7f1d1d;
}
.auth-switch {
    text-align: center;
    font-size: 13px;
    color: var(--color-text-muted);
    margin-top: 16px;
}
.auth-switch a {
    color: var(--color-accent);
    font-weight: 500;
}
.auth-switch a:hover { text-decoration: underline; }

/* ── Modals ──────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: 20px;
    backdrop-filter: blur(2px);
}
.modal {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 16px 48px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modal-in 150ms ease;
}
@keyframes modal-in {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

/* ── Toasts ──────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9999;
}
.toast {
    background: var(--color-text);
    color: var(--color-bg);
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: toast-in 200ms ease;
    max-width: 300px;
}
.toast.toast-error {
    background: var(--color-danger);
    color: #fff;
}
.toast.toast-success {
    background: var(--color-success);
    color: #fff;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Search overlay ──────────────────────────────────────────────── */
.search-overlay {
    position: fixed;
    inset: 0;
    z-index: 800;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 80px;
}
.search-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
}
.search-modal {
    position: relative;
    z-index: 1;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.2);
    overflow: hidden;
}
.search-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border);
}
.search-input-wrap i { color: var(--color-text-muted); width: 18px; height: 18px; flex-shrink: 0; }
.search-input-wrap input {
    flex: 1;
    font-size: 16px;
    border: none;
    outline: none;
    background: transparent;
    color: var(--color-text);
}
.search-esc {
    font-size: 11px;
    padding: 2px 6px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-muted);
    background: var(--color-bg-secondary);
}
.search-results {
    max-height: 400px;
    overflow-y: auto;
    padding: 8px;
}
.search-result-group { margin-bottom: 12px; }
.search-result-group-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    padding: 4px 8px;
}
.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}
.search-result-item:hover, .search-result-item.active {
    background: var(--color-bg-hover);
}
.search-result-item i { width: 16px; height: 16px; color: var(--color-text-muted); flex-shrink: 0; }
.search-result-title { font-weight: 500; font-size: 13px; }
.search-result-snippet { font-size: 12px; color: var(--color-text-muted); }
.search-empty {
    padding: 32px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 13px;
}

/* ── Tags ────────────────────────────────────────────────────────── */
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 500;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    cursor: pointer;
    white-space: nowrap;
}
.tag-chip .tag-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

/* ── Scrollbar styling ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ── Kbd ──────────────────────────────────────────────────────────── */
kbd {
    font-size: 11px;
    padding: 1px 5px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-bg-secondary);
    color: var(--color-text-muted);
    font-family: monospace;
}

/* ── Color picker dots ───────────────────────────────────────────── */
.color-picker {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.color-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform var(--transition), border-color var(--transition);
}
.color-dot:hover, .color-dot.active {
    transform: scale(1.2);
    border-color: var(--color-text);
}

/* ── Upload progress bar ─────────────────────────────────────────── */
.upload-progress {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 300px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 12px 14px;
    box-shadow: 0 4px 20px var(--color-shadow);
    z-index: 9000;
    font-size: 12px;
    animation: toast-in 200ms ease;
}
.upload-progress-name {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text);
}
.upload-progress-track {
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    overflow: hidden;
}
.upload-progress-fill {
    height: 100%;
    background: var(--color-accent);
    border-radius: 2px;
    transition: width 0.1s linear;
}
.upload-progress-info {
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
    color: var(--color-text-muted);
}

/* ── Mobile-only elements (invisible on desktop) ─────────────────── */
.mobile-header,
.mobile-bottom-nav { display: none; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 190;
}
.sidebar-overlay.active { display: block; }

/* ── Compact icon sidebar (tablet 821px–1100px) ──────────────────── */
@media (max-width: 1100px) and (min-width: 821px) {
    :root { --sidebar-width: 54px; --list-panel-width: 260px; }
}

/* ── Responsive (mobile ≤ 820px) ─────────────────────────────────── */
@media (max-width: 820px) {
    /* Base font bump so nothing needs zooming */
    body { font-size: 15px; }

    /* ── App shell ── */
    html, body { overflow-x: hidden; }
    .app-layout { position: relative; }

    /* Sidebar: completely off-layout; becomes a slide-in drawer.
       !important needed because sidebar.css loads after app.css and
       its .sidebar { display: flex } would otherwise win. */
    .sidebar {
        display: none !important;
        position: fixed;
        top: 0; bottom: 0; left: 0;
        width: min(300px, 88vw);
        z-index: 200;
    }
    .sidebar.open { display: flex !important; }

    /* Main takes full width */
    .main-content {
        width: 100vw;
        max-width: 100vw;
        overflow-x: hidden;
        padding-bottom: 56px; /* room for bottom nav */
    }

    /* ── Mobile header ── */
    .mobile-header {
        display: flex;
        align-items: center;
        height: 54px;
        padding: 0 8px;
        gap: 4px;
        border-bottom: 1px solid var(--color-border);
        background: var(--color-bg);
        flex-shrink: 0;
        position: relative;
        z-index: 180; /* stays above detail-panel overlays */
    }
    .mobile-title {
        flex: 1;
        font-size: 17px;
        font-weight: 600;
        padding: 0 8px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .mobile-header .icon-btn {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
    }

    /* ── Bottom nav ── */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 56px;
        background: var(--color-bg);
        border-top: 1px solid var(--color-border);
        z-index: 150;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        color: var(--color-text-muted);
        border: none;
        background: none;
        font-family: var(--font);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: color var(--transition);
    }
    .mobile-nav-item i { width: 22px; height: 22px; flex-shrink: 0; }
    .mobile-nav-item span { font-size: 10px; font-weight: 500; line-height: 1; }
    .mobile-nav-item.active { color: var(--color-accent); }

    /* ── Views: single-column, full-width ── */
    .view {
        flex-direction: column;
        width: 100vw;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* ── Notes view ── */
    .nb-panel {
        width: 100% !important;
        min-width: 0 !important;
        border-right: none;
    }
    /* Hide the notebook tree; keep notes list */
    .nb-panel-header, .nb-tree { display: none; }
    .nb-notes-subpanel { border-top: none; }

    /* Note editor: fixed fullscreen overlay sitting below the mobile header */
    .detail-panel { display: none; }
    .detail-panel.active {
        display: flex;
        position: fixed;
        top: 54px; bottom: 56px; left: 0; right: 0;
        z-index: 160;
        background: var(--color-bg);
        overflow-y: auto;
    }

    /* ── Todos view ── */
    .todos-sidebar {
        width: 100% !important;
        min-width: 0 !important;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        height: auto;
        flex-shrink: 0;
    }
    .todos-sidebar .list-panel-header,
    .todos-sidebar .sidebar-section-header { display: none; }
    .todo-smart-lists,
    .custom-lists {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        padding: 8px;
        gap: 6px;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .todo-smart-lists::-webkit-scrollbar,
    .custom-lists::-webkit-scrollbar { display: none; }
    .custom-lists { padding-top: 0; }
    .todo-list-item, .custom-list-item {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 7px 14px;
        border-radius: 99px;
        border: 1px solid var(--color-border);
        margin-bottom: 0;
        font-size: 13px;
    }
    .todo-list-item i { width: 14px; height: 14px; }
    .todo-list-item.active { border-color: var(--color-accent); background: var(--color-accent-light); }
    .todo-main { flex: 1; min-width: 0; }

    /* Todo detail: fixed fullscreen overlay sitting below the mobile header */
    .todo-detail-panel {
        position: fixed;
        top: 54px; bottom: 56px; left: 0; right: 0;
        z-index: 160;
        background: var(--color-bg);
        overflow-y: auto;
    }

    /* ── Files view ── */
    .files-sidebar { display: none; }
    .files-main { flex: 1; min-width: 0; }
    #files-detail { display: none !important; }

    /* ── Touch targets: minimum 44 px ── */
    .btn         { min-height: 44px; padding: 10px 16px; font-size: 14px; }
    .btn-sm      { min-height: 38px; padding: 8px 14px; font-size: 13px; }
    .icon-btn    { width: 44px; height: 44px; }
    .icon-btn-sm { width: 36px; height: 36px; }
    .note-card   { padding: 14px; margin-bottom: 6px; }
    .note-card-title  { font-size: 15px; }
    .note-card-preview { font-size: 13px; }
    .todo-item   { min-height: 52px; padding: 10px 12px; }
    .todo-title  { font-size: 15px; }
    .nav-item    { padding: 12px 14px; font-size: 14px; }
    .tag-list-item { padding: 10px 10px; font-size: 13px; }

    /* ── Auth: bottom sheet ── */
    .auth-screen { align-items: flex-end; }
    .auth-card {
        max-width: 100%;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-left: none; border-right: none; border-bottom: none;
        padding: 32px 24px;
    }

    /* ── Modals: bottom sheet ── */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal {
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 90vh;
        animation: modal-slide-up 200ms ease;
    }
    @keyframes modal-slide-up {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }

    /* ── Calendar ── */
    .calendar-toolbar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
    .calendar-title   { font-size: 15px; }
    .calendar-view-btns .btn { min-height: 36px; padding: 6px 10px; }

    /* ── Toasts above bottom nav ── */
    .toast-container { bottom: 68px; }

    /* ── Quill editor comfortable on mobile ── */
    .note-quill-area .ql-editor { padding: 16px; font-size: 15px; }
    .note-title-input { font-size: 18px; }

    /* ── Search modal full-width ── */
    .search-overlay { padding-top: 0; align-items: flex-start; }
    .search-modal { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
    .search-input-wrap input { font-size: 16px; }
}

/* ── Drag & Drop ────────────────────────────────────────────────── */
[draggable="true"] { cursor: grab; }
[draggable="true"]:active { cursor: grabbing; }

.dnd-dragging {
    opacity: 0.4;
    cursor: grabbing !important;
}

.dnd-insert-above {
    box-shadow: 0 -2px 0 var(--color-accent);
}

.dnd-insert-below {
    box-shadow: 0 2px 0 var(--color-accent);
}

/* Notebook/section rows highlighted when a note is dragged over them */
.dnd-note-target {
    background: var(--color-accent-light) !important;
    outline: 1px solid var(--color-accent);
    border-radius: var(--radius);
}
