/* ===== CSS Variables - Dark Theme (Default) ===== */
:root,
html[data-theme="dark"] {
    --bg-primary: #0f0f14;
    --bg-secondary: #16161d;
    --bg-tertiary: #1e1e28;
    --bg-card: rgba(30, 30, 42, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.03);
    --bg-glass-hover: rgba(255, 255, 255, 0.06);

    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;

    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);

    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-strong: rgba(255, 255, 255, 0.15);

    --danger: #f43f5e;
    --success: #22c55e;
    --accent-success: #22c55e;
    --warning: #f97316;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --sidebar-width: 260px;
    --topbar-height: 64px;
    --column-width: 300px;

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

/* ===== Light Theme - Clean & Minimal ===== */
html[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-glass: rgba(0, 0, 0, 0.02);
    --bg-glass-hover: rgba(0, 0, 0, 0.04);

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);

    --border-color: rgba(0, 0, 0, 0.06);
    --border-color-strong: rgba(0, 0, 0, 0.12);

    --danger: #ef4444;
    --success: #22c55e;
    --accent-success: #22c55e;
    --warning: #f97316;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
}

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

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ===== Global Font Classes ===== */
/* Ensure buttons, inputs, and all elements use the selected font */
body.font-default,
body.font-default button,
body.font-default input,
body.font-default textarea,
body.font-default select {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

body.font-sans,
body.font-sans button,
body.font-sans input,
body.font-sans textarea,
body.font-sans select {
    font-family: 'Helvetica Neue', 'Arial', sans-serif;
}

body.font-serif,
body.font-serif button,
body.font-serif input,
body.font-serif textarea,
body.font-serif select {
    font-family: 'Georgia', 'Times New Roman', 'Palatino Linotype', serif;
}

body.font-mono,
body.font-mono button,
body.font-mono input,
body.font-mono textarea,
body.font-mono select {
    font-family: 'SF Mono', 'Fira Code', 'Monaco', 'Menlo', monospace;
}

body.font-code,
body.font-code button,
body.font-code input,
body.font-code textarea,
body.font-code select {
    font-family: 'JetBrains Mono', 'Fira Code', 'Source Code Pro', 'Consolas', monospace;
}

body.font-dyslexic,
body.font-dyslexic button,
body.font-dyslexic input,
body.font-dyslexic textarea,
body.font-dyslexic select {
    font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif;
    letter-spacing: 0.05em;
    word-spacing: 0.1em;
}

body.font-contrast,
body.font-contrast button,
body.font-contrast input,
body.font-contrast textarea,
body.font-contrast select {
    font-family: 'Arial', 'Helvetica', sans-serif;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* High contrast mode - additional styling */
body.font-contrast {
    --text-primary: #000000;
    --text-secondary: #333333;
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --accent-primary: #0066cc;
}

body.font-system,
body.font-system button,
body.font-system input,
body.font-system textarea,
body.font-system select {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ===== Utility Classes ===== */
.hidden {
    display: none !important;
}

/* ===== App Layout ===== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width var(--transition-normal);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-version {
    padding: 0 20px 12px;
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    transition: transform var(--transition-fast);
}

.sidebar.collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

/* Collapsed Sidebar State */
.sidebar.collapsed {
    width: 56px;
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .version-badge,
.sidebar.collapsed .sidebar-version,
.sidebar.collapsed .section-header h2,
.sidebar.collapsed #add-project-btn,
.sidebar.collapsed .sidebar-footer .btn-secondary span:not(.settings-icon) {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    padding: 12px;
    justify-content: center;
    position: relative;
}

.sidebar.collapsed .logo {
    justify-content: center;
}

.sidebar.collapsed .logo-icon {
    font-size: 1.25rem;
}

/* Floating toggle button when collapsed - sticks out from sidebar edge */
.sidebar.collapsed .sidebar-toggle {
    position: absolute;
    right: -14px;
    top: 20px;
    transform: rotate(180deg);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    z-index: 200;
    box-shadow: var(--shadow-sm);
}

.sidebar.collapsed .sidebar-section {
    padding: 8px;
}

.sidebar.collapsed .project-item {
    padding: 10px;
    justify-content: center;
    position: relative;
}

/* Hide project name text when collapsed, show dot indicator */
.sidebar.collapsed .project-name {
    display: none;
}

/* Show colored dot when collapsed */
.sidebar.collapsed .project-item::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.sidebar.collapsed .project-item.active::before {
    background: white;
}

/* Rich tooltip for collapsed sidebar items - instant appearance */
.sidebar.collapsed .project-item::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease;
    z-index: 1000;
}

/* Arrow pointer */
.sidebar.collapsed .project-item::before {
    content: '';
    position: absolute;
    left: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: var(--bg-secondary);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease;
    z-index: 1001;
}

/* Show tooltip instantly on hover */
.sidebar.collapsed .project-item:hover::after {
    opacity: 1;
}

/* Keep the dot visible - override the arrow */
.sidebar.collapsed .project-item .project-name+.dot,
.sidebar.collapsed .project-item:not(:hover)::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    position: static;
    transform: none;
    border: none;
    opacity: 1;
}

.sidebar.collapsed .project-item.active:not(:hover)::before {
    background: white;
}

.sidebar.collapsed .sidebar-footer {
    padding: 8px;
}

.sidebar.collapsed .sidebar-footer .btn-secondary {
    padding: 10px;
    justify-content: center;
    overflow: hidden;
    width: 40px;
    height: 40px;
}

.sidebar.collapsed .sidebar-footer .btn-text {
    display: none !important;
}

.sidebar.collapsed .sidebar-footer .settings-icon {
    margin-right: 0;
    flex-shrink: 0;
}

/* Settings icon margin when not collapsed */
.settings-icon {
    margin-right: 8px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-icon {
    font-size: 1.5rem;
    -webkit-text-fill-color: initial;
}

.version-badge {
    font-size: 0.65rem;
    color: var(--text-muted);
    background: var(--bg-glass);
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: -4px;
}

.sidebar-section {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

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

.section-header h2 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.project-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.project-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.project-item:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
}

.project-item.active {
    background: var(--accent-gradient);
    color: white;
    font-weight: 500;
}

/* Project drag and drop */
.project-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

/* Show insertion line above item */
.project-item.drag-above {
    position: relative;
}

.project-item.drag-above::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 8px;
    right: 8px;
    height: 3px;
    background: var(--accent-primary);
    border-radius: 2px;
    box-shadow: 0 0 8px var(--accent-primary);
}

/* Show insertion line below item */
.project-item.drag-below {
    position: relative;
}

.project-item.drag-below::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 8px;
    right: 8px;
    height: 3px;
    background: var(--accent-primary);
    border-radius: 2px;
    box-shadow: 0 0 8px var(--accent-primary);
}

.project-item[draggable="true"] {
    cursor: grab;
}

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

/* ===== Buttons ===== */
.btn-icon {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

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

.btn-primary {
    padding: 10px 20px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition-fast);
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    padding: 10px 16px;
    background: var(--bg-glass);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition-fast);
}

