/* ============================================
   CSS Variables and Color Themes
   ============================================ */
   :root {
    --bg-color: #ffffff;
    --text-color: #333333;
    --text-secondary: #666666;
    --card-bg: #ffffff;
    --sidebar-bg: #f8f9fa; /* Ensure this is defined */
    --input-bg: #ffffff;
    --border-color: #e0e0e0;
    --hover-bg: #f1f3f5;
    --active-bg: #e8f0fe;
    --hover-border: #d0d0d0;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --primary-btn: #007bff;
    --primary-btn-hover: #0056b3;
    --primary-btn-text: #ffffff;
    --danger-btn: #dc3545;
    --danger-btn-hover: #c82333;
    --danger-btn-text: #ffffff;
    --tag-bg: #e9ecef;
    --tag-text: #495057;
    --tag-hover-bg: #ced4da;
    --scrollbar-thumb: #ced4da;
    --scrollbar-thumb-hover: #adb5bd;
    --link-color: #007bff;
    --logo-color: #007bff;
    /* Note Colors */
    --note-color-red: #f28b82; --note-color-orange: #fbbc04; --note-color-yellow: #fff475; --note-color-green: #ccff90; --note-color-teal: #a7ffeb; --note-color-blue: #cbf0f8; --note-color-darkblue: #aecbfa; --note-color-purple: #d7aefb; --note-color-pink: #fdcfe8; --note-color-brown: #e6c9a8; --note-color-gray: #e8eaed;
}
[data-theme="dark"] {
    --bg-color: #202124; --text-color: #e8eaed; --text-secondary: #9aa0a6; --card-bg: #2d2e30; --sidebar-bg: #28292c; --input-bg: #3c3d40; --border-color: #5f6368; --hover-bg: #3c3d40; --active-bg: #3a4a5f; --hover-border: #777; --shadow-color: rgba(0, 0, 0, 0.3); --primary-btn: #8ab4f8; --primary-btn-hover: #a3c7fa; --primary-btn-text: #202124; --danger-btn: #f28b82; --danger-btn-hover: #f5a39e; --danger-btn-text: #202124; --tag-bg: #3c3d40; --tag-text: #bdc1c6; --tag-hover-bg: #4d4e50; --scrollbar-thumb: #5f6368; --scrollbar-thumb-hover: #7f8388; --link-color: #8ab4f8; --logo-color: #8ab4f8;
}

/* --- Viewer Edit Mode --- */
/* Hide edit elements by default */
.edit-mode-element { display: none !important; }

/* When in VIEW mode */
#note-viewer-content.viewer-mode-view .view-mode-element {
    display: block; /* Default display */
}
#note-viewer-content.viewer-mode-view .note-viewer-actions .view-mode-element {
    display: flex !important; /* Ensure flex */
}
#note-viewer-content.viewer-mode-view .viewer-tags.view-mode-element {
    display: flex !important; /* Ensure flex */
}
#note-viewer-content.viewer-mode-view .edit-mode-element {
    display: none !important; /* Hide all edit elements */
}
#note-viewer-content.viewer-mode-view #viewer-note-body[contenteditable="true"] {
    /* Styles specific to body when in view mode but contenteditable might still be true momentarily */
    outline: none;
    border: none;
    padding: 0;
    background-color: transparent; /* Ensure no edit background */
    margin-bottom: 0; /* Reset margin */
}


/* When in EDIT mode */
#note-viewer-content.viewer-mode-edit .view-mode-element {
    display: none !important; /* Hide all view elements */
}
#note-viewer-content.viewer-mode-edit .edit-mode-element {
    display: block; /* Default display for edit elements */
}
#note-viewer-content.viewer-mode-edit .note-viewer-actions .edit-mode-element {
    display: flex !important; /* Ensure flex */
}
#note-viewer-content.viewer-mode-edit .modal-tags-section.edit-mode-element {
    display: block !important; /* Ensure block */
}
#note-viewer-content.viewer-mode-edit .modal-footer.edit-mode-element {
    display: flex !important; /* Ensure flex */
}
#note-viewer-content.viewer-mode-edit #viewer-title-input.edit-mode-element { /* More specific */
    display: block !important; /* Ensure block */
}
#note-viewer-content.viewer-mode-edit #viewer-note-body { /* No class needed, just apply when parent has .viewer-mode-edit */
    min-height: 20vh;
    outline: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 15px;
    background-color: var(--input-bg);
    color: var(--text-color); /* Ensure text color resets */
}

/* Style the title input like the modal one */
#viewer-title-input {
    border: none;
    background: none;
    font-size: 1.8em; /* Match h2 */
    font-weight: inherit; /* Match h2 */
    outline: none;
    width: 100%;
    color: var(--text-color);
    padding: 0; /* Match h2 */
    margin: 0; /* Match h2 */
    line-height: inherit; /* Match h2 */
    /* Add subtle bottom border for edit mode */
    border-bottom: 1px dashed var(--text-secondary);
    margin-bottom: -1px; /* Align with header border */
}
/* Style the viewer tag input area like the modal */
#viewer-tags-section-edit #viewer-tag-input {
    flex-grow: 1;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 0.9em;
}
#viewer-tags-section-edit #viewer-tag-input:focus {
    outline: none;
    border-color: var(--primary-btn);
}
#viewer-tags-section-edit #viewer-add-tag-btn {
    padding: 5px;
    flex-shrink: 0;
}
/* Style viewer toolbar footer like modal */
#viewer-toolbar-footer {
    padding: 10px 0px; /* Adjust padding */
    border-top: 1px solid var(--border-color);
    background-color: var(--sidebar-bg);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    min-height: 55px;
    margin-top: auto; /* Push to bottom if content is short */
}
#viewer-toolbar-footer .note-date {
    font-size: 0.8em;
    color: var(--text-secondary);
    white-space: nowrap;
}
#viewer-toolbar-footer .modal-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    flex-grow: 1;
    justify-content: flex-start;
    margin-right: 10px;
}

/* ============================================
   Shared Note Enhancements
   ============================================ */

/* Subtle indicator for notes shared by others in the list (Optional) */
.note-item.shared-by-other {
    /* Example: Add a subtle left border */
    /* border-left: 3px solid var(--primary-btn); */
    /* Example: Slightly different background tint */
    /* background-color: color-mix(in srgb, var(--card-bg) 95%, var(--primary-btn) 5%); */
}

/* Make the existing shared icon slightly more prominent if shared by other */
.note-item.shared-by-other .note-shared-indicator .shared-icon {
    opacity: 1;
    color: var(--primary-btn); /* Or var(--text-secondary) */
}
[data-theme="dark"] .note-item.shared-by-other .note-shared-indicator .shared-icon {
     color: var(--link-color); /* Match link color in dark mode */
}


