/* ================================================
   NextNote — Premium Design System v1.0
   ================================================ */

/* --- Custom Properties / Design Tokens --- */
:root {
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --sidebar-width: 280px;
    --card-radius: 16px;
    --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    /* Accent palette */
    --accent-primary: #4f6ef7;
    --accent-primary-rgb: 79, 110, 247;
    --accent-gradient: linear-gradient(135deg, #4f6ef7 0%, #6366f1 50%, #8b5cf6 100%);
    --accent-glow: 0 4px 20px rgba(79, 110, 247, 0.35);

    /* Note colors — Light */
    --note-blue: #eff6ff; --note-blue-border: #bfdbfe; --note-blue-text: #1e40af;
    --note-green: #ecfdf5; --note-green-border: #a7f3d0; --note-green-text: #065f46;
    --note-yellow: #fefce8; --note-yellow-border: #fde68a; --note-yellow-text: #92400e;
    --note-red: #fef2f2; --note-red-border: #fecaca; --note-red-text: #991b1b;
    --note-purple: #faf5ff; --note-purple-border: #e9d5ff; --note-purple-text: #6b21a8;
    --note-default: #ffffff;
    --note-default-border: var(--bs-border-color);

    /* Surface */
    --surface-glass: rgba(255, 255, 255, 0.7);
    --surface-card: #ffffff;
    --sidebar-bg: #f8fafc;
    --header-blur: blur(12px);
}

[data-bs-theme="dark"] {
    --note-default: #1e1e2e;
    --note-default-border: rgba(255,255,255,0.08);
    --note-blue: #172554; --note-blue-border: #1e3a5f; --note-blue-text: #93c5fd;
    --note-green: #052e16; --note-green-border: #14532d; --note-green-text: #86efac;
    --note-yellow: #422006; --note-yellow-border: #713f12; --note-yellow-text: #fde68a;
    --note-red: #450a0a; --note-red-border: #7f1d1d; --note-red-text: #fca5a5;
    --note-purple: #2e1065; --note-purple-border: #4c1d95; --note-purple-text: #d8b4fe;

    --surface-glass: rgba(30, 30, 46, 0.85);
    --surface-card: #1e1e2e;
    --sidebar-bg: #181825;
    --accent-glow: 0 4px 20px rgba(99, 102, 241, 0.3);
}

/* --- Base Reset & Setup --- */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    height: 100vh;
    overflow: hidden;
    background-color: var(--bs-body-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Masonry Grid --- */
.masonry-grid {
    column-count: 1;
    column-gap: 1rem;
}

@media (min-width: 640px) {
    .masonry-grid { column-count: 2; }
}
@media (min-width: 1024px) {
    .masonry-grid { column-count: 3; }
}
@media (min-width: 1400px) {
    .masonry-grid { column-count: 4; }
}

/* --- Note Items & Cards --- */
.note-item {
    break-inside: avoid;
    margin-bottom: 1rem;
    animation: noteSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* Staggered animation for cards */
.note-item:nth-child(1)  { animation-delay: 0.02s; }
.note-item:nth-child(2)  { animation-delay: 0.04s; }
.note-item:nth-child(3)  { animation-delay: 0.06s; }
.note-item:nth-child(4)  { animation-delay: 0.08s; }
.note-item:nth-child(5)  { animation-delay: 0.10s; }
.note-item:nth-child(6)  { animation-delay: 0.12s; }
.note-item:nth-child(7)  { animation-delay: 0.14s; }
.note-item:nth-child(8)  { animation-delay: 0.16s; }
.note-item:nth-child(9)  { animation-delay: 0.18s; }
.note-item:nth-child(10) { animation-delay: 0.20s; }
.note-item:nth-child(n+11) { animation-delay: 0.22s; }

@keyframes noteSlideIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.note-card {
    border: 1px solid var(--note-default-border);
    border-radius: var(--card-radius);
    padding: 1.25rem 1.25rem 1rem;
    cursor: pointer;
    transition: var(--transition);
    background-color: var(--note-default);
    position: relative;
    overflow: hidden;
}

.note-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.note-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.08), 0 4px 10px rgba(0, 0, 0, 0.04);
    border-color: rgba(var(--accent-primary-rgb), 0.2);
}

.note-card:hover::before {
    opacity: 1;
}

[data-bs-theme="dark"] .note-card:hover {
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3), 0 4px 10px rgba(0, 0, 0, 0.2);
}

.note-card:active {
    transform: translateY(-2px) scale(0.99);
}