.btn-secondary:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
    border-color: var(--border-color-strong);
}

.btn-danger {
    padding: 10px 16px;
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}

/* ===== Top Bar ===== */
.top-bar {
    height: var(--topbar-height);
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background: var(--bg-secondary);
}

.project-title-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.project-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.view-toggle {
    display: flex;
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    padding: 4px;
    border: 1px solid var(--border-color);
}

.view-btn {
    padding: 8px 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-fast);
}

.view-btn:hover {
    color: var(--text-primary);
}

.view-btn.active {
    background: var(--accent-gradient);
    color: white;
}

/* ===== Board View ===== */
.board-view {
    flex: 1;
    display: flex;
    padding: 24px;
    gap: 16px;
    overflow-x: auto;
    overflow-y: hidden;
}

.board {
    display: flex;
    gap: 16px;
    height: 100%;
    position: relative;
}

/* ===== Link Overlay (SVG connector lines) ===== */
.link-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 5;
    overflow: visible;
}

.link-overlay .link-line {
    transition: stroke-opacity 0.2s ease, stroke-width 0.2s ease;
}

.link-overlay .link-node {
    transition: opacity 0.2s ease, r 0.2s ease;
}

/* ===== Columns ===== */
.column {
    width: var(--column-width);
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    max-height: 100%;
}

