/* General Styling */
:root {
    /* Google-inspired Light Mode Colors */
    --bg-light: #f8f9fa; /* Lighter background for main area */
    --sidebar-bg-light: #ffffff; /* White sidebar background */
    --text-light: #202124; /* Darker, clear text */
    --text-secondary-light: #5f6368; /* Secondary text color */
    --border-light: #dadce0; /* Subtle border color */
    --app-shadow-light: 0 6px 20px rgba(60, 64, 67, 0.15); /* More pronounced app shadow */
    --sidebar-shadow-light: 2px 0 8px rgba(60, 64, 67, 0.08); /* Subtle sidebar shadow */
    --toolbar-shadow-light: 0 2px 5px rgba(60, 64, 67, 0.08); /* Toolbar shadow */
    --hover-overlay-light: rgba(0, 0, 0, 0.04); /* Light hover effect */
    --active-overlay-light: rgba(26, 115, 232, 0.1); /* Active item background */

    /* Google-inspired Dark Mode Colors */
    --bg-dark: #202124; /* Deep dark background */
    --sidebar-bg-dark: #2c2d30; /* Slightly lighter dark sidebar */
    --text-dark: #e8eaed; /* Light text for dark mode */
    --text-secondary-dark: #9aa0a6; /* Secondary text for dark mode */
    --border-dark: #5f6368; /* Dark border color */
    --app-shadow-dark: 0 6px 20px rgba(0, 0, 0, 0.4); /* More pronounced app shadow */
    --sidebar-shadow-dark: 2px 0 8px rgba(0, 0, 0, 0.2); /* Subtle sidebar shadow */
    --toolbar-shadow-dark: 0 2px 5px rgba(0, 0, 0, 0.2); /* Toolbar shadow */
    --hover-overlay-dark: rgba(255, 255, 255, 0.08); /* Dark hover effect */
    --active-overlay-dark: rgba(138, 180, 248, 0.16); /* Active item background */

    /* Universal Colors */
    --primary-color: #1a73e8; /* Google Blue */
    --primary-hover: #1765cf; /* Darker blue on hover */
    --danger-color: #d93025; /* Red for delete actions */
    --danger-hover: #c5221f;
    --focus-ring-color: #8ab4f8; /* Accessible focus ring */

    /* Spacing & Sizing */
    --sidebar-width: 280px;
    --border-radius-lg: 12px; /* Larger border-radius for main app */
    --border-radius-md: 8px; /* Medium border-radius for notes/toolbar */
    --border-radius-sm: 6px; /* Small border-radius for buttons */
}

/* Global Reset & Base Styles */
* {
    box-sizing: border-box;
    /* Focus styles for accessibility */
    &:focus-visible {
        outline: 2px solid var(--focus-ring-color);
        outline-offset: 2px;
        border-radius: var(--border-radius-sm); /* Ensure outline matches button shape */
    }
}

body {
    font-family: 'Roboto', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    min-height: 100vh; /* Use min-height to ensure full coverage even with margin */
    overflow: hidden; /* Ensure no body scrollbars */
    transition: background-color 0.3s ease, color 0.3s ease;
    font-size: 16px; /* Base font size */
    line-height: 1.5;
}

/* Light Mode Theme */
body.light-mode {
    background-color: var(--bg-light);
    color: var(--text-light);
}

body.light-mode #sidebar {
    background-color: var(--sidebar-bg-light);
    border-right: 1px solid var(--border-light);
    box-shadow: var(--sidebar-shadow-light);
}

body.light-mode #note-title,
body.light-mode #note-content {
    color: var(--text-light);
}

body.light-mode .sidebar-header h2 {
    color: var(--text-light);
}

body.light-mode #theme-toggle .material-icons {
    color: var(--text-secondary-light);
}
body.light-mode #theme-toggle:hover {
    background-color: var(--hover-overlay-light);
}

body.light-mode .note-item {
    color: var(--text-light);
    border-bottom: 1px solid var(--border-light); /* Subtle separator */
}

body.light-mode .note-item:hover {
    background-color: var(--hover-overlay-light);
}

body.light-mode .note-item.active {
    background-color: var(--active-overlay-light);
    border-left: 4px solid var(--primary-color);
    color: var(--primary-color); /* Active note text color */
}
body.light-mode .note-item.active .note-item-content {
    font-weight: 500; /* Make active note title slightly bolder */
}

body.light-mode .note-item .note-drag-handle,
body.light-mode .note-item .delete-note {
    color: var(--text-secondary-light);
}
body.light-mode .note-item:hover .delete-note {
    background-color: var(--hover-overlay-light);
}

