/* Using CSS variables for easy theming */
:root {
    --bg-color: #f0f2f5;
    --text-color: #333;
    --card-bg-color: #ffffff;
    --card-border: #e0e0e0;
    --primary-color: #007bff;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    --hover-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

body.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg-color: #1e1e1e;
    --card-border: #333;
    --primary-color: #90caf9;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    --hover-shadow: 0 6px 12px rgba(0, 0, 0, 0.6);
}

/* Base transition for all elements to ensure smooth state changes */
* {
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

/* Base Styles */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 20px;
}

/* Header and controls */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--card-border);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* --- ENHANCED SEARCH BAR STYLES --- */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
    width: 250px;
    z-index: 100;
}

#search-input {
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 8px 30px 8px 15px;
    background-color: var(--card-bg-color);
    color: var(--text-color);
    width: 100%;
}

#search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

.search-box .search-icon {
    position: absolute;
    right: 15px;
    color: #aaa;
    pointer-events: none;
}

.clear-search {
    position: absolute;
    right: 15px;
    color: #aaa;
    cursor: pointer;
    opacity: 0.7;
    display: none;
}

.clear-search:hover {
    opacity: 1;
}

/* --- New styles for search suggestions --- */
.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
    background-color: var(--card-bg-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 5px;
    margin-top: 5px;
    z-index: 100;
}

.suggestion-item {
    padding: 10px;
    cursor: pointer;
    border-radius: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.suggestion-item:hover {
    background-color: var(--bg-color);
}

.dark-mode-toggle {
    background: none;
    border: 1px solid var(--card-border);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    color: var(--text-color);
    position: relative;
    overflow: hidden;
}

.dark-mode-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Main Content and Sidebar */
.main-content {
    display: flex;
    flex: 1;
    gap: 20px;
}

.sidebar {
    width: 250px;
    background-color: var(--card-bg-color);
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.tags-list h3 {
    margin-top: 0;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 10px;
}

.tag {
    display: inline-block;
    background-color: var(--primary-color);
    color: white;
    padding: 5px 10px;
    border-radius: 20px;
    margin: 5px;
    cursor: pointer;
}

.tag:hover, .tag.active {
    background-color: #0056b3;
    transform: scale(1.05);
}

/* Notes Section */
.notes-section {
    flex: 1;
}

/* Note Editor (with Rich Text) */
.note-editor {
    background-color: var(--card-bg-color);
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#note-title, #note-tags {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    background-color: var(--bg-color);
    color: var(--text-color);
}

#note-title:focus,
#note-tags:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
    outline: none;
}

.rich-text-editor {
    min-height: 150px;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 10px;
    overflow-y: auto;
    background-color: var(--bg-color);
    position: relative;
}

.rich-text-editor:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

[contenteditable]:empty:before {
    content: attr(data-placeholder);
    color: #999;
    pointer-events: none;
    display: block;
}

#add-note-btn {
    padding: 12px 20px;
    border: none;
    background-color: var(--primary-color);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
}

#add-note-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#add-note-btn:active {
    transform: translateY(1px) scale(0.98);
}

/* Notes Container and individual notes */
.notes-container {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.note {
    background-color: var(--card-bg-color);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--shadow);
    word-wrap: break-word;
    position: relative;
    opacity: 0;
    transform: translateY(20px);
}

.note.fade-in-on-scroll {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.note:hover {
    box-shadow: var(--hover-shadow);
}

.note h3 {
    margin-top: 0;
}

.note-tags {
    margin-top: 10px;
    border-top: 1px solid var(--card-border);
    padding-top: 10px;
}

.note-tags .tag-in-note {
    display: inline-block;
    background-color: #e9e9e9;
    color: #555;
    padding: 3px 8px;
    border-radius: 15px;
    font-size: 12px;
    margin: 2px;
}

body.dark-mode .note-tags .tag-in-note {
    background-color: #333;
    color: #ccc;
}

.note-actions {
    margin-top: 15px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.note-actions button {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    opacity: 0.7;
}

.note-actions button:hover {
    opacity: 1;
    color: var(--primary-color);
    transform: scale(1.1);
}

.note-actions button:active {
    transform: translateY(1px) scale(0.98);
}

/* Inline List Items */
.note-content .list-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 20px;
    list-style: none;
    padding: 0;
}

.note-content .list-item {
    display: flex;
    align-items: center;
    position: relative;
}

.note-content .list-item::before {
    content: "•";
    color: var(--primary-color);
    font-weight: bold;
    display: inline-block;
    width: 1em;
    margin-right: 5px;
}