/* Note Color Classes */
.bg-blue {
    background-color: var(--note-blue) !important;
    color: var(--note-blue-text);
    border-color: var(--note-blue-border) !important;
}
.bg-green {
    background-color: var(--note-green) !important;
    color: var(--note-green-text);
    border-color: var(--note-green-border) !important;
}
.bg-yellow {
    background-color: var(--note-yellow) !important;
    color: var(--note-yellow-text);
    border-color: var(--note-yellow-border) !important;
}
.bg-red {
    background-color: var(--note-red) !important;
    color: var(--note-red-text);
    border-color: var(--note-red-border) !important;
}
.bg-purple {
    background-color: var(--note-purple) !important;
    color: var(--note-purple-text);
    border-color: var(--note-purple-border) !important;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    border-right: 1px solid var(--bs-border-color);
    display: flex;
    flex-direction: column;
    background-color: var(--sidebar-bg);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1040;
    overflow: hidden;
}

.sidebar-brand {
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-link {
    border-radius: 10px;
    margin-bottom: 2px;
    padding: 0.65rem 0.85rem;
    color: var(--bs-body-color);
    font-weight: 500;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    transition: var(--transition-fast);
}

.nav-link:hover {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-body-color);
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(var(--accent-primary-rgb), 0.12), rgba(var(--accent-primary-rgb), 0.06));
    color: var(--accent-primary);
    font-weight: 600;
}

.nav-link .badge {
    font-size: 0.7rem;
    font-weight: 600;
}

/* Category Items */
.cat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0;
    border-radius: 10px;
    transition: var(--transition-fast);
}

.cat-item:hover {
    background-color: var(--bs-secondary-bg);
}

.cat-item .nav-link {
    background: none;
    margin: 0;
    padding: 0.55rem 0.85rem;
    width: 100%;
    flex: 1;
    min-width: 0;
}

.cat-item .nav-link:hover {
    background: none;
}

.cat-item.active {
    background: linear-gradient(135deg, rgba(var(--accent-primary-rgb), 0.12), rgba(var(--accent-primary-rgb), 0.06));
}

.cat-item.active .nav-link {
    color: var(--accent-primary);
    font-weight: 600;
}

.cat-item .btn-del-cat {
    opacity: 0;
    transition: opacity 0.2s ease;
    flex-shrink: 0;
}

.cat-item:hover .btn-del-cat {
    opacity: 0.7;
}

.cat-item .btn-del-cat:hover {
    opacity: 1;
}

/* --- Header --- */
.app-header {
    background-color: var(--surface-glass);
    backdrop-filter: var(--header-blur);
    -webkit-backdrop-filter: var(--header-blur);
    border-bottom: 1px solid var(--bs-border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

.search-box {
    position: relative;
}

.search-box .bi-search {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--bs-secondary-color);
    font-size: 0.85rem;
    pointer-events: none;
}

.search-box input {
    padding-left: 36px;
    border-radius: 10px;
    border: 1px solid var(--bs-border-color);
    background-color: var(--bs-body-bg);
    font-size: 0.9rem;
    transition: var(--transition-fast);
}

.search-box input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(var(--accent-primary-rgb), 0.15);
}

/* --- Mobile Sidebar --- */
@media (max-width: 991px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        box-shadow: none;
    }
    .sidebar.show {
        transform: translateX(0);
        box-shadow: 8px 0 30px rgba(0, 0, 0, 0.15);
    }
    .overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 1030;
        transition: opacity 0.3s ease;
    }
    .overlay.show {
        display: block;
        animation: fadeIn 0.3s ease;
    }
}

@media (min-width: 992px) {
    .overlay { display: none !important; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- FAB (Floating Action Button) --- */
.fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 60px;
    height: 60px;
    border-radius: 18px;
    background: var(--accent-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--accent-glow);
    border: none;
    font-size: 22px;
    z-index: 1050;
    transition: var(--transition);
    cursor: pointer;
}

.fab:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 8px 30px rgba(var(--accent-primary-rgb), 0.45);
}

.fab:active {
    transform: scale(1.02);
}

/* --- Note Editor Modal --- */
#noteContent {
    min-height: 200px;
    resize: none;
    border: none;
    box-shadow: none;
    font-size: 1.05rem;
    line-height: 1.7;
    background: transparent;
    color: var(--bs-body-color);
}

#noteContent:focus {
    box-shadow: none;
    border-color: transparent;
}

#noteTitle {
    font-weight: 700;
    font-size: 1.45rem;
    border: none;
    box-shadow: none;
    background: transparent;
    letter-spacing: -0.01em;
    color: var(--bs-body-color);
}