body.light-mode #editor-toolbar {
    background-color: var(--sidebar-bg-light); /* Matches sidebar for continuity */
    border-bottom: 1px solid var(--border-light);
    box-shadow: var(--toolbar-shadow-light);
}

body.light-mode .tool-button {
    color: var(--text-secondary-light);
}
body.light-mode .tool-button:hover {
    background-color: var(--hover-overlay-light);
}

body.light-mode #note-title::placeholder,
body.light-mode #note-content::placeholder {
    color: var(--text-secondary-light);
}

body.light-mode #no-note-selected {
    color: var(--text-secondary-light);
}

/* Dark Mode Theme */
body.dark-mode {
    background-color: var(--bg-dark);
    color: var(--text-dark);
}

body.dark-mode #sidebar {
    background-color: var(--sidebar-bg-dark);
    border-right: 1px solid var(--border-dark);
    box-shadow: var(--sidebar-shadow-dark);
}

body.dark-mode #note-title,
body.dark-mode #note-content {
    color: var(--text-dark);
}

body.dark-mode .sidebar-header h2 {
    color: var(--text-dark);
}

body.dark-mode #theme-toggle .material-icons {
    color: var(--text-secondary-dark);
}
body.dark-mode #theme-toggle:hover {
    background-color: var(--hover-overlay-dark);
}

body.dark-mode .note-item {
    color: var(--text-dark);
    border-bottom: 1px solid var(--border-dark);
}

body.dark-mode .note-item:hover {
    background-color: var(--hover-overlay-dark);
}

body.dark-mode .note-item.active {
    background-color: var(--active-overlay-dark);
    border-left: 4px solid var(--primary-color);
    color: var(--primary-color);
}
body.dark-mode .note-item.active .note-item-content {
    font-weight: 500;
}

body.dark-mode .note-item .note-drag-handle,
body.dark-mode .note-item .delete-note {
    color: var(--text-secondary-dark);
}
body.dark-mode .note-item:hover .delete-note {
    background-color: var(--hover-overlay-dark);
}

body.dark-mode #editor-toolbar {
    background-color: var(--sidebar-bg-dark);
    border-bottom: 1px solid var(--border-dark);
    box-shadow: var(--toolbar-shadow-dark);
}

body.dark-mode .tool-button {
    color: var(--text-secondary-dark);
}
body.dark-mode .tool-button:hover {
    background-color: var(--hover-overlay-dark);
}

body.dark-mode #note-title::placeholder,
body.dark-mode #note-content::placeholder {
    color: var(--text-secondary-dark);
}

body.dark-mode #no-note-selected {
    color: var(--text-secondary-dark);
}

/* App Layout */
#app {
    display: flex;
    flex: 1;
    max-width: 1440px; /* Slightly wider max-width */
    margin: 20px auto; /* Center the app on larger screens */
    border-radius: var(--border-radius-lg);
    overflow: hidden; /* Ensures shadows and borders are contained */
    box-shadow: var(--app-shadow-light); /* Overall app shadow */
}
body.dark-mode #app {
    box-shadow: var(--app-shadow-dark);
}

#sidebar {
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    padding: 24px; /* Increased padding for more spacious feel */
    box-sizing: border-box;
    flex-shrink: 0;
    position: relative;
    overflow-y: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

#sidebar::-webkit-scrollbar {
    display: none;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 18px; /* More padding below header */
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border-light);
}
body.dark-mode .sidebar-header {
    border-bottom: 1px solid var(--border-dark);
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.75em; /* Larger, more prominent heading */
    font-weight: 500;
    letter-spacing: -0.5px;
}

#theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.6em; /* Slightly larger icon */
    padding: 10px; /* More padding for click target */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.1s ease;
}
#theme-toggle:active {
    transform: scale(0.95);
}

/* Button Styles */
.action-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 24px; /* More generous padding */
    border-radius: var(--border-radius-md); /* Use md radius for buttons */
    cursor: pointer;
    font-size: 1.1em; /* Slightly larger font */
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px; /* More space between icon and text */
    justify-content: center;
    margin-top: 10px;
    margin-bottom: 30px; /* More separation from notes list */
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15); /* Stronger initial shadow */
}

.action-button:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); /* Deeper shadow on hover */
}
.action-button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Notes List */
#notes-list {
    flex-grow: 1;
    overflow-y: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
    padding-top: 10px;
}

#notes-list::-webkit-scrollbar {
    display: none;
}