/* Banner for shared notes in Modal/Viewer (for Free users viewing) */
.shared-note-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px; /* Match modal/viewer padding */
    background-color: color-mix(in srgb, var(--primary-btn) 10%, var(--bg-color) 90%); /* Subtle background */
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85em;
    color: var(--text-secondary);
    margin: -15px -20px 15px -20px; /* Adjust negative margin for modal padding */
    flex-shrink: 0; /* Prevent shrinking */
}
/* Adjust banner margin for viewer */
.note-viewer-content .shared-note-banner {
    margin: 0 0 15px 0; /* No negative margin */
    padding: 10px 15px;
    border-radius: 4px; /* Optional rounded corners */
    border: 1px solid var(--border-color);
    background-color: color-mix(in srgb, var(--primary-btn) 8%, var(--bg-color) 92%); /* Slightly different mix */
}

.shared-note-banner .material-icons {
    font-size: 1.2em;
    color: var(--primary-btn);
    flex-shrink: 0;
}
[data-theme="dark"] .shared-note-banner {
     background-color: color-mix(in srgb, var(--primary-btn) 15%, var(--bg-color) 85%);
     border-color: color-mix(in srgb, var(--primary-btn) 25%, var(--border-color) 75%);
}
[data-theme="dark"] .shared-note-banner .material-icons {
     color: var(--link-color);
}

.shared-note-banner p {
    margin: 0;
    flex-grow: 1;
    line-height: 1.4;
}

.shared-note-banner a {
    color: var(--primary-btn);
    font-weight: 500;
    text-decoration: underline;
    white-space: nowrap;
    flex-shrink: 0;
}
.shared-note-banner a:hover {
    text-decoration: none;
}
[data-theme="dark"] .shared-note-banner a {
     color: var(--link-color);
}

/* Adjustments for modal banner positioning */
.modal .modal-scroll-content {
    padding-top: 0; /* Remove top padding if banner exists */
}
.modal .modal-scroll-content > .shared-note-banner {
    margin: 0; /* Reset margin when it's the first child */
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none; /* Only has bottom border */
}
.modal .modal-scroll-content > .shared-note-banner + .editor-wrapper {
     padding-top: 15px; /* Add padding back to editor if banner is present */
}

/* ============================================
   Base Styles & Resets
   ============================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 16px;
    line-height: 1.5;
    overflow: hidden; /* Prevent body scroll */
}
button { cursor: pointer; font-family: inherit; }
input, select, button, textarea { font-family: inherit; font-size: 1em; }
a { color: var(--link-color); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.scrollable { overflow-y: auto; -webkit-overflow-scrolling: touch; }
body.modal-open-no-scroll { overflow: hidden; }

/* ============================================
   App Layout Structure
   ============================================ */
.app-container {
    display: flex;
    height: 100%; /* Use 100% to inherit from body */
    width: 100%;
    overflow: hidden;
    position: relative;
}
.main-content {
    width: 100%;
    height: 100%; /* Use 100% */
    display: flex;
    flex-direction: column; /* Mobile default */
    overflow: hidden; /* Prevent main area scroll */
    position: relative;
    z-index: 1;
    background-color: var(--bg-color);
}

/* ============================================
   Sidebar Styling
   ============================================ */
.sidebar {
    width: 250px;
    height: 100%; /* Use 100% to fill app-container height */
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.3s ease-in-out;
    overflow: hidden; /* Hide any potential overflow from sidebar itself */
}

.sidebar-header,
.sidebar-actions {
    padding-left: 15px;
    padding-right: 15px;
    flex-shrink: 0; /* Header/Actions block don't shrink */
}
.sidebar-header { padding-top: 15px; padding-bottom: 20px; text-align: center; }
.sidebar-actions { padding-bottom: 15px; }

.sidebar-btn { display: flex; align-items: center; width: 100%; padding: 10px 15px; background: none; border: none; color: var(--text-color); text-align: left; font-size: 0.95em; border-radius: 5px; cursor: pointer; margin-bottom: 5px; transition: background-color 0.2s ease, opacity 0.2s ease; }
.sidebar-btn .material-icons { margin-right: 15px; font-size: 1.3em; color: var(--text-secondary); transition: color 0.2s ease; vertical-align: middle; line-height: 1; }
.sidebar-btn:not(:disabled):hover { background-color: var(--hover-bg); }
.sidebar-btn:not(:disabled):hover .material-icons { color: var(--text-color); }
.sidebar-btn:disabled { opacity: 0.5; cursor: not-allowed; background-color: transparent !important; }
.new-note-btn { background-color: var(--primary-btn); color: var(--primary-btn-text); font-weight: bold; }
.new-note-btn:disabled { background-color: var(--primary-btn) !important; color: var(--primary-btn-text); }
.new-note-btn .material-icons { color: var(--primary-btn-text); }
.new-note-btn:not(:disabled):hover { background-color: var(--primary-btn-hover); }

.sidebar-nav {
    flex-grow: 1; /* Takes up space */
    overflow-y: auto; /* Scrolls its content */
    -webkit-overflow-scrolling: touch;
    padding: 0 15px 15px 15px; /* Added bottom padding here */
    min-height: 0; /* Crucial for flex shrink/grow with overflow */
}
.sidebar-nav ul { list-style: none; padding: 0; margin: 0; } .sidebar-nav li { margin-bottom: 3px; }
.sidebar-nav .nav-link { display: flex; align-items: center; padding: 10px 10px; text-decoration: none; color: var(--text-color); border-radius: 5px; font-size: 0.95em; transition: background-color 0.2s ease, color 0.2s ease, font-weight 0.2s ease; }
.sidebar-nav .nav-link .material-icons { margin-right: 15px; font-size: 1.3em; color: var(--text-secondary); transition: color 0.2s ease; vertical-align: middle; line-height: 1; }
.sidebar-nav .nav-link:hover { background-color: var(--hover-bg); color: var(--text-color); }
.sidebar-nav .nav-link.active { background-color: var(--active-bg); color: var(--primary-btn); font-weight: bold; }
.sidebar-nav .nav-link.active .material-icons { color: var(--primary-btn); }
.tag-list-sidebar { list-style: none; padding-left: 40px; margin-top: 5px; font-size: 0.9em; max-height: 200px; overflow-y: auto; }
.tag-list-sidebar li { margin-bottom: 2px; }
.tag-list-sidebar a { display: block; padding: 5px; text-decoration: none; color: var(--text-secondary); border-radius: 3px; transition: background-color 0.2s ease, color 0.2s ease; word-break: break-all; }
.tag-list-sidebar a:hover { background-color: var(--hover-bg); color: var(--text-color); }
.tag-list-sidebar a.active { background-color: var(--active-bg); color: var(--text-color); font-weight: 500; }

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0; /* Footer doesn't shrink */
    background-color: var(--sidebar-bg); /* Ensure footer has bg */
}
.sidebar-footer .sidebar-btn { width: 100%; margin-bottom: 0; }
.sidebar-footer .user-info { font-size: 0.85em; color: var(--text-secondary); margin-top: 10px; display: flex; justify-content: space-between; align-items: center; width: 100%; overflow: hidden; }
#sidebar-user-email { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 10px; }
.sidebar-footer .logout-btn { padding: 5px 8px; width: auto; flex-shrink: 0; }
.sidebar-footer .logout-btn .material-icons { margin-right: 5px; }

/* ============================================
   Note List Column & Empty State
   ============================================ */
.note-list-column {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-color);
}

