/* ====== Theme: Dark (Deep Forest at Night) ====== */
html {
    --bg-primary: #141c15;
    --bg-card: #1c2a1e;
    --bg-sidebar: #111a12;
    --bg-hover: #243327;
    --bg-topbar: #1a2618;
    --border-primary: #2d4a2f;
    --border-subtle: #1c2a1e;
    --text-primary: #d4e4d0;
    --text-bright: #eaf2e8;
    --text-muted: #8fa88a;
    --text-dim: #4e6a4c;
    --text-faint: #3d5a3b;
    --accent: #d4a843;
    --accent-hover: #e6c35a;
    --accent-text: #141c15;
    --status-done: #5ea65e;
    --status-due: #e09f45;
    --status-danger: #c94f4f;
    --status-danger-hover: #d96a6a;
    --logo-text: #d4a843;
    --logo-tree: #5ea65e;
    --topbar-tab: #8fa88a;
    --topbar-tab-hover-text: #eaf2e8;
    --topbar-tab-hover-bg: #2d4a2f;
    --topbar-tab-active-text: #eaf2e8;
    --topbar-tab-active-bg: #2d4a2f;
    --topbar-border: #2d4a2f;
    --topbar-user: #8fa88a;
    --topbar-logout: #4e6a4c;
    --topbar-logout-hover-text: #eaf2e8;
    --topbar-logout-hover-bg: #2d4a2f;
    --check-border: #4e6a4c;
    --cat-bg: #2d4a2f;
    --cat-text: #8fa88a;
    --toggle-group-bg: #1c2a1e;
    --notes-tab-hover-bg: #1c2a1e;
    --notes-tab-active-border: #d4a843;
    --notes-tab-active-bg: #1c2a1e;
    --login-card-bg: #1c2a1e;
    --login-card-shadow: rgba(0, 0, 0, 0.5);
    --login-heading: #eaf2e8;
    --login-tagline: #8fa88a;
}

/* ====== Theme: Light (Sunlit Woodland) ====== */
html[data-theme="light"] {
    --bg-primary: #f4f1eb;
    --bg-card: #e8e3d8;
    --bg-sidebar: #ede8de;
    --bg-hover: #ddd8cb;
    --bg-topbar: #3a2f24;
    --border-primary: #c7bfae;
    --border-subtle: #ddd8cb;
    --text-primary: #2c3e2c;
    --text-bright: #1a2b1a;
    --text-muted: #5a6e52;
    --text-dim: #8a9a80;
    --text-faint: #a8b8a0;
    --accent: #b8892e;
    --accent-hover: #a07825;
    --accent-text: #ffffff;
    --status-done: #4a8c4a;
    --status-due: #c08530;
    --status-danger: #b33e3e;
    --status-danger-hover: #cc5555;
    --logo-text: #eaf2e8;
    --logo-tree: #5ea65e;
    --topbar-tab: #a8b8a0;
    --topbar-tab-hover-text: #eaf2e8;
    --topbar-tab-hover-bg: #4a3f33;
    --topbar-tab-active-text: #eaf2e8;
    --topbar-tab-active-bg: #4a3f33;
    --topbar-border: #4a3f33;
    --topbar-user: #a8b8a0;
    --topbar-logout: #8a9a80;
    --topbar-logout-hover-text: #eaf2e8;
    --topbar-logout-hover-bg: #4a3f33;
    --check-border: #8a9a80;
    --cat-bg: #ddd8cb;
    --cat-text: #5a6e52;
    --toggle-group-bg: #e8e3d8;
    --notes-tab-hover-bg: #e8e3d8;
    --notes-tab-active-border: #b8892e;
    --notes-tab-active-bg: #e8e3d8;
    --login-card-bg: #e8e3d8;
    --login-card-shadow: rgba(0, 0, 0, 0.15);
    --login-heading: #1a2b1a;
    --login-tagline: #5a6e52;
}

/* ====== Reset & Base ====== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* ====== Focus styles ====== */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