.note-item {
    padding: 14px 18px; /* Adjusted padding */
    margin-bottom: 6px; /* Slightly less margin for denser list */
    cursor: pointer;
    border-radius: var(--border-radius-sm); /* Smaller radius for individual items */
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background-color 0.2s ease, border-left 0.2s ease, color 0.2s ease;
    position: relative;
    user-select: none;
    min-height: 52px; /* Increased min-height for better usability */
    border-left: 4px solid transparent; /* Placeholder for active state */
}

.note-item .note-drag-handle {
    cursor: grab;
    margin-right: 5px;
    opacity: 0.4; /* Slightly more visible by default */
    transition: opacity 0.2s ease;
    font-size: 1.3em; /* Larger drag icon */
}

.note-item:hover .note-drag-handle {
    opacity: 0.8; /* More visible on hover */
}

.note-item.dragging {
    opacity: 0.6;
    background-color: var(--active-overlay-light); /* Consistent dragging feedback */
    border: 1px dashed var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25); /* More prominent shadow when dragging */
}
body.dark-mode .note-item.dragging {
    background-color: var(--active-overlay-dark);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.note-item-content {
    flex-grow: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 1em; /* Base font size */
    padding-right: 30px;
}

.note-item .delete-note {
    background: none;
    border: none;
    opacity: 0;
    cursor: pointer;
    font-size: 1.2em; /* Larger delete icon */
    padding: 8px; /* More padding */
    border-radius: 50%;
    transition: opacity 0.2s ease, background-color 0.2s ease, transform 0.1s ease;
    position: absolute;
    right: 12px; /* Slightly adjusted position */
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary-light);
}
body.dark-mode .note-item .delete-note {
    color: var(--text-secondary-dark);
}


.note-item:hover .delete-note {
    opacity: 1;
}
.note-item .delete-note:hover {
    color: var(--danger-color);
    background-color: rgba(217, 48, 37, 0.1);
}
.note-item .delete-note:active {
    transform: translateY(-50%) scale(0.9); /* Subtle press effect */
}

/* Sub-note indentation */
.note-item.level-1 { padding-left: 40px; } /* Even deeper indentation */
.note-item.level-2 { padding-left: 60px; }
.note-item.level-3 { padding-left: 80px; }


/* Editor Area */
#editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 30px 40px; /* Generous padding for content */
    box-sizing: border-box;
    position: relative;
    overflow-y: auto;
}

#no-note-selected {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    opacity: 0.7; /* Slightly less opaque for better integration */
}

#no-note-selected .large-icon {
    font-size: 7em; /* Even larger icon */
    margin-bottom: 30px;
    color: var(--border-light);
}
body.dark-mode #no-note-selected .large-icon {
    color: var(--border-dark);
}

#no-note-selected h1 {
    font-size: 2.2em; /* More impactful heading */
    font-weight: 400;
    line-height: 1.3;
    max-width: 80%; /* Prevent text from being too wide */
}


#note-editor {
    flex: 1;
}

#note-title {
    width: 100%;
    padding: 18px 0; /* More vertical padding */
    margin-bottom: 20px;
    font-size: 2.8em; /* Even larger title */
    font-weight: 700;
    border: none;
    outline: none;
    background: transparent;
    border-bottom: 2px solid var(--border-light); /* Thicker subtle separator */
    transition: border-color 0.2s ease;
}
body.dark-mode #note-title {
    border-bottom: 2px solid var(--border-dark);
}
#note-title:focus {
    border-bottom-color: var(--primary-color); /* Highlight on focus */
}

#editor-toolbar {
    display: flex;
    gap: 10px; /* More space between buttons */
    padding: 12px 18px;
    border-radius: var(--border-radius-md);
    margin-bottom: 25px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    box-shadow: var(--toolbar-shadow-light); /* Subtle toolbar shadow */
}
body.dark-mode #editor-toolbar {
    box-shadow: var(--toolbar-shadow-dark);
}

.tool-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px 12px; /* Horizontal padding for better click area */
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.1s ease;
}
.tool-button:active {
    transform: scale(0.95);
}

.tool-button .material-icons {
    font-size: 1.3em; /* Slightly larger icons */
}

.tool-button .heading-text {
    font-size: 0.9em;
    font-weight: 500;
}

/* Specific delete button in toolbar */
#delete-note-button {
    margin-left: auto; /* Push to the right */
    color: var(--danger-color);
}
#delete-note-button:hover {
    background-color: rgba(217, 48, 37, 0.1);
}


#note-content {
    flex-grow: 1;
    padding: 25px; /* Generous padding */
    border: none;
    outline: none;
    font-size: 1.2em; /* Slightly larger body text */
    line-height: 1.8; /* Improved readability */
    background: transparent;
    overflow-y: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
    min-height: 200px;
    caret-color: var(--primary-color); /* Cursor color */
}