/* Mobile Top Header */
.mobile-top-header {
    display: block !important;
    text-align: center !important;
    padding-top: 70px;
    padding-bottom: 10px;
    padding-left: 15px;
    padding-right: 15px;
    width: 100%;
    background-color: var(--bg-color);
    flex-shrink: 0;
}
.mobile-top-header .logo-text {
    display: inline-block !important;
    font-size: 1.8em;
    font-weight: bold;
    color: var(--logo-color);
    margin: 0;
}

/* Header (Base styles - primarily mobile) */
.note-list-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    position: relative;
    background-color: var(--bg-color);
    z-index: 1;
    /* Mobile specific flex */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Header content styles (Base) */
#search-input {
    width: 100%; /* Full width on mobile */
    padding: 8px 12px;
    border-radius: 5px;
    border: 1px solid var(--border-color);
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 0.9em;
}
#sort-options {
    display: none !important; /* Hide sort on mobile */
}

/* Notes Container - Will hold the scrollable notes */
.notes-container {
    flex-grow: 1; /* ** Allow it to take available space ** */
    overflow-y: auto; /* ** Allow notes grid/list to scroll ** */
    -webkit-overflow-scrolling: touch;
    padding: 10px;
    display: grid; /* Mobile default */
    gap: 10px;
    /* Use auto-fit and minmax for responsive columns that fill space */
    /* Adjust 150px minimum width as needed */
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    /* Center the grid items horizontally if space allows */
    justify-content: center;
    min-height: 0; /* Important flex item property */
    /* display: none; */ /* ** JS will control visibility ** */
    will-change: transform; /* Optimize for scrolling */
    transform: translateZ(0); /* Force GPU acceleration */
    backface-visibility: hidden; /* Improve rendering performance */
    -webkit-backface-visibility: hidden; /* Safari support */
    perspective: 1000; /* Create a new stacking context */
    contain: content; /* Optimize rendering */
}

/* Empty State - Also designed to take available space */
.empty-state {
    flex-grow: 1; /* ** Allow it to take available space ** */
    width: 100%;
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
    font-size: 1.1em;
    display: none; /* ** Hide by default, JS controls ** */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px; /* Optional: Ensure minimum visible area */
    background-color: var(--bg-color); /* Ensure background match */
}
/* Icon/Link styles remain the same */
#empty-notes-msg .placeholder-icon { font-size: 3em; margin-bottom: 15px; }
.empty-state p a { color: var(--link-color); text-decoration: underline; cursor: pointer; font-weight: 500; }
.empty-state p a:hover { text-decoration: none; }
#empty-notes-msg p .material-icons { font-size: 1.1em; vertical-align: -2px; margin: 0 2px; }

/* ============================================
   Other General Components
   ============================================ */
/* Hamburger Menu */
.menu-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 15px;
    left: 15px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    padding: 0;
    cursor: pointer;
    box-shadow: 0 2px 5px var(--shadow-color);
    z-index: 1090;
    transition: background-color 0.2s ease;
}

select {
    padding: 8px 12px; /* Default padding */
    border-radius: 5px;
    border: 1px solid var(--border-color);
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 0.9em; /* Match search input size */
    /* Appearance might be needed for better cross-browser styling */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    /* Add a background arrow */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23${({ theme }) => theme === 'dark' ? 'e8eaed' : '666666'}'%3E%3Cpath d='M8 11.043l-4.18-4.18a.75.75 0 1 1 1.06-1.06L8 8.922l3.12-3.12a.75.75 0 1 1 1.06 1.06L8 11.043z'/%3E%3C/svg%3E"); /* Simple SVG arrow, color needs dynamic update or JS */
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 35px; /* Make space for the arrow */
}

[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23e8eaed'%3E%3Cpath d='M8 11.043l-4.18-4.18a.75.75 0 1 1 1.06-1.06L8 8.922l3.12-3.12a.75.75 0 1 1 1.06 1.06L8 11.043z'/%3E%3C/svg%3E");
}

input, button, textarea { font-family: inherit; font-size: 1em; }


.menu-toggle-btn .material-icons { color: var(--text-color); font-size: 24px; }
.menu-toggle-btn:hover { background-color: var(--hover-bg); }

/* Note Viewer Column (Initially hidden, shown on desktop) */
.note-viewer-column { display: none; }
.new-note-placeholder-btn { display: none; } /* Placeholder button in viewer */

/* Floating Action Button */
.fab { position: fixed; bottom: 20px; right: 20px; width: 56px; height: 56px; background-color: var(--primary-btn); color: var(--primary-btn-text); border-radius: 50%; border: none; box-shadow: 0 4px 8px var(--shadow-color); display: flex; align-items: center; justify-content: center; z-index: 900; cursor: pointer; transition: transform 0.2s ease, opacity 0.2s ease, background-color 0.2s ease, visibility 0.2s ease; }
.fab .material-icons { font-size: 1.8rem; color: var(--primary-btn-text); }
.fab:hover { background-color: var(--primary-btn-hover); transform: scale(1.05); }
.fab-hidden { opacity: 0; visibility: hidden; transform: scale(0.8); pointer-events: none; }

/* Mobile Context Menu */
.mobile-context-menu { position: fixed; background-color: var(--card-bg); border-radius: 8px; box-shadow: 0 4px 12px var(--shadow-color); z-index: 1050; padding: 8px 0; min-width: 150px; border: 1px solid var(--border-color); opacity: 1; transition: opacity 0.1s ease-out, transform 0.1s ease-out; transform: scale(1); }
.mobile-context-menu.hidden { opacity: 0; transform: scale(0.95); pointer-events: none; visibility: hidden; transition: opacity 0.1s ease-out, transform 0.1s ease-out, visibility 0s linear 0.1s; }
.mobile-context-menu button { display: flex; align-items: center; width: 100%; padding: 10px 15px; background: none; border: none; color: var(--text-color); text-align: left; font-size: 0.95em; cursor: pointer; }
.mobile-context-menu button:hover { background-color: var(--hover-bg); }
.mobile-context-menu button .material-icons { margin-right: 12px; color: var(--text-secondary); font-size: 1.2em; line-height: 1; vertical-align: middle; }
.mobile-context-menu button .action-text { line-height: 1; vertical-align: middle; }
.mobile-context-menu button.delete-action { color: var(--danger-btn); }
.mobile-context-menu button.delete-action .material-icons { color: var(--danger-btn); }
.mobile-context-menu button.delete-action:hover { background-color: rgba(220, 53, 69, 0.1); }
[data-theme="dark"] .mobile-context-menu button.delete-action:hover { background-color: rgba(242, 139, 130, 0.15); }

