@import url('../shared/global.css');

:root {
    --sidebar-width: 280px;
    --transition-speed: 0.2s;
    --note-bg: var(--md-sys-color-surface-container-lowest, #ffffff);
    --note-border: var(--md-sys-color-outline-variant);
}

body {
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-top: 64px; /* Account for fixed topbar */
}

/* Main content area */
#main-content {
    margin-left: var(--sidebar-width);
    margin-top: 0;
    height: calc(100vh - 64px);
    overflow-y: auto;
    flex: 1;
}

/* When sidebar is collapsed */
body.sidebar-collapsed #main-content {
    margin-left: 0;
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    background-color: var(--workspace-sidebar-bg, #ffffff);
    display: flex;
    flex-direction: column;
    padding: 16px;
    height: calc(100vh - 64px); /* Account for topbar */
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    z-index: 900;
}

.sidebar-content {
    flex-grow: 1;
    overflow-y: auto;
}



.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 4px;
    cursor: pointer;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    transition: background-color var(--transition-speed);
}

.nav-item:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.nav-item.active {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.nav-item .material-symbols-rounded {
    font-size: 24px;
}

/* Sidebar Footer Buttons */
.sidebar-footer {
    padding-top: 8px;
    border-top: 1px solid var(--md-sys-color-outline-variant, #e0e0e0);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 100px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    width: 100%;
    text-align: left;
    transition: background-color 0.2s;
}

.sidebar-btn:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.sidebar-btn.primary {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.sidebar-btn.primary:hover {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.sidebar-btn .material-symbols-rounded {
    font-size: 22px;
}


#main-content {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px;
    background-color: var(--md-sys-color-surface);
}

/* Note Input */
#note-input-container {
    width: 100%;
    max-width: 600px;
    background-color: var(--md-sys-color-surface-container-lowest) !important;
    border: 1px solid var(--note-border);
    border-radius: 8px;
    box-shadow: 0 1px 2px color-mix(in srgb, var(--md-sys-color-shadow) 10%, transparent), 0 2px 4px color-mix(in srgb, var(--md-sys-color-shadow) 10%, transparent);
    margin-bottom: 32px;
    transition: box-shadow 0.3s, background-color 0.3s;
}

#note-input-container:focus-within,
#note-input-container:has(#note-input-expanded[style*="flex"]) {
    box-shadow: 0 1px 3px color-mix(in srgb, var(--md-sys-color-shadow) 20%, transparent), 0 4px 12px color-mix(in srgb, var(--md-sys-color-shadow) 15%, transparent);
    background-color: var(--md-sys-color-surface-container-lowest);
}

#note-input-collapsed {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: text;
}

#note-input-collapsed span {
    color: var(--md-sys-color-outline);
    font-weight: 500;
}

.input-actions {
    display: flex;
    gap: 8px;
    color: var(--md-sys-color-on-surface-variant);
}

.input-actions .material-symbols-rounded {
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
}

.input-actions .material-symbols-rounded:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
}

#note-input-expanded {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    background-color: var(--md-sys-color-surface-container-lowest);
    border-radius: 8px;
}

#note-title {
    border: none;
    background: var(--md-sys-color-surface-container-lowest);
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 12px;
    outline: none;
    color: var(--md-sys-color-on-surface);
}

#note-body {
    border: none;
    background: var(--md-sys-color-surface-container-lowest);
    font-size: 16px;
    resize: none;
    outline: none;
    min-height: 40px;
    color: var(--md-sys-color-on-surface);
    font-family: inherit;
}

#note-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
}

.toolbar-left {
    display: flex;
    gap: 4px;
    color: var(--md-sys-color-on-surface-variant);
}

.toolbar-left .material-symbols-rounded {
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    transition: background-color 0.2s;
}

.toolbar-left .material-symbols-rounded:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
    color: var(--md-sys-color-on-surface);
}

#close-note {
    background: transparent;
    border: none;
    padding: 8px 16px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 4px;
    color: var(--md-sys-color-on-surface);
}

#close-note:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
}

/* Notes Grid */
#notes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    width: 100%;
    transition: opacity 0.2s ease-in-out;
}

#notes-grid.fade-out {
    opacity: 0;
}

