:root {
    --bg-color: #f0f2f5;
    --bg-image: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    --text-color: #202124;
    --card-bg: rgba(255, 255, 255, 0.4);
    --border-color: rgba(255, 255, 255, 0.3);
    --primary-color: #1a73e8;
    --primary-hover: #1557b0;
    --header-bg: rgba(255, 255, 255, 0.3);
    --input-bg: rgba(255, 255, 255, 0.5);
    --note-default: rgba(255, 255, 255, 0.3);
    --note-red: rgba(242, 139, 130, 0.5);
    --note-orange: rgba(251, 188, 4, 0.5);
    --note-yellow: rgba(255, 244, 117, 0.5);
    --note-green: rgba(204, 255, 144, 0.5);
    --note-blue: rgba(203, 240, 248, 0.5);
    --note-purple: rgba(215, 174, 251, 0.5);
    --nav-active: #1a73e8;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #202124;
        --bg-image: linear-gradient(135deg, #1f1c2c 0%, #928DAB 100%);
        --text-color: #e8eaed;
        --card-bg: rgba(45, 46, 48, 0.4);
        --border-color: rgba(255, 255, 255, 0.1);
        --primary-color: #8ab4f8;
        --primary-hover: #aecbfa;
        --header-bg: rgba(32, 33, 36, 0.5);
        --input-bg: rgba(82, 83, 85, 0.5);
        --note-default: rgba(45, 46, 48, 0.5);
        --note-red: rgba(92, 43, 41, 0.5);
        --note-orange: rgba(97, 74, 25, 0.5);
        --note-yellow: rgba(99, 93, 25, 0.5);
        --note-green: rgba(52, 89, 32, 0.5);
        --note-blue: rgba(22, 80, 75, 0.5);
        --note-purple: rgba(66, 39, 94, 0.5);
    }
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    background-image: var(--bg-image);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--text-color);
    margin: 0;
    padding: 0;
    line-height: 1.5;
    min-height: 100vh;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    color: inherit;
}

.app-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.header-bottom {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.header-left .logo {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-color);
}

.search-container {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}
.advanced-search-filters {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}
.advanced-search {
    font-size: 13px;
    opacity: 0.8;
    white-space: nowrap;
    cursor: pointer;
}
.sort-select, .date-input {
    padding: 8px;
    border-radius: 8px;
    border: none;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 14px;
    outline: none;
    cursor: pointer;
}
.date-field {
    display: flex;
    flex: 1 1 220px;
    min-width: 0;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
}
.date-input {
    width: 100%;
    min-width: 0;
}

#search-input {
    flex: 1;
    min-width: 0;
    width: auto;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 16px;
}
#search-input:focus {
    outline: none;
    background-color: var(--card-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.header-right {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}
.icon-btn:hover {
    background-color: rgba(150,150,150,0.2);
}

.logout-btn {
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    width: auto;
    padding: 0 16px;
    border-radius: 8px;
    color: #ffffff;
    background-color: var(--primary-color);
}
.logout-btn:hover {
    background-color: var(--primary-hover);
}

.app-nav {
    display: flex;
    padding: 0 16px;
    gap: 16px;
    border-bottom: 1px solid var(--border-color);
    background-color: transparent;
}

.tab {
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
    opacity: 0.7;
    border-bottom: 3px solid transparent;
}
.tab.active {
    opacity: 1;
    color: var(--nav-active);
    border-bottom-color: var(--nav-active);
}

.app-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px;
}

.create-note-container {
    max-width: 600px;
    margin: 0 auto 32px;
    background-color: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    overflow: hidden;
    transition: box-shadow 0.2s;
}
.create-note-container:focus-within {
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

#create-note-collapsed {
    padding: 12px 16px;
    color: var(--text-color);
    opacity: 0.7;
    cursor: text;
    font-size: 16px;
}

#create-note-form, #edit-note-form {
    display: flex;
    flex-direction: column;
}
#create-note-form input, #edit-note-form input {
    padding: 12px 16px;
    border: none;
    font-size: 16px;
    font-weight: 600;
    background: transparent;
    color: var(--text-color);
}
#create-note-form textarea, #edit-note-form textarea {
    padding: 12px 16px;
    border: none;
    font-size: 16px;
    resize: none;
    background: transparent;
    color: var(--text-color);
    min-height: 100px;
    max-height: 50vh;
}
#create-note-form input:focus, #create-note-form textarea:focus,
#edit-note-form input:focus, #edit-note-form textarea:focus {
    outline: none;
}