/* Settings Modal */
.settings-modal .modal-content { max-width: 550px; }
.settings-modal .modal-scroll-content { padding: 10px 25px 25px 25px; }
.settings-modal .static-title { border: none; background: none; font-size: 1.4em; font-weight: 500; outline: none; color: var(--text-color); padding: 5px 0; margin-right: 10px; }
.settings-section { margin-bottom: 25px; padding-bottom: 15px; border-bottom: 1px solid var(--border-color); }
.settings-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.settings-section h3 { font-size: 1.1em; margin-bottom: 15px; color: var(--text-secondary); }
.setting-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; gap: 20px; }
.setting-item:last-child { margin-bottom: 0; }
.setting-item label { flex-shrink: 0; }
.setting-item select, .setting-item input[type="text"] { padding: 8px 12px; border-radius: 5px; border: 1px solid var(--border-color); background-color: var(--input-bg); color: var(--text-color); font-size: 0.95em; min-width: 150px; }
.setting-item p { color: var(--text-secondary); }
#upgradeSubscriptionBtn { width: auto; padding: 8px 15px; font-size: 0.9em; }
#manageDataBtn { width: auto; background-color: var(--hover-bg); color: var(--text-color); padding: 8px 15px; font-size: 0.9em; }
#manageDataBtn:hover { background-color: var(--border-color); }

/* Checklist */
.modal-content-editable ul > li { list-style-type: none; position: relative; padding-left: 28px; margin-left: 0; cursor: pointer; }
.modal-content-editable ul > li::before { content: ''; position: absolute; left: 0; top: 4px; width: 18px; height: 18px; border: 1px solid var(--text-secondary); background-color: var(--input-bg); border-radius: 3px; display: inline-block; }
.modal-content-editable ul > li.checked { text-decoration: line-through; color: var(--text-secondary); opacity: 0.7; }
.modal-content-editable ul > li.checked::before { background-color: var(--primary-btn); border-color: var(--primary-btn); }
.modal-content-editable ul > li.checked::after { content: ''; position: absolute; left: 6px; top: 6px; width: 6px; height: 10px; border: solid var(--primary-btn-text); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.modal-content-editable ul ul > li { margin-left: 20px; }

/* Premium Feature Placeholder */
.premium-feature { position: relative; }
.premium-feature::after { /* Placeholder for icon */ }
.premium-feature.requires-upgrade { opacity: 0.6; cursor: help; }

/* Note List Item */
.note-item {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 15px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    background-color: var(--card-bg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 130px;
    box-shadow: 0 1px 3px var(--shadow-color);
    color: inherit;
    will-change: transform, opacity; /* Optimize for animations */
    transform: translateZ(0); /* Force GPU acceleration */
    backface-visibility: hidden; /* Improve rendering performance */
    -webkit-backface-visibility: hidden; /* Safari support */
    contain: content; /* Optimize rendering */
}
.note-item:hover {
    background-color: var(--hover-bg);
    border-color: var(--hover-border);
    box-shadow: 0 2px 5px var(--shadow-color);
}
.note-item.selected {
    background-color: var(--active-bg);
    border-color: var(--primary-btn);
    box-shadow: 0 0 0 2px var(--primary-btn);
}
.note-item h3 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 0 0 5px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: inherit;
    padding-right: 35px; /* Space for shared icon */
}
.note-date-list, .note-snippet {
    font-size: 0.85em;
    color: inherit;
    opacity: 0.8;
    margin-bottom: 5px;
    line-height: 1.3;
}
.note-snippet {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
    word-break: break-word;
    min-height: calc(1.3em * 2);
}
.note-pin-icon {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 1rem;
    color: inherit;
    opacity: 0.7;
}
.note-item.pinned { /* Optional styling */ }
.note-shared-indicator {
    font-size: 0.8em;
    color: var(--text-secondary);
    margin-left: 8px;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    opacity: 0.8;
    position: absolute;
    top: 13px;
    right: 15px;
}
.note-shared-indicator .shared-icon {
    font-size: 1.2em;
}
.note-item .tags-display {
    margin-top: auto;
    padding-top: 5px;
    max-height: 2.5em;
    overflow: hidden;
}

/* Note Viewer Placeholder & Content */
.note-viewer-placeholder {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
}
.note-viewer-placeholder .placeholder-icon {
    font-size: 4em;
    margin-bottom: 20px;
}
.note-viewer-placeholder p a {
    background: none;
    border: none;
    color: var(--link-color);
    text-decoration: underline;
    cursor: pointer;
    font-size: inherit;
    padding: 0;
}
.note-viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    gap: 15px;
}
#viewer-note-title {
    font-size: 1.8em;
    margin: 0;
    flex-grow: 1;
    word-break: break-word;
}
.note-viewer-actions {
    display: flex;
    flex-shrink: 0;
    gap: 8px;
    align-items: center;
}
.note-viewer-actions .tool-button {
    padding: 6px 10px;
}
.note-viewer-actions .tool-button .material-icons {
    font-size: 1.2rem;
    vertical-align: middle;
    margin-right: 0;
}
.note-viewer-actions .tool-button span + .material-icons, .note-viewer-actions .tool-button .material-icons + span {
    margin-left: 5px;
}
.note-viewer-actions .primary-action {
    background-color: var(--primary-btn);
    color: var(--primary-btn-text);
    padding: 6px 12px;
    border-radius: 5px;
}
.note-viewer-actions .primary-action:hover {
    background-color: var(--primary-btn-hover);
}
.note-viewer-actions .delete-action {
    color: var(--danger-btn);
}
.note-viewer-actions .delete-action:hover {
    background-color: rgba(220, 53, 69, 0.1);
}
[data-theme="dark"] .note-viewer-actions .delete-action:hover {
    background-color: rgba(242, 139, 130, 0.15);
}
.viewer-note-meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-bottom: 20px;
    gap: 15px;
    flex-wrap: wrap;
}
#viewer-note-date {
    flex-shrink: 0;
}
.viewer-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: flex-end;
}
.viewer-note-body {
    line-height: 1.6;
    word-wrap: break-word;
    font-size: 1rem;
}
.viewer-note-body h1, .viewer-note-body h2, .viewer-note-body h3 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
}
.viewer-note-body h1 {
    font-size: 1.6em;
}
.viewer-note-body h2 {
    font-size: 1.4em;
}
.viewer-note-body h3 {
    font-size: 1.2em;
}
.viewer-note-body p {
    margin-bottom: 1em;
}
.viewer-note-body ul, .viewer-note-body ol {
    margin-left: 2em;
    margin-bottom: 1em;
    padding-left: 0;
}
.viewer-note-body li {
    margin-bottom: 0.3em;
}
.viewer-note-body b, .viewer-note-body strong {
    font-weight: bold;
}
.viewer-note-body i, .viewer-note-body em {
    font-style: italic;
}
.viewer-note-body u {
    text-decoration: underline;
}
.viewer-note-body s, .viewer-note-body strike {
    text-decoration: line-through;
}
.viewer-note-body blockquote {
    border-left: 3px solid var(--border-color);
    padding-left: 1em;
    margin: 1em 0;
    font-style: italic;
    color: var(--text-secondary);
}
.viewer-note-body a {
    color: var(--link-color);
}
.viewer-note-body a:hover {
    text-decoration: underline;
}
.viewer-note-body pre {
    background-color: var(--hover-bg);
    padding: 1em;
    border-radius: 4px;
    overflow-x: auto;
    margin-bottom: 1em;
    font-family: monospace;
    font-size: 0.9em;
}
.viewer-note-body code {
    background-color: var(--hover-bg);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
}
.viewer-note-body hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2em 0;
}