#note-content::-webkit-scrollbar {
    display: none;
}

/* Styling for content within contenteditable */
#note-content p {
    margin: 1em 0;
}
#note-content h1 {
    font-size: 2em; /* H1 within content */
    font-weight: 600;
    margin: 0.8em 0;
    line-height: 1.2;
}
#note-content h2 {
    font-size: 1.6em; /* H2 within content */
    font-weight: 600;
    margin: 0.7em 0;
    line-height: 1.3;
}
#note-content ul {
    margin: 1em 0;
    padding-left: 2em;
    list-style-type: disc;
}
#note-content li {
    margin-bottom: 0.5em;
}
#note-content b, #note-content strong {
    font-weight: 700;
}
#note-content i, #note-content em {
    font-style: italic;
}
#note-content u {
    text-decoration: underline;
}


#note-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 20px 0; /* More spacing around images */
    border-radius: var(--border-radius-sm);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* Slightly stronger image shadow */
}

/* Placeholder styling for contenteditable */
[contenteditable]:empty:before {
    content: attr(placeholder);
    color: var(--text-secondary-light);
    pointer-events: none;
    display: block;
}
body.dark-mode [contenteditable]:empty:before {
    color: var(--text-secondary-dark);
}

/* Responsive Adjustments */
@media (max-width: 1024px) {
    #app {
        margin: 15px auto; /* Adjust margin */
    }
    #sidebar {
        width: 250px; /* Slightly narrower sidebar */
        padding: 20px;
    }
    #editor-area {
        padding: 25px;
    }
    #note-title {
        font-size: 2.4em;
    }
    #no-note-selected h1 {
        font-size: 1.8em;
    }
}

@media (max-width: 768px) {
    body {
        min-height: 100vh; /* Ensure full viewport height */
    }
    #app {
        flex-direction: column;
        margin: 0;
        border-radius: 0;
        height: 100%; /* Take full height on mobile */
        max-width: 100%;
        box-shadow: none; /* No app shadow on mobile */
    }
    #sidebar {
        width: 100%;
        height: auto;
        max-height: 200px; /* Limit sidebar height on small screens */
        border-right: none;
        border-bottom: 1px solid var(--border-light);
        padding-bottom: 15px;
        box-shadow: none; /* No sidebar shadow on mobile */
    }
    body.dark-mode #sidebar {
        border-bottom: 1px solid var(--border-dark);
    }
    .sidebar-header {
        border-bottom: none;
        margin-bottom: 10px;
        padding-bottom: 10px;
    }
    #add-note-button {
        width: calc(100% - 48px); /* Adjust for padding */
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 20px;
    }
    #notes-list {
        display: none; /* Hide notes list by default on small screens if not active */
    }
    #editor-area {
        padding: 20px;
        flex: 1;
        overflow-y: auto;
    }
    #note-title {
        font-size: 2em;
        padding: 12px 0;
        margin-bottom: 15px;
    }
    #no-note-selected .large-icon {
        font-size: 5em;
        margin-bottom: 20px;
    }
    #no-note-selected h1 {
        font-size: 1.6em;
    }
    #editor-toolbar {
        padding: 10px 15px;
        gap: 8px;
        margin-bottom: 20px;
        box-shadow: var(--toolbar-shadow-light); /* Keep toolbar shadow */
    }
    body.dark-mode #editor-toolbar {
        box-shadow: var(--toolbar-shadow-dark);
    }
    .tool-button {
        padding: 8px 10px;
    }
    #note-content {
        font-size: 1.1em;
        line-height: 1.7;
        padding: 20px 0;
    }
}

@media (max-width: 480px) {
    #sidebar {
        padding: 15px;
        max-height: 160px;
    }
    .sidebar-header h2 {
        font-size: 1.5em;
    }
    #add-note-button {
        font-size: 1em;
        padding: 12px 18px;
        gap: 8px;
        width: calc(100% - 30px);
    }
    #editor-area {
        padding: 15px;
    }
    #note-title {
        font-size: 1.8em;
        padding: 10px 0;
        margin-bottom: 10px;
    }
    #editor-toolbar {
        flex-direction: row;
        justify-content: center; /* Center toolbar buttons */
        padding: 8px 10px;
        gap: 6px;
        margin-bottom: 15px;
    }
    .tool-button {
        font-size: 0.9em;
        padding: 6px 8px;
    }
    #delete-note-button {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        margin-left: 0; /* Reset margin-left auto */
    }
    #note-content {
        padding: 15px 0;
    }
    #no-note-selected h1 {
        font-size: 1.4em;
    }
}