/* ── CSS Variables / Theming ─────────────────────────────────────── */
:root {
    --bg: #f1f3f4;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-topbar: #ffffff;
    --bg-input: #f1f3f4;
    --bg-hover: #e8eaed;
    --text: #202124;
    --text-secondary: #5f6368;
    --text-muted: #9aa0a6;
    --border: #e0e0e0;
    --border-light: #eeeeee;
    --primary: #1a73e8;
    --primary-hover: #1765cc;
    --danger: #d93025;
    --shadow: 0 1px 2px 0 rgba(60,64,67,.3), 0 2px 6px 2px rgba(60,64,67,.15);
    --shadow-hover: 0 1px 3px 0 rgba(60,64,67,.3), 0 4px 8px 3px rgba(60,64,67,.15);
    --radius: 8px;
    --sidebar-width: 280px;
    --topbar-height: 64px;
    --transition: .2s ease;
}

[data-theme="dark"] {
    --bg: #202124;
    --bg-card: #2d2e30;
    --bg-sidebar: #2d2e30;
    --bg-topbar: #2d2e30;
    --bg-input: #3c4043;
    --bg-hover: #3c4043;
    --text: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-muted: #5f6368;
    --border: #5f6368;
    --border-light: #3c4043;
    --primary: #8ab4f8;
    --primary-hover: #aecbfa;
    --danger: #f28b82;
    --shadow: 0 1px 2px 0 rgba(0,0,0,.6), 0 2px 6px 2px rgba(0,0,0,.3);
    --shadow-hover: 0 1px 3px 0 rgba(0,0,0,.6), 0 4px 8px 3px rgba(0,0,0,.3);
}

[data-theme="dark"] .color-dot[data-color="#ffffff"] { background: #2d2e30 !important; border: 2px solid var(--border); }
[data-theme="dark"] .note-card[style*="background:#ffffff"],
[data-theme="dark"] .note-edit-modal[style*="background:#ffffff"],
[data-theme="dark"] .composer[style*="background:#ffffff"] { background: var(--bg-card) !important; }
[data-theme="dark"] .note-card[style*="background:#fff3e0"] { background: #5c3d14 !important; }
[data-theme="dark"] .note-card[style*="background:#e8f5e9"] { background: #1b3a1e !important; }
[data-theme="dark"] .note-card[style*="background:#e3f2fd"] { background: #1a2c42 !important; }
[data-theme="dark"] .note-card[style*="background:#f3e5f5"] { background: #3a1c42 !important; }
[data-theme="dark"] .note-card[style*="background:#fce4ec"] { background: #3e1c24 !important; }
[data-theme="dark"] .note-card[style*="background:#fff9c4"] { background: #4a4210 !important; }
[data-theme="dark"] .note-card[style*="background:#efebe9"] { background: #3e3530 !important; }

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

body {
    font-family: 'Google Sans', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
}

.hidden { display: none !important; }

/* ── Login ──────────────────────────────────────────────────────── */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 16px;
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    text-align: center;
}

.login-logo {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 32px;
    color: white;
}

.login-card h1 { font-size: 28px; color: #202124; margin-bottom: 4px; }
.login-subtitle { color: #5f6368; margin-bottom: 32px; }

.input-group {
    position: relative;
    margin-bottom: 16px;
}

.input-group i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #9aa0a6;
    font-size: 14px;
}

.input-group input {
    width: 100%;
    padding: 12px 14px 12px 42px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    outline: none;
    transition: border-color .2s;
    background: white;
    color: #202124;
}

.input-group input:focus { border-color: #667eea; }

.btn-login {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: opacity .2s;
}

.btn-login:hover { opacity: .9; }
.login-error { color: #d93025; margin-top: 12px; min-height: 20px; font-size: 14px; }

/* ── App Layout ─────────────────────────────────────────────────── */
.app {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid var(--border-light);
}

.sidebar-header i {
    font-size: 24px;
    color: var(--primary);
}

.sidebar-nav { padding: 8px 12px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background var(--transition);
    cursor: pointer;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: #e8f0fe; color: var(--primary); }
[data-theme="dark"] .nav-item.active { background: rgba(138,180,248,.15); }
.nav-item i { width: 20px; text-align: center; font-size: 16px; }

.sidebar-labels {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    border-top: 1px solid var(--border-light);
}

.sidebar-labels h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.label-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: background var(--transition);
}

.label-item:hover { background: var(--bg-hover); }
.label-item.active { background: #e8f0fe; color: var(--primary); }
[data-theme="dark"] .label-item.active { background: rgba(138,180,248,.15); }

.sidebar-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--border-light);
}

/* ── Main Content ───────────────────────────────────────────────── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Top Bar ────────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-height);
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar #btn-menu { display: none; }

.search-bar {
    flex: 1;
    max-width: 720px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border-radius: 8px;
    padding: 0 16px;
    height: 44px;
    transition: box-shadow var(--transition);
}

.search-bar:focus-within { box-shadow: var(--shadow); background: var(--bg-card); }
.search-bar i { color: var(--text-muted); font-size: 16px; }

.search-bar input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 15px;
    color: var(--text);
}

.search-bar input::placeholder { color: var(--text-muted); }

.topbar-actions { display: flex; gap: 4px; margin-left: auto; }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 16px;
    transition: background var(--transition);
}

.btn-icon:hover { background: var(--bg-hover); }
.btn-icon.btn-danger:hover { color: var(--danger); }
.btn-icon.active { color: var(--primary); }

.btn-primary {
    padding: 8px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-text {
    padding: 8px 16px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
}

.btn-text:hover { background: var(--bg-hover); }

/* ── Composer ───────────────────────────────────────────────────── */
.composer-wrapper {
    padding: 24px 24px 0;
    max-width: 680px;
    margin: 0 auto;
    width: 100%;
}

.composer {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: box-shadow var(--transition);
}

.composer:focus-within { box-shadow: var(--shadow-hover); }

.composer.collapsed .composer-title,
.composer.collapsed .composer-toolbar { display: none; }

.composer.collapsed .composer-content {
    padding: 14px 16px;
    min-height: unset;
}

.composer-title {
    width: 100%;
    border: none;
    outline: none;
    padding: 16px 16px 0;
    font-size: 16px;
    font-weight: 600;
    background: transparent;
    color: var(--text);
}

.composer-title::placeholder { color: var(--text-muted); }

.composer-content {
    min-height: 60px;
    padding: 12px 16px;
    outline: none;
    font-size: 14px;
    color: var(--text);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.composer-content:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
}

.composer-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-light);
}

.composer-actions { margin-left: auto; display: flex; gap: 8px; }

/* ── Color & Label Pickers ──────────────────────────────────────── */
.color-picker, .label-picker { position: relative; }

.color-options {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: var(--shadow-hover);
    padding: 8px;
    display: flex;
    gap: 4px;
    z-index: 200;
}

.color-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    transition: transform .15s;
}

.color-dot:hover { transform: scale(1.2); }
.color-dot.selected { border-color: var(--primary); border-width: 3px; }

.label-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: var(--shadow-hover);
    padding: 8px;
    min-width: 200px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 200;
}

.label-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
}

.label-dropdown-item:hover { background: var(--bg-hover); }
.label-dropdown-item i { color: var(--primary); width: 16px; }

.label-dropdown .new-label-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px;
    font-size: 13px;
    margin-top: 4px;
    background: var(--bg-input);
    color: var(--text);
    outline: none;
}

/* ── Notes Grid ─────────────────────────────────────────────────── */
.notes-grid { padding: 16px 24px; }

.section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin: 16px 0 8px;
    font-weight: 500;
}

.notes-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.notes-list.list-view {
    grid-template-columns: 1fr;
    max-width: 680px;
}

/* ── Note Card ──────────────────────────────────────────────────── */
.note-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    padding: 16px;
    cursor: pointer;
    transition: box-shadow var(--transition), border-color var(--transition);
    position: relative;
    overflow: hidden;
    max-height: 300px;
}

.note-card:hover {
    box-shadow: var(--shadow-hover);
    border-color: var(--border);
}

.note-card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
    word-break: break-word;
}