/* Tool Button */
.tool-button {
    background: none;
    border: none;
    padding: 8px;
    margin: 0 2px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    color: var(--text-secondary);
    transition: background-color 0.2s ease, color 0.2s ease;
    min-width: 36px;
    min-height: 36px;
    line-height: 1;
    vertical-align: middle;
}
.tool-button:hover {
    background-color: var(--hover-bg);
    color: var(--text-color);
}
.tool-button .material-icons {
    font-size: 1.25rem;
    vertical-align: middle;
}
.tool-button.active {
    background-color: var(--active-bg);
    color: var(--primary-btn);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s ease;
    align-items: center;
    justify-content: center;
}
.modal.visible {
    display: flex;
    opacity: 1;
}
.modal-content {
    position: relative;
    background-color: var(--card-bg);
    margin: auto;
    border-radius: 8px;
    box-shadow: 0 5px 15px var(--shadow-color);
    width: 90%;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: hidden;
}
.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 60px;
}
.modal-title-input {
    border: none;
    background: none;
    font-size: 1.4em;
    font-weight: 500;
    outline: none;
    width: 100%;
    color: var(--text-color);
    padding: 5px 0;
    margin-right: 10px;
}
.modal-header .header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.saving-indicator {
    font-size: 0.8em;
    color: var(--text-secondary);
    margin-right: 10px;
    white-space: nowrap;
}
#closeModalBtn, #closeAuthModalBtn, #closeSettingsModalBtn {
    padding: 8px;
}
.modal-scroll-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}
.editor-wrapper {
    padding: 15px 20px;
    flex-grow: 1;
    display: flex;
    position: relative;
    background-color: var(--card-bg);
    transition: background-color 0.3s ease;
}
#modalNoteContentWrapper[style*="background-color"] .modal-content-editable {
    color: inherit;
}
#modalNoteContentWrapper[style*="background-color"] + .modal-tags-section, #modalNoteContentWrapper[style*="background-color"] ~ .modal-footer {
    background-color: inherit;
    border-top-color: rgba(0, 0, 0, 0.1);
}
#modalNoteContentWrapper[style*="background-color"] ~ .modal-footer .modal-actions .tool-button, #modalNoteContentWrapper[style*="background-color"] ~ .modal-footer .note-date {
    color: inherit;
}
[data-theme="dark"] #modalNoteContentWrapper[style*="background-color"] + .modal-tags-section, [data-theme="dark"] #modalNoteContentWrapper[style*="background-color"] ~ .modal-footer {
    border-top-color: rgba(255, 255, 255, 0.15);
}
.modal-content-editable {
    width: 100%;
    font-size: 1rem;
    flex-grow: 1;
    min-height: 25vh;
    line-height: 1.6;
    border-radius: 5px;
    outline: none;
    word-wrap: break-word;
    white-space: pre-wrap;
    color: var(--text-color);
    border: none;
    background-color: transparent;
    padding: 0;
    caret-color: var(--text-color);
    z-index: 1;
}
.modal-content-editable ul, .modal-content-editable ol {
    padding-left: 2em;
    margin: 0.5em 0;
}
.modal-content-editable li {
    margin-bottom: 0.2em;
}
.modal-content-editable b, .modal-content-editable strong {
    font-weight: bold;
}
.modal-content-editable i, .modal-content-editable em {
    font-style: italic;
}
.modal-content-editable u {
    text-decoration: underline;
}
.modal-content-editable s, .modal-content-editable strike {
    text-decoration: line-through;
}
.modal-content-editable a {
    color: var(--link-color);
}
.modal-content-editable blockquote {
    border-left: 3px solid var(--border-color);
    padding-left: 1em;
    margin: 1em 0;
    font-style: italic;
    color: var(--text-secondary);
}
.modal-content-editable[contenteditable=true]:empty::before {
    content: "Note content...";
    color: var(--text-secondary);
    opacity: 0.6;
    pointer-events: none;
    display: block;
    position: absolute;
    top: 15px;
    left: 20px;
    z-index: 0;
}
#modalNoteContentWrapper[style*="background-color"] .modal-content-editable[contenteditable=true]:empty::before, [data-theme="dark"] .editor-wrapper .modal-content-editable[contenteditable=true]:empty::before {
    content: "";
    display: none;
}
.modal-tags-section {
    padding: 10px 20px 15px 20px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background-color: var(--card-bg);
    transition: background-color 0.3s ease;
}
.modal-tags-display {
    margin-bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    min-height: 20px;
}
.modal-tag-input-area {
    display: flex;
    gap: 5px;
}
#modalTagInput {
    flex-grow: 1;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 0.9em;
}
#modalTagInput:focus {
    outline: none;
    border-color: var(--primary-btn);
}
.add-tag-button {
    padding: 5px;
    flex-shrink: 0;
}
.modal-footer {
    padding: 10px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--sidebar-bg);
    flex-shrink: 0;
    position: relative;
    transition: bottom 0.15s ease-out, background-color 0.3s ease;
    z-index: 10;
    min-height: 55px;
}
.modal-footer .note-date {
    font-size: 0.8em;
    color: var(--text-secondary);
    white-space: nowrap;
}
.modal-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    flex-grow: 1;
    justify-content: flex-start;
    margin-right: 10px;
}
.tool-group {
    display: flex;
    align-items: center;
    gap: 0;
}
.color-palette {
    position: absolute;
    bottom: calc(100% + 5px);
    right: 10px;
    background-color: var(--card-bg);
    border-radius: 5px;
    box-shadow: 0 2px 10px var(--shadow-color);
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    z-index: 1010;
    border: 1px solid var(--border-color);
    width: max-content;
}
.color-palette.hidden {
    display: none;
}
.color-option {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.color-option:hover {
    transform: scale(1.1);
}
.color-option.selected {
    border-color: var(--primary-btn) !important;
    box-shadow: 0 0 0 2px var(--primary-btn) !important;
}
.color-option[data-color-value=""] {
    background-color: transparent !important;
    border: 1px dashed var(--text-secondary) !important;
    box-shadow: none !important;
}
.color-option[data-color-value=""]::before {
    content: '✕';
    color: var(--text-secondary);
    font-size: 0.8em;
    line-height: 1;
}

/* Auth Modal */
.auth-modal .modal-content {
    max-width: 400px;
    padding: 30px;
}
.auth-modal h2 {
    text-align: center;
    margin-bottom: 10px;
}
.auth-modal p {
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-secondary);
}
#auth-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}
#auth-container input {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: var(--input-bg);
    color: var(--text-color);
}
#auth-container button {
    padding: 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
}
#auth-container #emailSignInBtn, #auth-container #emailSignUpBtn {
    background-color: var(--primary-btn);
    color: var(--primary-btn-text);
}
#auth-container #emailSignInBtn:hover, #auth-container #emailSignUpBtn:hover {
    background-color: var(--primary-btn-hover);
}
#auth-container #googleSignInBtn {
    background-color: #ffffff;
    color: #444;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
#auth-container #googleSignInBtn img {
    width: 20px;
    height: 20px;
}
#auth-container #googleSignInBtn:hover {
    background-color: #f8f8f8;
}
.error-message {
    color: var(--danger-btn);
    font-size: 0.9em;
    text-align: center;
    margin-top: -10px;
    margin-bottom: 10px;
}
.close-auth-btn {
    position: absolute;
    top: 10px;
    right: 10px;
}