/* ====== Top Bar ====== */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--topbar-border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 24px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.logo {
    display: flex; align-items: center; gap: 8px;
    font-size: 1.2rem; font-weight: 700; color: var(--logo-text);
}
.logo .logo-tree { color: var(--logo-tree); }
.tabs { display: flex; gap: 4px; }
.tab {
    background: none; border: none; color: var(--topbar-tab); padding: 8px 16px;
    border-radius: 6px; cursor: pointer; font-size: 0.9rem; font-weight: 500;
}
.tab:hover { color: var(--topbar-tab-hover-text); background: var(--topbar-tab-hover-bg); }
.tab.active { color: var(--topbar-tab-active-text); background: var(--topbar-tab-active-bg); }
.avatar { width: 28px; height: 28px; border-radius: 50%; }
.user-name { font-size: 0.85rem; color: var(--topbar-user); }
.logout-btn {
    font-size: 0.8rem; color: var(--topbar-logout); text-decoration: none;
    padding: 4px 10px; border-radius: 4px;
}
.logout-btn:hover { color: var(--topbar-logout-hover-text); background: var(--topbar-logout-hover-bg); }

/* ====== Theme Toggle ====== */
.theme-toggle {
    background: none; border: none; cursor: pointer;
    color: var(--topbar-tab); padding: 6px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { color: var(--topbar-tab-hover-text); background: var(--topbar-tab-hover-bg); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-icon-sun { display: none; }
.theme-icon-moon { display: block; }
html[data-theme="light"] .theme-icon-sun { display: block; }
html[data-theme="light"] .theme-icon-moon { display: none; }

/* ====== Layout ====== */
.container { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.container:has(#notes-view:not(.hidden)) { max-width: 100%; padding: 0; }
.view { }
.hidden { display: none !important; }

/* ====== View Header ====== */
.view-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}
.toggle-group { display: flex; gap: 2px; background: var(--toggle-group-bg); border-radius: 8px; padding: 3px; }
.toggle {
    background: none; border: none; color: var(--text-muted); padding: 7px 18px;
    border-radius: 6px; cursor: pointer; font-size: 0.85rem; font-weight: 500;
}
.toggle:hover { color: var(--text-bright); }
.toggle.active { background: var(--accent); color: var(--accent-text); }

.filters select {
    background: var(--bg-card); border: 1px solid var(--border-primary); color: var(--text-primary);
    padding: 7px 12px; border-radius: 6px; font-size: 0.85rem;
}
.search-box input {
    background: var(--bg-card); border: 1px solid var(--border-primary); color: var(--text-primary);
    padding: 8px 14px; border-radius: 8px; font-size: 0.9rem; width: 280px;
}
.search-box input::placeholder { color: var(--text-dim); }

/* ====== Buttons ====== */
.btn-primary {
    background: var(--accent); color: var(--accent-text); border: none; padding: 8px 18px;
    border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 0.85rem;
    white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger {
    background: var(--status-danger); color: #fff; border: none; padding: 8px 18px;
    border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 0.85rem;
}
.btn-danger:hover { background: var(--status-danger-hover); }

/* ====== Add Todo Form ====== */
.add-form {
    display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap;
}
.add-form input[type="text"] {
    flex: 1; min-width: 180px; background: var(--bg-card); border: 1px solid var(--border-primary);
    color: var(--text-primary); padding: 8px 12px; border-radius: 8px; font-size: 0.9rem;
}
.add-form input[type="date"] {
    background: var(--bg-card); border: 1px solid var(--border-primary); color: var(--text-primary);
    padding: 8px 12px; border-radius: 8px; font-size: 0.9rem;
}
.add-form input::placeholder { color: var(--text-dim); }

/* ====== Todo List ====== */
.item-list { list-style: none; }
.todo-item {
    display: flex; align-items: center; gap: 12px;
    background: var(--bg-card); border-radius: 10px; padding: 14px 16px;
    margin-bottom: 8px; transition: opacity 0.2s;
}
.todo-item.done { opacity: 0.55; }
.todo-item .check {
    width: 22px; height: 22px; border: 2px solid var(--check-border); border-radius: 50%;
    cursor: pointer; flex-shrink: 0; display: flex; align-items: center;
    justify-content: center; transition: all 0.15s;
}
.todo-item .check:hover { border-color: var(--accent); }
.todo-item.done .check { background: var(--status-done); border-color: var(--status-done); }
.todo-item.done .check::after { content: '\2713'; color: #fff; font-size: 13px; font-weight: 700; }
.todo-info { flex: 1; min-width: 0; }
.todo-desc {
    font-size: 0.95rem; color: var(--text-bright); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.todo-item.done .todo-desc { text-decoration: line-through; color: var(--text-muted); }
.todo-meta { display: flex; gap: 10px; margin-top: 4px; font-size: 0.78rem; color: var(--text-dim); }
.todo-meta .due { color: var(--status-due); }
.todo-meta .due.overdue { color: var(--status-danger); }
.todo-meta .cat {
    background: var(--cat-bg); padding: 1px 8px; border-radius: 10px; color: var(--cat-text);
}
.todo-delete {
    background: none; border: none; color: var(--check-border); cursor: pointer;
    font-size: 1.1rem; padding: 4px; border-radius: 4px;
}
.todo-delete:hover { color: var(--status-danger); }

/* ====== Notes Toolbar ====== */
.notes-toolbar {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-primary);
}
.notes-search-input {
    background: var(--bg-card); border: 1px solid var(--border-primary); color: var(--text-primary);
    padding: 6px 12px; font-size: 0.85rem; width: 220px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    margin-left: auto;
}
.notes-search-input::placeholder { color: var(--text-dim); }

/* ====== Notes Panel (sidebar + editor) ====== */
.notes-panel {
    display: flex;
    height: calc(100vh - 56px - 45px);
}

/* ====== Notes Sidebar ====== */
.notes-sidebar {
    width: 220px; min-width: 220px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    overflow-y: auto;
}
.notes-tab {
    display: block; width: 100%;
    padding: 10px 12px;
    border: none; border-left: 3px solid transparent;
    background: none; color: var(--text-muted);
    cursor: pointer; text-align: left;
    border-bottom: 1px solid var(--border-subtle);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}
.notes-tab:hover { background: var(--notes-tab-hover-bg); color: var(--text-primary); }
.notes-tab.active {
    border-left-color: var(--notes-tab-active-border);
    background: var(--notes-tab-active-bg);
    color: var(--text-bright);
}
.notes-tab-title {
    font-size: 0.82rem; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.notes-tab-date {
    font-size: 0.68rem; color: var(--text-dim); margin-top: 2px;
}
.notes-sidebar-empty {
    padding: 24px 12px; text-align: center;
    color: var(--text-dim); font-size: 0.82rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* ====== Notes Editor Pane ====== */
.notes-editor-pane {
    flex: 1; display: flex; flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
}
.notes-empty-state {
    flex: 1; display: flex; align-items: center; justify-content: center;
    color: var(--text-dim); font-size: 0.9rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}
.notes-editor-content {
    flex: 1; display: flex; flex-direction: column;
}
.notes-editor-title {
    background: none; border: none; border-bottom: 1px solid var(--border-subtle);
    color: var(--text-bright); font-size: 0.95rem; font-weight: 500;
    padding: 10px 16px; width: 100%;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}
.notes-editor-title::placeholder { color: var(--text-faint); }
.notes-editor-body {
    background: none; border: none; color: var(--text-primary); font-size: 0.88rem;
    padding: 16px; flex: 1; resize: none;
    line-height: 1.6;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}
.notes-editor-body::placeholder { color: var(--text-faint); }
.notes-editor-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px; border-top: 1px solid var(--border-subtle);
}
.notes-editor-meta { font-size: 0.72rem; color: var(--text-dim); font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }

/* ====== Empty state ====== */
.empty-state {
    text-align: center; padding: 48px 16px; color: var(--text-dim); font-size: 0.95rem;
}

/* ====== Login Page ====== */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
}
.login-card {
    background: var(--login-card-bg);
    border-radius: 16px;
    padding: 48px;
    text-align: center;
    box-shadow: 0 25px 50px var(--login-card-shadow);
    max-width: 400px;
    width: 90%;
}
.login-logo {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    margin-bottom: 8px;
}
.login-logo .logo-tree { color: var(--logo-tree); }
.login-logo-text {
    font-size: 2rem; font-weight: 700; color: var(--login-heading);
}
.login-tagline {
    color: var(--login-tagline); margin-bottom: 32px; font-size: 1rem;
}
.google-btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 12px 32px;
    background: #fff;
    color: #1e293b;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.1s, box-shadow 0.1s;
}
.google-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.google-btn svg { width: 20px; height: 20px; }

/* ====== Responsive ====== */
@media (max-width: 640px) {
    .topbar { padding: 0 12px; }
    .user-name { display: none; }
    .container { padding: 16px 10px; }
    .add-form { flex-direction: column; }
    .search-box input { width: 100%; }
    .notes-panel { flex-direction: column; height: auto; }
    .notes-sidebar { width: 100%; min-width: 100%; max-height: 35vh; border-right: none; border-bottom: 1px solid var(--border-subtle); }
    .notes-search-input { width: 100%; }
}
