:root {
    /* Colors */
    --bg-primary: #fdfdfd;
    --bg-secondary: #f4f4f5;
    --bg-tertiary: #e9e9ed;
    --bg-hover: #e0e0e6;
    --text-primary: #333333;
    --text-secondary: #777777;
    --border-color: #e0e0e0;
    --accent-color: #2563eb;
    --accent-hover: #3b82f6;
    --accent-light: #93c5fd;
    --danger-color: #e57373;
    --danger-hover: #ef5350;
    --success-color: #81c784;
    --warning-color: #f59e0b;
    --warning-light: #ffd54f;
    --btn-dark: #1a1a1a;
    --btn-dark-hover: #333333;
    --gray-300: #bdbdbd;
    --gray-400: #9e9e9e;

    /* Typography - Font Families */
    --font-sans: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'Fira Code', 'Source Code Pro', monospace;

    /* Typography - Font Weights */
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* Typography - Font Sizes */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 2rem;
}



body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

.container {
    display: flex;
    flex: 1;
    overflow: hidden;
    width: 100%;
    margin-left: 250px;
    transition: margin-left 0.2s ease;
}

.container.sidebar-collapsed {
    margin-left: 0 !important;
}

.container.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}

/* Sidebar Styles */
.sidebar {
    width: 250px;
    flex: none;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 10px;
    box-sizing: border-box;
    overflow: hidden;
    user-select: none;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, transform 0.2s ease;
}

.sidebar h2 {
    margin: 0 0 10px 0;
    text-align: center;
    user-select: none;
    font-weight: var(--font-weight-semibold);
    color: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar .search-container {
    position: relative;
    flex-grow: 1;
    display: flex;
    align-items: center;
}

.sidebar input#searchNotes {
    width: 100%;
    padding: 8px 8px 8px 30px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    box-sizing: border-box;
    height: 38px;
}

.sidebar .search-container .fa-magnifying-glass {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.sidebar button#newNoteBtn {
    background-color: var(--btn-dark);
    border: none;
    color: #fff;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 10px;
    width: 100%;
    font-size: 1em;
    user-select: none;
    font-weight: var(--font-weight-medium);
}

.sidebar button#newNoteBtn:hover {
    background-color: var(--btn-dark-hover);
}

#sidebarDeckList {
    flex: 1;
    overflow-y: auto;
    margin: 1rem 0;
    padding-right: 4px;
}

.sidebar-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

#sortBtn {
    padding: 8px 12px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    height: 38px;
    width: 40px;
}

/* Main Area Styles */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: visible;
    position: relative;
    /* Added for absolute positioning of children if needed */
}

/* --- SIDEBAR PIXEL-PERFECT RESET --- */

/* Navigation Links Container */
.nav-links {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 2px;
    /* Reset inherited styles */
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 0;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
    box-sizing: border-box;
}

/* Footer Container */
.sidebar-footer {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 2px;
    /* Reset inherited styles */
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 0;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
    box-sizing: border-box;
}

/* Shared Item Styles (Reset everything) */
.nav-link,
.sidebar-footer a,
.sidebar-footer button {
    /* Box Model */
    box-sizing: border-box;
    display: flex;
    align-items: center;
    width: 100%;
    height: 40px;
    /* Explicit height */
    padding: 0 12px;
    /* Explicit horizontal padding */
    margin: 0;
    border: none;
    border-radius: 4px;
    outline: none;

    /* Typography */
    font-family: inherit;
    /* Inherits Poppins */
    font-size: 16px;
    /* Explicit pixel value */
    font-weight: var(--font-weight-medium);
    /* Constant weight */
    line-height: 1;
    /* normalize line height */
    text-align: left;
    text-decoration: none;
    color: var(--text-secondary);

    /* Background */
    background: transparent;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

/* Icon Styles */
.nav-link i,
.sidebar-footer i {
    width: 24px;
    /* Fixed icon container width */
    text-align: center;
    margin-right: 12px;
    /* Fixed gap */
    font-size: 18px;
    /* Icon size */
    display: inline-block;
}

/* Hover States */
.nav-link:hover,
.sidebar-footer a:hover,
.sidebar-footer button:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* Active State */
.nav-link.active {
    background-color: var(--bg-tertiary);
    color: var(--accent-color);
    font-weight: 500;
    /* Ensure no shift */
}

/* About Modal Styles */
#aboutModal .modal-content,
#ez-settings-modal .settings-modal-content {
    background-color: var(--bg-primary);
    margin: auto;
    /* Centered by flex parent */
    padding: 0;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 500px;
    border-radius: 8px;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    animation: modalSlideIn 0.3s ease;
    overflow: hidden;
}