/* Share Modal */
.share-modal .modal-content {
    max-width: 450px;
}
.share-modal .modal-scroll-content {
    padding: 20px 25px 25px 25px;
    display: block;
}
#shareCollaboratorEmail {
    width: 100%;
    padding: 10px 12px;
    border-radius: 5px;
    border: 1px solid var(--border-color);
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 0.95em;
    margin-bottom: 10px;
}
.share-modal .modal-footer .modal-actions {
    justify-content: flex-end;
}
.share-modal .modal-footer .sidebar-btn {
    padding: 8px 16px;
}
.share-modal .modal-footer .sidebar-btn.primary {
    background-color: var(--primary-btn);
    color: var(--primary-btn-text);
}
.share-modal .modal-footer .sidebar-btn.primary:hover {
    background-color: var(--primary-btn-hover);
}

/* Tags */
.tag {
    display: inline-flex;
    align-items: center;
    background-color: var(--tag-bg);
    color: var(--tag-text);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    margin: 2px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    white-space: nowrap;
}
.tag:hover {
    background-color: var(--tag-hover-bg);
}
.modal-tag-remove-btn {
    background: none;
    border: none;
    color: inherit;
    margin-left: 5px;
    padding: 0;
    cursor: pointer;
    opacity: 0.7;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1em;
    line-height: 1;
    vertical-align: middle;
}
.modal-tag-remove-btn:hover {
    opacity: 1;
    color: var(--danger-btn);
}
.modal-tag-remove-btn .material-icons {
    font-size: inherit;
    display: block;
}

/* Info Prompt */
.info-prompt {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    font-size: 0.9em;
    z-index: 1200;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.info-prompt.visible {
    opacity: 1;
}

/* Scrollbars */
.scrollable::-webkit-scrollbar, body::-webkit-scrollbar, .sidebar-nav::-webkit-scrollbar, .tag-list-sidebar::-webkit-scrollbar, .notes-container::-webkit-scrollbar, .note-viewer-column::-webkit-scrollbar, .modal-scroll-content::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.scrollable::-webkit-scrollbar-track, body::-webkit-scrollbar-track, .sidebar-nav::-webkit-scrollbar-track, .tag-list-sidebar::-webkit-scrollbar-track, .notes-container::-webkit-scrollbar-track, .note-viewer-column::-webkit-scrollbar-track, .modal-scroll-content::-webkit-scrollbar-track {
    background: transparent;
}
.scrollable::-webkit-scrollbar-thumb, body::-webkit-scrollbar-thumb, .sidebar-nav::-webkit-scrollbar-thumb, .tag-list-sidebar::-webkit-scrollbar-thumb, .notes-container::-webkit-scrollbar-thumb, .note-viewer-column::-webkit-scrollbar-thumb, .modal-scroll-content::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 10px;
    border: 2px solid var(--bg-color);
}
[data-theme="dark"] .scrollable::-webkit-scrollbar-thumb, [data-theme="dark"] body::-webkit-scrollbar-thumb, [data-theme="dark"] .notes-container::-webkit-scrollbar-thumb, [data-theme="dark"] .note-viewer-column::-webkit-scrollbar-thumb, [data-theme="dark"] .modal-scroll-content::-webkit-scrollbar-thumb {
    border: 2px solid var(--card-bg);
}
[data-theme="dark"] body::-webkit-scrollbar-thumb, [data-theme="dark"] .sidebar-nav::-webkit-scrollbar-thumb, [data-theme="dark"] .tag-list-sidebar::-webkit-scrollbar-thumb {
    border: 2px solid var(--sidebar-bg);
}
.scrollable::-webkit-scrollbar-thumb:hover, body::-webkit-scrollbar-thumb:hover, .sidebar-nav::-webkit-scrollbar-thumb:hover, .tag-list-sidebar::-webkit-scrollbar-thumb:hover, .notes-container::-webkit-scrollbar-thumb:hover, .note-viewer-column::-webkit-scrollbar-thumb:hover, .modal-scroll-content::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}