.note-card-content {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 8;
    -webkit-box-orient: vertical;
    word-break: break-word;
    white-space: pre-wrap;
}

.note-card-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 10px;
}

.label-chip {
    background: var(--bg-input);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.note-card-actions {
    position: absolute;
    bottom: 4px;
    right: 4px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity var(--transition);
}

.note-card:hover .note-card-actions { opacity: 1; }

.note-card-actions .btn-icon {
    width: 32px;
    height: 32px;
    font-size: 13px;
}

.note-card .pin-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    color: var(--text-muted);
    font-size: 14px;
    opacity: 0;
    transition: opacity var(--transition);
}

.note-card:hover .pin-indicator,
.note-card .pin-indicator.visible { opacity: 1; }

/* ── Empty State ────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state i { font-size: 64px; margin-bottom: 16px; opacity: .5; }
.empty-state p { font-size: 18px; }

/* ── Modal ──────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.5);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-title {
    width: 100%;
    border: none;
    outline: none;
    padding: 20px 20px 0;
    font-size: 18px;
    font-weight: 600;
    background: transparent;
    color: var(--text);
}

.modal-title::placeholder { color: var(--text-muted); }

.modal-body {
    flex: 1;
    padding: 12px 20px;
    outline: none;
    font-size: 14px;
    color: var(--text);
    min-height: 150px;
    max-height: 50vh;
    overflow-y: auto;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.modal-body:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
}

.modal-labels {
    padding: 0 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.modal-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-light);
    flex-wrap: wrap;
}

.modal-tools { display: flex; gap: 2px; }

.modal-meta {
    flex: 1;
    font-size: 12px;
    color: var(--text-muted);
    text-align: right;
    margin-right: 8px;
}

/* Settings Modal */
.settings-modal { padding: 32px; max-width: 420px; }
.settings-modal h2 { margin-bottom: 24px; }
.settings-section { margin-bottom: 24px; }
.settings-section h3 { margin-bottom: 12px; font-size: 15px; color: var(--text-secondary); }
.settings-section .input-group input { padding-left: 14px; }
.settings-message { margin-top: 8px; font-size: 13px; }
.settings-message.success { color: #0d904f; }
.settings-message.error { color: var(--danger); }

/* ── Toast ──────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #323232;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 2000;
    box-shadow: 0 4px 12px rgba(0,0,0,.3);
    animation: toastIn .3s ease;
}

@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(20px); } }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-hover); }
    .main-content { margin-left: 0; }
    .topbar #btn-menu { display: flex; }
    .composer-wrapper { padding: 16px 12px 0; }
    .notes-grid { padding: 12px; }
    .notes-list { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
    .note-card-actions { opacity: 1; }
    .modal { padding: 12px; }
}

@media (max-width: 480px) {
    .notes-list { grid-template-columns: 1fr; }
}

/* ── Scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