.form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
}

.char-count {
    font-size: 12px;
    opacity: 0.7;
}
.char-count.warning {
    color: #d93025;
    opacity: 1;
    font-weight: bold;
}

.form-actions {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
}
.btn:hover {
    background-color: rgba(150,150,150,0.1);
}
.btn-primary {
    color: var(--primary-color);
}
.btn-primary:hover {
    background-color: rgba(26, 115, 232, 0.1);
}

.notes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    align-items: start;
}

.note-card {
    background-color: var(--note-default);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    position: relative;
    transition: box-shadow 0.2s, transform 0.2s;
    display: flex;
    flex-direction: column;
}
.note-card:hover {
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}
.note-card.color-default { background-color: var(--note-default); }
.note-card.color-red { background-color: var(--note-red); }
.note-card.color-orange { background-color: var(--note-orange); }
.note-card.color-yellow { background-color: var(--note-yellow); }
.note-card.color-green { background-color: var(--note-green); }
.note-card.color-blue { background-color: var(--note-blue); }
.note-card.color-purple { background-color: var(--note-purple); }

.note-title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 8px;
    word-wrap: break-word;
}
.note-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 15px;
    max-height: 250px;
    overflow: hidden;
    position: relative;
}
.note-content.expanded {
    max-height: none;
}
.note-expand-btn {
    display: none;
    color: var(--primary-color);
    font-size: 14px;
    padding: 4px 0;
    margin-top: 4px;
    font-weight: 500;
}
.note-content.overflow + .note-expand-btn {
    display: block;
}

.note-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
    opacity: 0.6;
    transition: opacity 0.2s;
}
.note-card:hover .note-actions {
    opacity: 1;
}

.action-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    opacity: 0.8;
}
.action-btn:hover {
    background-color: rgba(150,150,150,0.2);
    opacity: 1;
}

.note-copy-btn {
    background-color: rgba(26,115,232,0.1);
    color: var(--primary-color);
    opacity: 1;
    margin-right: auto;
    width: auto;
    padding: 0 12px;
    border-radius: 18px;
    font-size: 14px;
    font-weight: 500;
}
.note-copy-btn:hover {
    background-color: rgba(26,115,232,0.2);
}

.note-timestamp {
    font-size: 11px;
    opacity: 0.5;
    margin-top: 12px;
    text-align: right;
}

.color-picker {
    position: absolute;
    bottom: 40px;
    right: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    display: none;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 10;
}
.color-picker.active {
    display: grid;
}
.color-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    cursor: pointer;
}
.color-dot:hover {
    transform: scale(1.1);
}

.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal.active {
    display: flex;
}
.modal-content {
    background-color: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 600px;
    border-radius: 8px;
    margin: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: #323232;
    color: white;
    padding: 12px 24px;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2000;
    font-size: 14px;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
}

.fab {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--card-bg);
    color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    font-size: 32px;
    align-items: center;
    justify-content: center;
    z-index: 90;
}

@media (max-width: 600px) {
    .create-note-container {
        display: none; /* Hide top bar on mobile */
    }
    .fab {
        display: flex;
    }
    .notes-grid {
        grid-template-columns: 1fr;
    }
    .note-actions {
        opacity: 1;
    }
    .note-copy-btn {
        padding: 8px 16px;
        font-size: 16px;
    }
    .action-btn {
        width: 44px;
        height: 44px;
    }
}

#create-dialog {
    width: calc(100% - 32px);
    max-width: 560px;
    max-height: calc(100dvh - 32px);
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--bg-color);
    color: var(--text-color);
    box-shadow: 0 16px 48px rgba(0,0,0,0.35);
    overflow: auto;
}
#create-dialog::backdrop {
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
}
body:has(#create-dialog[open]) {
    overflow: hidden;
}
#create-dialog #note-content {
    min-height: 140px;
    max-height: 40dvh;
    overflow-y: auto;
}
#create-dialog .form-footer {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
}
#create-dialog .form-actions {
    margin-left: auto;
    gap: 4px;
}
#create-dialog .btn {
    min-height: 44px;
    padding: 8px 10px;
}