/* ============================================
   Media Queries (Mobile First Structure)
   ============================================ */

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

    /* Reset Modal Ancestor Transforms (Keep this just in case) */
    .modal#noteModal.visible,
    .modal#noteModal.visible .modal-content {
        transform: none !important;
        filter: none !important;
        perspective: none !important;
    }

    /* Hide Desktop Elements */
    .note-viewer-column {
        display: none;
    }
    #sort-options {
        display: none !important;
    }

    /* Show Mobile Elements */
    .menu-toggle-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 15px;
        left: 15px;
        background-color: var(--card-bg);
        border: 1px solid var(--border-color);
        border-radius: 50%;
        width: 45px;
        height: 45px;
        padding: 0;
        cursor: pointer;
        box-shadow: 0 2px 5px var(--shadow-color);
        z-index: 1090;
        transition: background-color 0.2s ease;
    }
    .mobile-sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 990;
        opacity: 0;
        transition: opacity 0.3s ease-in-out;
        pointer-events: none;
        display: block;
    }
    .mobile-sidebar-backdrop.visible {
        opacity: 1;
        pointer-events: auto;
    }
    .fab {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        background-color: var(--primary-btn);
        color: var(--primary-btn-text);
        border-radius: 50%;
        border: none;
        box-shadow: 0 4px 8px var(--shadow-color);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 900;
        cursor: pointer;
        transition: transform 0.2s ease, opacity 0.2s ease, background-color 0.2s ease, visibility 0.2s ease;
    }
    .mobile-top-header {
        display: block !important;
        text-align: center !important;
        padding-top: 70px;
        padding-bottom: 10px;
        padding-left: 15px;
        padding-right: 15px;
        width: 100%;
        background-color: var(--bg-color);
        flex-shrink: 0;
    }
    .mobile-top-header .logo-text {
        display: inline-block !important;
        font-size: 1.8em;
        font-weight: bold;
        color: var(--logo-color);
        margin: 0;
    }

    /* Mobile Sidebar */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        width: 280px;
        box-shadow: none;
        border-right: none;
        z-index: 1000;
        transition: transform 0.3s ease-in-out;
    }
    .sidebar.visible {
        transform: translateX(0);
        box-shadow: 2px 0 15px rgba(0, 0, 0, 0.2);
    }

    /* Mobile Notes List Header */
    .note-list-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    #search-input {
        width: 100%;
    }

    /* Mobile Notes Container */
    .notes-container {
        display: grid !important;
        gap: 10px;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        justify-content: center;
        padding: 10px;
        transform: none;
        will-change: auto;
    }

    /* --- Mobile Modal Layout --- */
    .modal#noteModal .modal-content {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column; /* Header, Scroll Area, Footer Area */
        overflow: hidden; /* Prevent overall scroll */
        position: relative; /* Context for JS positioning of footer area */
    }
    .modal#noteModal .modal-header {
        padding: 10px 15px;
        min-height: 50px; /* Adjust if needed */
        flex-shrink: 0; /* Fixed height */
        position: relative; /* Keep for z-index */
        z-index: 5;
        border-bottom: 1px solid var(--border-color); /* Add border back here */
        background-color: var(--card-bg); /* Header background */
        display: flex; /* Align items in header */
        justify-content: space-between;
        align-items: center;
    }
    .modal#noteModal .modal-header .modal-title-input {
        flex-grow: 1; /* Allow title to take space */
        margin-right: 10px;
        font-size: 1.2em;
    }
    .modal#noteModal .modal-header .header-actions {
        display: flex;
        align-items: center;
        gap: 10px;
        flex-shrink: 0;
    }

    /* --- Scrollable Content Area --- */
    .modal#noteModal .modal-scroll-content {
        flex-grow: 1; /* Takes space between header and footer area */
        overflow-y: auto; /* Allows THIS to scroll */
        -webkit-overflow-scrolling: touch;
        padding: 0; /* Reset */
        padding-bottom: 120px; /* Space for sticky footer */
        min-height: 0; /* Necessary for flex item with overflow */
        z-index: 1; /* Below header/footer */
        background-color: var(--card-bg); /* Set background for scroll area */
        transition: background-color 0.3s ease; /* Allow color transition */
        position: relative; /* For absolute positioning of editor */
    }

    /* Padding/styles for internal wrappers within scroll content */
    .modal#noteModal .modal-scroll-content > .shared-note-banner {
        margin: 0;
        padding: 10px 15px;
        flex-shrink: 0;
        border-bottom: 1px solid var(--border-color);
        /* Inherit background from scroll-content or set explicitly */
        background-color: color-mix(in srgb, var(--primary-btn) 10%, var(--card-bg) 90%);
    }
    [data-theme="dark"] .modal#noteModal .modal-scroll-content > .shared-note-banner {
        background-color: color-mix(in srgb, var(--primary-btn) 15%, var(--card-bg) 85%);
    }
    .modal#noteModal .modal-scroll-content > .editor-wrapper {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        padding: 10px 15px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* Ensure editor itself has correct styling */
    #modalNoteContent.modal-content-editable {
        min-height: 100%;
        width: 100%;
        padding-bottom: 120px; /* Match footer height */
    }
    /* Apply background color changes to the scroll content parent */
    .modal#noteModal .modal-scroll-content[style*="background-color"] {
        /* Style changes when color is applied */
    }
    .modal#noteModal .modal-scroll-content[style*="background-color"] #modalNoteContent.modal-content-editable {
        color: inherit; /* Inherit contrasting text color */
    }


    /* --- Sticky Footer Area (Container for Tags + Toolbar) --- */
    .modal#noteModal .modal-sticky-footer-area {
        flex-shrink: 0; /* Fixed height block */
        position: fixed; /* Changed from absolute to fixed */
        bottom: 0; /* Default position, JS will override */
        left: 0;
        right: 0;
        width: 100%;
        z-index: 10; /* Above scroll content */
        background-color: var(--sidebar-bg); /* Background for the whole area */
        border-top: 1px solid var(--border-color); /* Single border at the top */
        /* Apply transition for smooth JS movement */
        transition: bottom 0.15s ease-out, background-color 0.3s ease;
        /* Apply color changes */
        transform: translateZ(0); /* Force GPU acceleration */
        will-change: bottom; /* Optimize for animation */
    }
    /* Apply background color changes from JS to this area */
    .modal#noteModal .modal-sticky-footer-area[style*="background-color"] {
        /* Styles when color is applied */
        border-top-color: rgba(0,0,0,0.1); /* Adjust border contrast */
    }
    [data-theme="dark"] .modal#noteModal .modal-sticky-footer-area[style*="background-color"] {
        border-top-color: rgba(255,255,255,0.15);
    }


    /* --- Tags Section (Now inside sticky footer area) --- */
    .modal#noteModal .modal-tags-section {
        padding: 10px 15px 10px 15px; /* Adjust padding */
        background-color: transparent; /* Inherit from sticky area */
        transition: none;
        border-bottom: 1px solid var(--border-color); /* Separator line */
    }
    .modal#noteModal .modal-sticky-footer-area[style*="background-color"] .modal-tags-section {
        border-bottom-color: rgba(0,0,0,0.1); /* Adjust contrast */
        color: inherit; /* Inherit contrast */
    }
    [data-theme="dark"] .modal#noteModal .modal-sticky-footer-area[style*="background-color"] .modal-tags-section {
        border-bottom-color: rgba(255,255,255,0.15);
    }
    /* Ensure tag input elements inherit color */
    .modal#noteModal .modal-sticky-footer-area[style*="background-color"] .modal-tags-section .modal-tags-display .tag {
        /* Adjust tag appearance if needed on colored background */
        background-color: rgba(0,0,0,0.1);
        color: inherit;
    }
    [data-theme="dark"] .modal#noteModal .modal-sticky-footer-area[style*="background-color"] .modal-tags-section .modal-tags-display .tag {
        background-color: rgba(255,255,255,0.1);
    }
    .modal#noteModal .modal-sticky-footer-area[style*="background-color"] #modalTagInput {
        background-color: rgba(0,0,0,0.1);
        color: inherit;
        border-color: transparent;
    }
    .modal#noteModal .modal-sticky-footer-area[style*="background-color"] #modalTagInput::placeholder {
        color: inherit;
        opacity: 0.7;
    }
    [data-theme="dark"] .modal#noteModal .modal-sticky-footer-area[style*="background-color"] #modalTagInput {
        background-color: rgba(255,255,255,0.1);
    }


    /* --- Toolbar Footer (Now inside sticky footer area) --- */
    .modal#noteModal .modal-footer {
        padding: 8px 15px;
        min-height: 55px; /* Keep for consistency */
        border-top: none; /* Removed border, handled by tags section separator */
        background-color: transparent; /* Inherit from sticky area */
        position: static; /* Normal flow within sticky area */
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        transition: none;
    }
    /* Ensure footer elements inherit contrast color */
    .modal#noteModal .modal-sticky-footer-area[style*="background-color"] .modal-footer .tool-button,
    .modal#noteModal .modal-sticky-footer-area[style*="background-color"] .modal-footer .note-date {
        color: inherit;
    }
    .modal#noteModal .modal-sticky-footer-area[style*="background-color"] .modal-footer .tool-button.active {
        background-color: rgba(0,0,0,0.15); /* Adjust active state */
    }
    [data-theme="dark"] .modal#noteModal .modal-sticky-footer-area[style*="background-color"] .modal-footer .tool-button.active {
        background-color: rgba(255,255,255,0.15);
    }


    /* Horizontal scroll for actions */
    .modal#noteModal .modal-actions { /* Target within .modal-footer */
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
        flex-grow: 1;
        margin-right: 10px;
        scrollbar-width: thin;
        scrollbar-color: var(--scrollbar-thumb) transparent;
    }
    .modal#noteModal .modal-actions::-webkit-scrollbar {
        height: 4px;
        background: transparent;
    }
    .modal#noteModal .modal-actions::-webkit-scrollbar-thumb {
        background-color: var(--scrollbar-thumb);
        border-radius: 2px;
    }
    .modal#noteModal .modal-actions .tool-group {
        flex-shrink: 0;
    }

    /* Color palette positioning - relative to sticky footer area */
    .modal#noteModal .color-palette {
        /* Should be absolute relative to modal-sticky-footer-area */
        position: absolute;
        bottom: calc(100% + 5px); /* Position above the entire sticky area */
        right: 10px;
        left: auto;
        z-index: 15; /* Above sticky area */
        /* Base palette styles */
        background-color: var(--card-bg);
        border-radius: 5px;
        box-shadow: 0 2px 10px var(--shadow-color);
        padding: 10px;
        display: grid;
        grid-template-columns: repeat(6, 1fr);
        gap: 8px;
        border: 1px solid var(--border-color);
        width: max-content;
    }
    .modal#noteModal .color-palette.hidden {
        display: none !important;
    }

    /* --- Other Modals --- */
    /* Auth Modal Padding */
    .auth-modal .modal-content {
        max-width: 90%;
        padding: 20px;
    }

    /* Settings Modal Padding */
    .settings-modal .modal-content {
        max-width: 90%;
    }
    .settings-modal .modal-scroll-content {
        padding: 10px 20px 20px 20px;
    }
    .setting-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .setting-item label {
        margin-bottom: 3px;
    }
    .setting-item select, #upgradeSubscriptionBtn, #manageDataBtn {
        width: 100%;
        min-width: unset;
    }

    /* Share Modal Padding */
    .share-modal .modal-content {
        max-width: 90%;
    }

    /* Note item selection style hidden on mobile */
    .note-item.selected {
        background-color: var(--card-bg); /* Revert background */
        border-color: var(--border-color); /* Revert border */
        box-shadow: 0 1px 3px var(--shadow-color); /* Revert shadow */
    }

    /* Reduce animation complexity on mobile */
    .notes-container {
        transform: none;
        will-change: auto;
    }
    
    /* Simplify transitions on mobile */
    .note-item {
        transition: none;
    }
}