#noteTitle:focus {
    box-shadow: none;
}

#noteTitle::placeholder,
#noteContent::placeholder {
    color: var(--bs-secondary-color);
    opacity: 0.5;
}

/* Word count badge */
.word-count-badge {
    font-size: 0.72rem;
    color: var(--bs-secondary-color);
    font-variant-numeric: tabular-nums;
    user-select: none;
}

/* Note Preview */
.note-preview {
    white-space: pre-wrap;
    font-size: 0.9rem;
    line-height: 1.55;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    opacity: 0.85;
}

.note-card .note-title {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
    margin-bottom: 0.35rem;
}

.note-card .note-meta {
    font-size: 0.78rem;
    opacity: 0.65;
}

/* Pin indicator */
.pin-indicator {
    position: absolute;
    top: 10px;
    right: 12px;
    color: #f59e0b;
    font-size: 0.9rem;
    filter: drop-shadow(0 1px 2px rgba(245, 158, 11, 0.3));
}

/* --- Settings Modal --- */
.settings-section {
    padding: 0.65rem 0;
}

.settings-section + .settings-section {
    border-top: 1px solid var(--bs-border-color);
}

.settings-section-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--bs-secondary-color);
    padding: 0 1.25rem;
    margin-bottom: 0.35rem;
    font-weight: 700;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1.25rem;
    transition: var(--transition-fast);
    border-radius: 0;
}

.settings-item[role="button"]:hover {
    background-color: var(--bs-secondary-bg);
    cursor: pointer;
}

.settings-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* --- Modal Enhancements --- */
.modal-content {
    border-radius: 20px;
    overflow: hidden;
}

.modal.fade .modal-dialog {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

/* --- Empty State --- */
.empty-state-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
}

.empty-state-icon {
    font-size: 4.5rem;
    opacity: 0.15;
    margin-bottom: 1rem;
}

.empty-state-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--bs-secondary-color);
    max-width: 280px;
}

.empty-state-hint {
    font-size: 0.85rem;
    color: var(--bs-secondary-color);
    opacity: 0.6;
    margin-top: 0.5rem;
}

/* --- Scrollbar --- */
.custom-scroll::-webkit-scrollbar { width: 5px; }
.custom-scroll::-webkit-scrollbar-track { background: transparent; }
.custom-scroll::-webkit-scrollbar-thumb {
    background: var(--bs-secondary-bg);
    border-radius: 10px;
}
.custom-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--bs-secondary-color);
}

#main-scroll::-webkit-scrollbar { width: 6px; }
#main-scroll::-webkit-scrollbar-track { background: transparent; }
#main-scroll::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
    border-radius: 10px;
}
[data-bs-theme="dark"] #main-scroll::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
}

/* --- Tooltip for buttons --- */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--bs-body-color);
    transition: var(--transition-fast);
    cursor: pointer;
}

.btn-icon:hover {
    background-color: var(--bs-secondary-bg);
}

/* --- Color dots in select --- */
.color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    border: 2px solid rgba(0,0,0,0.1);
}

/* --- Keyboard shortcut hint --- */
.kbd {
    display: inline-block;
    padding: 2px 6px;
    font-size: 0.7rem;
    font-family: var(--font-main);
    font-weight: 600;
    color: var(--bs-secondary-color);
    background-color: var(--bs-secondary-bg);
    border-radius: 5px;
    border: 1px solid var(--bs-border-color);
    line-height: 1.3;
}

/* --- Toast enhancement --- */
.toast {
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

/* --- Responsive fine-tuning --- */
@media (max-width: 575px) {
    .fab {
        bottom: 20px;
        right: 20px;
        width: 54px;
        height: 54px;
        border-radius: 16px;
        font-size: 20px;
    }

    .note-card {
        padding: 1rem;
        border-radius: 14px;
    }

    .app-header {
        padding: 0.65rem 1rem !important;
    }
}

/* --- Confirmation Dialog Styling --- */
.confirm-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.confirm-dialog {
    background: var(--bs-body-bg);
    border-radius: 20px;
    padding: 2rem;
    max-width: 380px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: dialogIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes dialogIn {
    from {
        opacity: 0;
        transform: scale(0.92) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* --- Category badge on cards --- */
.cat-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    background-color: var(--bs-body-secondary);
    border: 1px solid var(--bs-border-color);
}

/* --- Selection highlight --- */
::selection {
    background: rgba(var(--accent-primary-rgb), 0.2);
    color: inherit;
}

/* --- Focus visible for accessibility --- */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

button:focus:not(:focus-visible) {
    outline: none;
}