.column-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.column-title {
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.column-count {
    background: var(--bg-glass);
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

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

.column-cards {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.column-footer {
    padding: 12px;
    border-top: 1px solid var(--border-color);
}

.add-card-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all var(--transition-fast);
}

.add-card-btn:hover {
    background: var(--bg-glass);
    border-color: var(--border-color-strong);
    color: var(--text-secondary);
}

.add-column-btn {
    width: var(--column-width);
    min-height: 120px;
    background: var(--bg-glass);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.add-column-btn:hover {
    background: var(--bg-glass-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* ===== Cards ===== */
.card {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    padding: 14px;
    cursor: grab;
    transition: all var(--transition-fast);
    position: relative;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    background: var(--card-color, var(--accent-primary));
}

.card:hover {
    border-color: var(--border-color-strong);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.card-content {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-links {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.card-links svg {
    width: 12px;
    height: 12px;
}

/* ===== Drop Zone ===== */
.column-cards.drag-over {
    background: var(--bg-glass);
}

.drop-placeholder {
    height: 60px;
    border: 2px dashed var(--accent-primary);
    border-radius: var(--radius-md);
    background: rgba(99, 102, 241, 0.1);
}

/* ===== Map View ===== */
.map-view {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at center, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}

#map-canvas {
    width: 100%;
    height: 100%;
    cursor: grab;
}

#map-canvas:active {
    cursor: grabbing;
}

.map-controls {
    position: absolute;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    padding: 8px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.map-legend {
    position: absolute;
    bottom: 24px;
    left: 24px;
    display: flex;
    gap: 16px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-line {
    width: 20px;
    height: 2px;
    background: var(--text-muted);
}

/* ===== Empty State ===== */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 24px;
    opacity: 0.8;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 12px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    max-width: 400px;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn var(--transition-fast);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    animation: slideIn var(--transition-normal);
    display: flex;
    flex-direction: column;
}

.modal-sm {
    max-width: 380px;
}

.modal-lg {
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-lg .modal-body {
    overflow-y: auto;
    flex: 1;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ===== Card Viewer ===== */
.card-viewer-content {
    overflow-y: auto;
}

/* ===== Modal with TOC Layout ===== */
.modal-body-with-toc {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Mobile TOC Dropdown - appears above content */
.mobile-toc-dropdown {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    flex-shrink: 0;
}

.mobile-toc-dropdown summary {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.mobile-toc-dropdown summary:hover {
    color: var(--text-primary);
}

.mobile-toc-dropdown[open] {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.mobile-toc-list {
    list-style: none;
    padding: 0 14px 14px;
    max-height: 200px;
    overflow-y: auto;
}

.mobile-toc-list li {
    padding: 6px 0;
}

.mobile-toc-list a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
}

.mobile-toc-list a:hover {
    color: var(--accent-primary);
}

/* Desktop TOC Sidebar - hidden on mobile, shown on larger screens */
.toc-sidebar {
    display: none;
}

@media (min-width: 900px) {
    .modal-body-with-toc {
        flex-direction: row;
    }

    .mobile-toc-dropdown {
        display: none;
    }

    .toc-sidebar {
        display: block;
        width: 200px;
        flex-shrink: 0;
        border-right: 1px solid var(--border-color);
        padding: 16px;
        overflow-y: auto;
    }

    .toc-header {
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        color: var(--text-muted);
        margin-bottom: 12px;
    }

    .toc-list {
        list-style: none;
    }

    .toc-list li {
        padding: 4px 0;
    }

    .toc-list a {
        color: var(--text-secondary);
        text-decoration: none;
        font-size: 0.85rem;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .toc-list a:hover {
        color: var(--accent-primary);
    }

    .card-viewer-content {
        flex: 1;
        padding: 16px;
    }
}

/* ===== Resizable Modal (for edit modal) ===== */
.modal.resizable {
    resize: both;
    overflow: hidden;
    min-width: 380px;
    min-height: 400px;
}

.modal.modal-edit {
    max-width: 600px;
    width: 90%;
    height: auto;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.modal.modal-edit .modal-body {
    flex: 1;
    overflow-y: auto;
}

.modal.modal-edit textarea {
    min-height: 200px;
    flex: 1;
}

.card-viewer-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== Mobile TOC Trigger ===== */
.mobile-toc-dropdown {
    display: none;
    margin-bottom: 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.mobile-toc-dropdown summary {
    padding: 10px 16px;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    list-style: none;
    /* Hide default triangle in some browsers */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mobile-toc-dropdown summary::-webkit-details-marker {
    display: none;
}

.mobile-toc-dropdown summary::after {
    content: '▼';
    font-size: 0.8rem;
    transition: transform 0.2s;
}

.mobile-toc-dropdown[open] summary::after {
    transform: rotate(180deg);
}

.mobile-toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    border-top: 1px solid var(--border-color);
    max-height: 200px;
    overflow-y: auto;
}

.mobile-toc-list li a {
    display: block;
    padding: 8px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    border-left: 2px solid transparent;
}

.mobile-toc-list li a:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
}

.mobile-toc-list li.level-2 a {
    padding-left: 24px;
}

.mobile-toc-list li.level-3 a {
    padding-left: 32px;
}

/* ===== Markdown Content Rendering ===== */
.markdown-content {
    line-height: 1.7;
    color: var(--text-primary);
}

.markdown-content h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin: 1.5rem 0 0.75rem 0;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.markdown-content h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 1.25rem 0 0.5rem 0;
    color: var(--text-primary);
}

.markdown-content h4 {
    font-size: 1rem;
    font-weight: 600;
    margin: 1rem 0 0.5rem 0;
    color: var(--text-secondary);
}

.markdown-content p {
    margin: 0.75rem 0;
}

.markdown-content a {
    color: var(--accent-primary);
    text-decoration: none;
}

.markdown-content a:hover {
    text-decoration: underline;
}

.markdown-content code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85em;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent-secondary);
}

.markdown-content pre {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    overflow-x: auto;
    margin: 1rem 0;
}

.markdown-content pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
}

.markdown-content blockquote {
    border-left: 3px solid var(--accent-primary);
    padding-left: 16px;
    margin: 1rem 0;
    color: var(--text-secondary);
    font-style: italic;
}

.markdown-content ul,
.markdown-content ol {
    margin: 0.75rem 0;
    padding-left: 24px;
}

.markdown-content li {
    margin: 0.4rem 0;
}

.markdown-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}

.markdown-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.markdown-content em {
    font-style: italic;
}

.markdown-content del {
    text-decoration: line-through;
    opacity: 0.7;
}

.markdown-content input[type="checkbox"] {
    margin-right: 8px;
    accent-color: var(--accent-primary);
}

.markdown-content .md-image {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 1rem 0;
}

/* Card markdown badge */
.card-md-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    margin-top: 8px;
}

/* ===== Card Viewer Modal (Enhanced) ===== */
.modal-viewer {
    max-width: 900px;
    width: 90%;
    height: 80vh;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 400px;
    min-height: 300px;
}

.modal-viewer.resizable {
    resize: both;
    overflow: hidden;
}

.modal-body-with-toc {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
    height: 100%;
}

/* ===== TOC Sidebar ===== */
.toc-sidebar {
    width: 200px;
    min-width: 180px;
    background: var(--bg-tertiary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.toc-sidebar.hidden {
    display: none;
}

.toc-header {
    padding: 12px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.toc-list {
    list-style: none;
    padding: 8px 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
}

.toc-item {
    margin: 0;
}

.toc-item a {
    display: block;
    padding: 6px 16px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition-fast);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-left: 2px solid transparent;
}

.toc-item a:hover {
    color: var(--text-primary);
    background: var(--bg-glass-hover);
    border-left-color: var(--accent-primary);
}

.toc-item.level-2 a {
    padding-left: 24px;
    font-size: 0.75rem;
}

.toc-item.level-3 a {
    padding-left: 32px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.toc-empty {
    padding: 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
}

/* ===== Viewer Content Area ===== */
.modal-body-with-toc .card-viewer-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    scroll-behavior: smooth;
    height: 100%;
}

/* ===== Resize Handle ===== */
.resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, var(--border-color-strong) 50%);
    border-radius: 0 0 var(--radius-lg) 0;
    opacity: 0.5;
    transition: opacity var(--transition-fast);
}

.resize-handle:hover {
    opacity: 1;
}

/* ===== Font Options ===== */
.font-indicator {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: auto;
}

/* Font: Default (Inter) */
.markdown-content.font-default {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Font: Mono (Courier-like) */
.markdown-content.font-mono {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'Courier New', monospace;
    font-size: 0.9rem;
    letter-spacing: -0.02em;
}

.markdown-content.font-mono code {
    font-size: 1em;
}

/* Font: System */
.markdown-content.font-system {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* ===== No TOC State ===== */
.modal-body-with-toc.no-toc .toc-sidebar {
    display: none;
}

.modal-body-with-toc.no-toc .card-viewer-content {
    padding: 24px 32px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-left: auto;
}

/* ===== Form Elements ===== */
.form-group {
    margin-bottom: 20px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

input[type="text"],
textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: all var(--transition-fast);
}

input[type="text"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

/* ===== Color Picker ===== */
.color-picker {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.color-option {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.color-option:hover {
    transform: scale(1.15);
}

.color-option.active {
    border-color: white;
    box-shadow: var(--shadow-sm);
}

/* ===== Linked Cards ===== */
.linked-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.linked-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.linked-card-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
}

.linked-card-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.linked-card-remove {
    padding: 4px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.linked-card-remove:hover {
    color: var(--danger);
    background: rgba(244, 63, 94, 0.1);
}

/* ===== Linkable Cards List ===== */
.linkable-cards {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.linkable-group-header {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 12px 8px 4px;
    border-bottom: 1px solid var(--border-color);
    margin-top: 8px;
}

.linkable-group-header:first-child {
    margin-top: 0;
}

.linkable-card {
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 10px;
}

.linkable-card:hover {
    background: var(--bg-glass-hover);
    border-color: var(--accent-primary);
}

.linkable-card-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.linkable-card-title {
    font-size: 0.85rem;
    flex: 1;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color-strong);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Responsive ===== */
/* Moved media query to end of file for correct cascading */

/* ===== Hamburger Button ===== */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 200;
    /* Increased to ensure visibility */
    width: 40px;
    height: 40px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all var(--transition-fast);
}


/* ===== Sidebar Overlay ===== */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 95;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

/* ===== Column Footer Buttons ===== */
.column-footer-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn-add-card {
    flex: 2;
    background: transparent;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    width: auto;
    margin-top: 0;
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-add-card:hover {
    background: var(--bg-glass-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.btn-add-file {
    flex: 1;
    background: transparent;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 10px;
}

.btn-add-file:hover {
    background: var(--bg-glass-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* ===== Settings Form Styles ===== */
.form-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.input-with-button {
    display: flex;
    gap: 12px;
}

.input-with-button input {
    flex: 1;
}

.storage-status {
    font-size: 0.8rem;
    margin-top: 8px;
}

/* ===== Theme Picker ===== */
.theme-picker {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

.theme-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.theme-option:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-color-strong);
    color: var(--text-primary);
}

.theme-option.active {
    background: var(--accent-gradient);
    border-color: var(--accent-primary);
    color: white;
}

.theme-icon {
    font-size: 1.1rem;
}

/* ===== Font Picker ===== */
.font-picker {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.font-option {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
}

.font-option:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-color-strong);
    color: var(--text-primary);
}

.font-option.active {
    background: var(--accent-gradient);
    border-color: var(--accent-primary);
    color: white;
}

/* ===== Slider ===== */
.slider-group {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.slider-input {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
}

.slider-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
    box-shadow: var(--shadow-sm);
}

.slider-input::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
}

.slider-value {
    min-width: 40px;
    text-align: right;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== QR Code ===== */
#qrcode img {
    display: block;
    margin: 0 auto;
}

/* ===== Responsive (Moved to End) ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        z-index: 100;
        transition: transform var(--transition-normal);
        transform: translateX(0);
    }

    .sidebar.open {
        transform: translateX(260px);
    }

    .sidebar-overlay.open {
        opacity: 1;
        pointer-events: auto;
    }

    .hamburger-btn {
        display: flex;
    }

    .top-bar {
        padding-left: 60px;
        /* Space for hamburger */
    }

    /* Mobile Modal Adjustments */
    .modal-header {
        flex-wrap: wrap;
        gap: 12px;
    }

    .modal-header h3 {
        width: 100%;
        order: 1;
    }

    .modal-header-actions {
        width: 100%;
        order: 2;
        justify-content: flex-end;
        padding-top: 4px;
        border-top: 1px solid var(--border-color);
        /* Separator */
    }

    /* Swap Desktop TOC for Mobile Dropdown */
    .toc-sidebar {
        display: none;
    }

    .mobile-toc-dropdown {
        display: block;
    }
}

/* ===== Toggle Switch ===== */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-tertiary);
    transition: .4s;
    border-radius: 24px;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-muted);
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
}

input:checked+.slider:before {
    transform: translateX(20px);
    background-color: white;
}

/* Syncing Indicator */
.sync-indicator {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-card);
    padding: 8px 16px;
    border-radius: 100px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    z-index: 1000;
    transition: opacity 0.3s, transform 0.3s;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

.sync-indicator.visible {
    opacity: 1;
    transform: translateY(0);
}

.sync-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}