/* Desktop Layout */
@media (min-width: 769px) {
    /* Hide Mobile Elements */
    .menu-toggle-btn {
        display: none !important;
    }
    .mobile-sidebar-backdrop {
        display: none !important;
    }
    .fab {
        display: none !important;
    }
    .mobile-top-header {
        display: none !important;
    }

    .sidebar {
        position: static;
        transform: none;
        transition: none;
        width: 240px;
        flex-shrink: 0;
        box-shadow: none;
        border-right: 1px solid var(--border-color);
    }

    .main-content {
        flex-direction: row;
        overflow: visible;
    }

    .note-list-column {
        /* Increase width slightly */
        width: 340px; /* Changed from 320px */
        flex-shrink: 0;
        border-right: 1px solid var(--border-color);
        height: 100%;
        display: flex; /* Ensure flex context for children */
        flex-direction: column; /* Stack header and list */
        overflow: hidden; /* Keep this to prevent column scroll */
    }

    .note-viewer-column {
        display: block; /* Show viewer */
        flex-grow: 1;
        height: 100%;
        overflow-y: auto; /* Allow viewer content to scroll */
        padding: 25px 30px;
        min-width: 0;
    }

    /* Desktop Overrides for Header and its contents (Corrected - Single Block) */
    .note-list-header {
        flex-direction: row;
        align-items: center;
        gap: 10px;
        padding: 15px; /* Ensure padding exists */
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0; /* Prevent header from shrinking */
        /* overflow: visible; */ /* Usually not needed if width is sufficient */
    }
    #search-input {
        flex-grow: 1; /* Takes up most space */
        width: auto;
        font-size: 0.9em;
        height: 38px;
        box-sizing: border-box;
        min-width: 50px; /* Prevent shrinking too much */
    }
    #sort-options {
        display: inline-block !important;
        flex-shrink: 0; /* Prevent select from shrinking */
        width: auto;
        min-width: 170px;
        padding: 8px 35px 8px 12px;
        font-size: 0.9em;
        line-height: 1.4;
        box-sizing: border-box;
        cursor: pointer;
        vertical-align: middle;
        /* overflow: visible; */ /* Not needed on the element itself */
    }
    /* End Header Desktop Overrides */

    .notes-list-content-area {
        flex-grow: 1;
        min-height: 0; /* Allow shrinking */
        display: flex; /* Use flex for its children */
        flex-direction: column; /* Stack notes/empty state */
        overflow: hidden; /* Hide potential overflow from here down */
    }

    /* Desktop Override for Notes Container */
    .notes-container {
        display: block !important; /* Desktop list view */
        grid-template-columns: none;
        flex-grow: 1;
    }

    /* Desktop Note Item */
    .note-item {
        margin-bottom: 10px; /* Spacing for list */
        /* grid gap doesn't apply */
    }

    /* Desktop Empty State Positioning */
    .empty-state {
        position: static; /* Override potential absolute positioning if any */
        height: auto; /* Let flexbox determine height naturally */
        flex-grow: 1;
    }

    /* Show placeholder button in viewer */
    .new-note-placeholder-btn {
        display: inline;
    }
}

/* Hide stray icons potentially added by extensions */
body > .material-icons {
    display: none;
}

/* Add loading indicator styles */
.notes-loading-indicator {
    display: none;
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

.notes-loading-indicator.visible {
    display: block;
}

/* Optimize scroll performance */
.scrollable {
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scroll-behavior: smooth; /* Smooth scrolling on modern browsers */
    overscroll-behavior: contain; /* Prevent scroll chaining */
}

/* Add these media queries for better mobile performance */
@media (max-width: 768px) {
    .notes-container {
        /* Reduce animation complexity on mobile */
        transform: none;
        will-change: auto;
    }
    
    .note-item {
        /* Simplify transitions on mobile */
        transition: none;
    }
}

/* Subscription Plans */
.subscription-plans {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.plan-card {
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px var(--shadow-color);
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.plan-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-color);
}

.plan-badge {
    position: absolute;
    top: -10px;
    right: 20px;
    background-color: var(--primary-btn);
    color: var(--primary-btn-text);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
}

.plan-card h4 {
    margin: 0 0 10px 0;
    color: var(--text-color);
    font-size: 1.2em;
}

.plan-price {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 15px;
}

.plan-price span {
    font-size: 0.6em;
    color: var(--text-secondary);
    font-weight: normal;
}

.plan-features {
    list-style: none;
    padding: 0;
    margin: 0 0 20px 0;
}

.plan-features li {
    padding: 5px 0;
    color: var(--text-color);
    display: flex;
    align-items: center;
}

.plan-features li::before {
    content: '✓';
    color: var(--primary-btn);
    margin-right: 10px;
    font-weight: bold;
}

.select-plan-btn {
    width: 100%;
    padding: 10px;
    background-color: var(--primary-btn);
    color: var(--primary-btn-text);
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

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

/* Premium Features */
.premium-feature {
    position: relative;
}

.premium-feature::after {
    content: '★';
    position: absolute;
    top: -5px;
    right: -5px;
    color: var(--primary-btn);
    font-size: 0.8em;
}

.premium-feature.requires-upgrade {
    opacity: 0.6;
    cursor: help;
}