:root {
    /* Light Mode */
    --bg-primary: #f8f9fc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f3f9;
    --surface-bg: rgba(255, 255, 255, 0.85);
    --surface-border: rgba(0, 0, 0, 0.06);
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-subtle: rgba(99, 102, 241, 0.08);
    --accent-glow: rgba(99, 102, 241, 0.25);
    --danger: #ef4444;
    --danger-subtle: rgba(239, 68, 68, 0.08);
    --success: #22c55e;
    --success-subtle: rgba(34, 197, 94, 0.1);
    --card-hover: rgba(0, 0, 0, 0.02);
    --card-active: rgba(99, 102, 241, 0.06);
    --card-active-border: rgba(99, 102, 241, 0.3);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.08);
    --modal-bg: rgba(255, 255, 255, 0.98);
    --overlay-bg: rgba(0, 0, 0, 0.4);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

.dark-theme {
    --bg-primary: #0c0c14;
    --bg-secondary: #12121e;
    --bg-tertiary: #1a1a2e;
    --surface-bg: rgba(18, 18, 30, 0.9);
    --surface-border: rgba(255, 255, 255, 0.06);
    --text-primary: #e8e8f0;
    --text-secondary: #8b8b9e;
    --text-tertiary: #5c5c72;
    --accent: #818cf8;
    --accent-hover: #6366f1;
    --accent-subtle: rgba(129, 140, 248, 0.1);
    --accent-glow: rgba(129, 140, 248, 0.2);
    --danger: #f87171;
    --danger-subtle: rgba(248, 113, 113, 0.1);
    --success: #4ade80;
    --success-subtle: rgba(74, 222, 128, 0.1);
    --card-hover: rgba(255, 255, 255, 0.02);
    --card-active: rgba(129, 140, 248, 0.08);
    --card-active-border: rgba(129, 140, 248, 0.3);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --modal-bg: rgba(18, 18, 30, 0.98);
    --overlay-bg: rgba(0, 0, 0, 0.6);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    height: 100vh;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

.hidden { display: none !important; }

/* ── App Container ─────────────────────────────────────── */

.app-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* ── Sidebar ───────────────────────────────────────────── */

.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--surface-border);
    display: flex;
    flex-direction: column;
    padding: 20px;
    position: relative;
    transition: transform 0.3s ease;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.header-actions {
    display: flex;
    gap: 4px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    color: var(--accent);
    width: 22px;
    height: 22px;
}

.logo h1 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ── Collab Bar ────────────────────────────────────────── */

.collab-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--success-subtle);
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

.collab-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--success);
}

.collab-icon {
    width: 14px;
    height: 14px;
}

.collab-count {
    background: var(--success);
    color: var(--bg-primary);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* ── Buttons ───────────────────────────────────────────── */

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--card-hover);
    color: var(--text-primary);
}

.icon-btn.small {
    padding: 4px;
}

.icon-btn.small svg {
    width: 14px;
    height: 14px;
}

.icon-btn.delete:hover {
    color: var(--danger);
    background: var(--danger-subtle);
}

/* ── Search ────────────────────────────────────────────── */

.search-container {
    margin-bottom: 16px;
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    width: 16px;
    color: var(--text-tertiary);
}

#search-input {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    padding: 10px 12px 10px 38px;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    transition: all 0.2s ease;
}

#search-input::placeholder {
    color: var(--text-tertiary);
}

#search-input:focus {
    border-color: var(--accent);
    background: var(--bg-secondary);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* ── Notes List ────────────────────────────────────────── */

.notes-list-container {
    flex: 1;
    overflow-y: auto;
    margin-right: -6px;
    padding-right: 6px;
}

.notes-list-container::-webkit-scrollbar {
    width: 3px;
}

.notes-list-container::-webkit-scrollbar-thumb {
    background: var(--surface-border);
    border-radius: 10px;
}

.note-item {
    background: transparent;
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
}

.note-item:hover {
    background: var(--card-hover);
}

.note-item.active {
    background: var(--card-active);
    border-color: var(--card-active-border);
}

.note-item h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.note-item p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.note-item .note-date {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 6px;
    display: block;
}

/* ── Sidebar Footer ────────────────────────────────────── */

.sidebar-footer {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--surface-border);
}

.fab-btn {
    flex: 1;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.fab-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.collab-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--surface-border);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.collab-btn:hover {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: var(--accent);
}

/* ── Editor Area ───────────────────────────────────────── */

.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 32px 48px;
    position: relative;
    background: var(--bg-primary);
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-btn {
    display: none;
}

.note-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.timestamp {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.word-count {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

.editor-actions {
    display: flex;
    gap: 4px;
}

.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#note-title {
    background: transparent;
    border: none;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    outline: none;
    width: 100%;
    letter-spacing: -0.5px;
}

#note-title::placeholder {
    color: var(--text-tertiary);
}

#note-content {
    flex: 1;
    background: transparent;
    border: none;
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-primary);
    outline: none;
    resize: none;
    width: 100%;
}

#note-content::placeholder {
    color: var(--text-tertiary);
}

/* ── Empty State ───────────────────────────────────────── */

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-tertiary);
}

.empty-icon {
    width: 48px;
    height: 48px;
    opacity: 0.3;
}

.empty-state h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.85rem;
}

/* ── Modal ─────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--modal-bg);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-xl);
    padding: 28px;
    width: 420px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.modal-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.tab-btn.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

.modal-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s ease;
}

.form-group input::placeholder {
    color: var(--text-tertiary);
}

.form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.primary-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.primary-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.secondary-btn {
    width: 100%;
    padding: 10px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    background: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Share Panel ───────────────────────────────────────── */

.share-success {
    text-align: center;
    margin-bottom: 20px;
}

.success-icon {
    color: var(--success);
    width: 40px;
    height: 40px;
    margin-bottom: 8px;
}

.share-success h3 {
    font-size: 1rem;
    font-weight: 600;
}

.room-code-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
}

.room-code-value {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 6px;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}

.qr-container {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    padding: 16px;
    background: white;
    border-radius: var(--radius-md);
}

.modal-error {
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--danger-subtle);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 0.85rem;
    text-align: center;
}

/* ── Footer ───────────────────────────────────────────── */

.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 16px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    background: var(--bg-secondary);
    border-top: 1px solid var(--surface-border);
    z-index: 50;
}

.app-footer strong {
    color: var(--text-secondary);
    font-weight: 600;
}

/* ── Animations ────────────────────────────────────────── */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        z-index: 100;
        left: -320px;
        height: 100%;
        width: 300px;
        min-width: 300px;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-overlay {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: var(--overlay-bg);
        z-index: 90;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    .menu-btn {
        display: flex;
    }

    .editor-area {
        padding: 20px;
    }

    #note-title {
        font-size: 1.5rem;
    }
}