.note-card {
    background-color: var(--note-bg);
    border: 1px solid var(--note-border);
    border-radius: 8px;
    padding: 16px;
    position: relative;
    transition: box-shadow 0.2s, background-color 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.note-card:hover {
    box-shadow: 0 1px 3px color-mix(in srgb, var(--md-sys-color-shadow) 12%, transparent), 0 1px 2px color-mix(in srgb, var(--md-sys-color-shadow) 24%, transparent);
}

.note-card:hover .note-actions {
    opacity: 1;
}

.note-card.pinned {
    border: 2px solid var(--md-sys-color-primary);
}

.note-card.deep-link-focus {
    border-radius: 12px;
    animation: noteDeepLinkPulse 1.1s ease-out;
}

@keyframes noteDeepLinkPulse {
    0% {
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--md-sys-color-primary) 35%, transparent);
        transform: scale(1.0);
    }
    60% {
        box-shadow: 0 0 0 10px color-mix(in srgb, var(--md-sys-color-primary) 0%, transparent);
        transform: scale(1.01);
    }
    100% {
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--md-sys-color-primary) 0%, transparent);
        transform: scale(1.0);
    }
}

.note-card-title {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
    word-break: break-word;
}

.note-card-body {
    font-size: 14px;
    color: var(--md-sys-color-on-surface);
    white-space: pre-wrap;
    word-break: break-word;
    flex-grow: 1;
}

.note-actions {
    display: flex;
    justify-content: flex-start;
    gap: 4px;
    margin-top: 16px;
    opacity: 0;
    transition: opacity 0.2s;
    color: var(--md-sys-color-on-surface-variant);
}

.note-actions .material-symbols-rounded {
    padding: 6px;
    border-radius: 50%;
    font-size: 18px;
}

.note-actions .material-symbols-rounded:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
    color: var(--md-sys-color-on-surface);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: color-mix(in srgb, var(--md-sys-color-scrim) 60%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background-color: var(--note-bg, var(--md-sys-color-surface-container-lowest));
    width: 100%;
    max-width: 600px;
    border-radius: 8px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 24px color-mix(in srgb, var(--md-sys-color-shadow) 30%, transparent);
}

.pin-content {
    background-color: var(--md-sys-color-surface-container-high) !important;
    max-width: 320px !important;
    padding: 32px 24px !important;
}

.pin-content h3 {
    margin: 0 0 8px 0;
    font-size: 20px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.pin-content p {
    margin: 0 0 24px 0;
    font-size: 14px;
    color: var(--md-sys-color-on-surface-variant);
}

#pin-input {
    background-color: var(--md-sys-color-surface);
    border: 2px solid var(--md-sys-color-outline-variant);
    border-radius: 8px;
    padding: 16px;
    text-align: center !important;
    font-size: 32px !important;
    letter-spacing: 12px !important;
    margin: 24px 0 !important;
    width: 100%;
    box-sizing: border-box;
    color: var(--md-sys-color-on-surface);
    font-family: monospace;
    outline: none;
    transition: border-color 0.2s;
}

#pin-input:focus {
    border-color: var(--md-sys-color-primary);
}

#pin-cancel {
    background: transparent !important;
    border: none !important;
    padding: 8px 16px !important;
    font-weight: 500 !important;
    cursor: pointer;
    border-radius: 4px;
    color: var(--md-sys-color-primary) !important;
    transition: background-color 0.2s;
}

#pin-cancel:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent) !important;
}

#pin-submit {
    background-color: var(--md-sys-color-primary) !important;
    color: white !important;
    border: none !important;
    padding: 8px 24px !important;
    border-radius: 100px !important;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

#pin-submit:hover {
    opacity: 0.9;
}

#modal-title {
    border: none;
    background: transparent;
    font-size: 22px;
    font-weight: 500;
    margin-bottom: 16px;
    outline: none;
    color: var(--md-sys-color-on-surface);
}

#modal-body {
    border: none;
    background: transparent;
    font-size: 16px;
    resize: none;
    outline: none;
    min-height: 200px;
    color: var(--md-sys-color-on-surface);
    font-family: inherit;
    margin-bottom: 16px;
}

.modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#modal-close {
    background: transparent;
    border: none;
    padding: 8px 24px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 4px;
    color: var(--md-sys-color-on-surface);
}