#ez-settings-modal .settings-modal-content {
    animation: none;
}

#aboutModal h3,
#ez-settings-modal h3 {
    margin: 0;
    font-size: var(--text-xl);
    color: var(--accent-color);
}

#ez-settings-modal .settings-modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-secondary);
}

#ez-settings-modal .settings-modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#ez-settings-modal label {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

#ez-settings-modal .settings-desc {
    margin: 0 0 5px 0;
    font-size: 0.9em;
    color: var(--text-secondary);
}

#ez-settings-modal input[type="password"] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    box-sizing: border-box;
}

#ez-settings-modal .settings-modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background-color: var(--bg-secondary);
}

/* Modal Overlay (Shared) */
.modal,
#ez-settings-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.15s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Modal content slide-in */
.modal-content,
.settings-modal-content {
    animation: modalSlideIn 0.15s ease;
}

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

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

/* Close Button (Shared) */
.close,
.close-btn {
    color: var(--text-secondary);
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
}

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

/* Button Styles for Modals */
.btn-primary {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

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

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

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

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

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

/* Button Danger */
.btn-danger {
    background-color: var(--danger-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

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

/* Toast Notification (Shared) */
#ez-toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2100;
    /* Higher than modal */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.ez-toast {
    padding: 12px 20px;
    background-color: var(--text-primary);
    color: #fff;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    font-size: var(--text-sm);
    pointer-events: auto;
}

.ez-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.ez-with-sidebar {
    padding-left: 250px;
    box-sizing: border-box;
}

/* --- Pane Slide Animation --- */
#editorPane,
#preview {
    transition: transform 0.2s ease, opacity 0.2s ease, flex 0.2s ease;
}

#preview {
    overflow-y: auto;
    overflow-x: hidden;
}

#editorPane.pane-hidden {
    transform: translateX(-100%);
    opacity: 0;
    flex: 0 0 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    min-width: 0 !important;
    pointer-events: none;
}

#preview.pane-hidden {
    transform: translateX(100%);
    opacity: 0;
    flex: 0 0 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    min-width: 0 !important;
    pointer-events: none;
}

/* --- Mobile Sidebar Styles --- */
@media (max-width: 768px) {

    /* Hide sidebar by default */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        width: 280px;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
        z-index: 100;
    }

    /* Show sidebar when active */
    .sidebar.mobile-visible {
        transform: translateX(0);
    }

    /* Reset content margin/padding */
    .container,
    .ez-with-sidebar {
        margin-left: 0 !important;
        padding-left: 0 !important;
        transition: margin-left 0.3s ease-in-out, padding-left 0.3s ease-in-out;
    }

    /* Overlay */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 99;
        /* Behind sidebar (z-100) */
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease-in-out, visibility 0.3s;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.visible {
        opacity: 1;
        visibility: visible;
    }

    /* Ensure header/toolbar scrolls if needed */
    .toolbar,
    .header {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    /* Mobile Close Button */
    .mobile-close-btn {
        display: block !important;
        /* Force show on mobile */
        position: absolute;
        top: 15px;
        right: 15px;
        background: transparent;
        border: none;
        color: var(--text-secondary);
        font-size: 1.5rem;
        cursor: pointer;
        z-index: 11;
    }
}

/* Hide by default on desktop */
.mobile-close-btn {
    display: none;
}

/* Mobile Menu Button - Fixed for Flashcards/Apps without toolbar */
.mobile-menu-btn {
    display: none;
    /* Hidden on desktop */
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 10px;
        left: 10px;
        z-index: 5;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        padding: 8px;
        border-radius: 4px;
        color: var(--text-secondary);
        cursor: pointer;
    }
}