#modal-close:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
}

/* Settings Modal */
.settings-content {
    background-color: var(--md-sys-color-surface);
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.settings-header h3 {
    margin: 0;
    font-size: 24px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.settings-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.settings-close:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.settings-section h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.settings-description {
    margin: 0 0 16px 0;
    font-size: 14px;
    color: var(--md-sys-color-on-surface-variant);
}

.settings-divider {
    height: 1px;
    background-color: var(--md-sys-color-outline-variant);
    opacity: 0.5;
}

.icon-settings-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.icon-setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-radius: 8px;
    background-color: var(--md-sys-color-surface-container);
}

.icon-setting-item span:first-child {
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.icon-change-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 1px solid var(--md-sys-color-outline-variant);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--md-sys-color-on-surface);
    transition: all 0.2s;
}

.icon-change-btn:hover {
    background-color: var(--md-sys-color-surface-container-high);
    border-color: var(--md-sys-color-primary);
}

.icon-change-btn .material-symbols-rounded {
    font-size: 20px;
}

.change-pin-btn {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s;
    width: fit-content;
}

.change-pin-btn:hover {
    background-color: var(--md-sys-color-primary);
    opacity: 0.9;
}

/* Icon Picker Modal */
.icon-picker-modal {
    z-index: 3000;
}

.icon-picker-content {
    background-color: var(--note-bg);
    border-radius: 16px;
    box-shadow: 0 8px 16px color-mix(in srgb, var(--md-sys-color-shadow) 20%, transparent);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.icon-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.icon-picker-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.icon-picker-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.icon-picker-close:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
}

.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    padding: 16px;
    overflow-y: auto;
    max-height: calc(80vh - 80px);
}

.icon-picker-item {
    background: none;
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    aspect-ratio: 1;
}

.icon-picker-item .material-symbols-rounded {
    font-size: 28px;
    color: var(--md-sys-color-on-surface);
}

.icon-picker-item:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
    border-color: var(--md-sys-color-outline-variant);
}

.icon-picker-item.selected {
    background-color: var(--md-sys-color-primary-container);
    border-color: var(--md-sys-color-primary);
}

.icon-picker-item.selected .material-symbols-rounded {
    color: var(--md-sys-color-on-primary-container);
}

#global-topbar .user-menu {
    position: absolute;
    right: 16px;
    top: 56px;
    z-index: 1001;
}

/* Responsive */
@media (max-width: 768px) {
    #sidebar {
        width: 80px;
    }

    .nav-item span:not(.material-symbols-rounded) {
        display: none;
    }

    #main-content {
        padding: 16px;
    }
}

/* Context Menu */
#context-menu {
    position: fixed;
    display: none;
    z-index: 10001;
    min-width: 180px;
    background-color: var(--md-sys-color-surface-container-high);
    border-radius: 8px;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--md-sys-color-shadow) 30%, transparent);
    padding: 8px 0;
}

.color-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    width: 200px;
    background-color: var(--md-sys-color-surface-container-high);
    border-radius: 8px;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--md-sys-color-shadow) 20%, transparent);
    padding: 8px 0;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: none;
    color: var(--md-sys-color-on-surface);
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.context-menu-item:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

.context-menu-item .material-symbols-rounded {
    font-size: 20px;
    color: var(--md-sys-color-on-surface-variant);
}

/* Background Color Picker Modal */
.background-picker-content {
    background-color: var(--md-sys-color-surface);
    border-radius: 16px;
    box-shadow: 0 12px 24px color-mix(in srgb, var(--md-sys-color-shadow) 30%, transparent);
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.background-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.background-picker-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.background-picker-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.background-picker-close:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
}

.background-picker-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    padding: 24px;
    overflow-y: auto;
    max-height: calc(80vh - 80px);
}

.background-color-item {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.background-color-item:hover {
    transform: scale(1.1);
    border-color: var(--md-sys-color-outline);
}

.background-color-item.selected {
    border-color: var(--md-sys-color-primary);
    transform: scale(1.1);
}

.background-color-item.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--md-sys-color-on-primary-container);
    font-weight: bold;
    font-size: 20px;
    text-shadow: 0 1px 2px color-mix(in srgb, var(--md-sys-color-shadow) 50%, transparent);
}
