/* ═══════════════════════════════════════════════════════════
   CloudNotes — Design System & Styles
   ═══════════════════════════════════════════════════════════ */

/* ─── Tokens ─── */
:root {
    /* Palette */
    --bg-primary:     #0f1117;
    --bg-secondary:   #161822;
    --bg-card:        #1c1f2e;
    --bg-card-hover:  #242738;
    --bg-sidebar:     #131520;
    --bg-input:       #1a1d2e;
    --bg-modal:       #1c1f2e;

    --text-primary:   #e8eaed;
    --text-secondary: #9aa0b0;
    --text-muted:     #5f6577;

    --accent:         #6c5ce7;
    --accent-hover:   #7f71eb;
    --accent-glow:    rgba(108, 92, 231, 0.25);

    --danger:         #e74c6f;
    --danger-hover:   #f06292;

    --success:        #00cec9;
    --warning:        #fdcb6e;

    --border:         rgba(255, 255, 255, 0.06);
    --border-focus:   rgba(108, 92, 231, 0.5);

    /* Radius */
    --radius-sm:  8px;
    --radius-md:  12px;
    --radius-lg:  16px;
    --radius-xl:  24px;

    /* Shadows */
    --shadow-card:  0 2px 12px rgba(0,0,0,0.25);
    --shadow-modal: 0 24px 80px rgba(0,0,0,0.5);

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

    /* Layout */
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

/* ─── Reset ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ═══════════════════════════════════════════
   Sidebar
   ═══════════════════════════════════════════ */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.35s var(--ease-out);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 16px;
}
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}
.logo-icon {
    font-size: 1.6rem;
    filter: drop-shadow(0 0 8px var(--accent-glow));
}
.logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--success));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.sidebar-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
}

/* Nav Items */
.sidebar-nav {
    flex: 1;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-family: inherit;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.nav-item.active { background: var(--accent-glow); color: var(--accent-hover); font-weight: 500; }
.nav-icon { font-size: 1.1rem; width: 24px; text-align: center; }
.nav-count {
    margin-left: auto;
    font-size: 0.75rem;
    background: rgba(255,255,255,0.06);
    padding: 2px 8px;
    border-radius: 20px;
    min-width: 24px;
    text-align: center;
}

/* Footer */
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Stats Panel */
.stats-panel {
    background: rgba(108, 92, 231, 0.06);
    border: 1px solid rgba(108, 92, 231, 0.12);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 8px;
}
.stats-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 2px 0;
}
.stats-row span:last-child {
    font-weight: 500;
    color: var(--text-secondary);
}

/* Backup Panel */
.backup-panel {
    background: rgba(0, 206, 201, 0.06);
    border: 1px solid rgba(0, 206, 201, 0.12);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 8px;
}
.truncate {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: bottom;
}
.env-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.env-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.version-info {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ═══════════════════════════════════════════
   Main Content
   ═══════════════════════════════════════════ */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Top Bar */
.top-bar {
    height: var(--topbar-height);
    padding: 0 28px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
}
.menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
}
.search-wrapper {
    flex: 1;
    max-width: 480px;
    position: relative;
}
.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9rem;
    opacity: 0.5;
}
.search-input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.btn-primary {
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: #fff;
    box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-hover), #9b7cf6);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }

/* ═══════════════════════════════════════════
   Notes Grid
   ═══════════════════════════════════════════ */
.notes-container {
    flex: 1;
    padding: 28px;
    overflow-y: auto;
}
.notes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

/* Note Card */
.note-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    cursor: pointer;
    transition: all 0.25s var(--ease-out);
    position: relative;
    animation: fadeInUp 0.35s var(--ease-out) both;
}
.note-card:hover {
    background: var(--bg-card-hover);
    border-color: rgba(108, 92, 231, 0.2);
    transform: translateY(-2px);
    box-shadow: var(--shadow-card);
}
.note-card.pinned {
    border-left: 3px solid var(--accent);
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.note-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}
.note-card-title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
    flex: 1;
}
.note-pin { font-size: 0.85rem; opacity: 0.6; }

.note-card-content {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: pre-line;
}

.note-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}
.note-category-tag {
    font-size: 0.72rem;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--accent-glow);
    color: var(--accent-hover);
    font-weight: 500;
    text-transform: capitalize;
}
.note-date {
    font-size: 0.72rem;
    color: var(--text-muted);
}
.note-views {
    font-size: 0.72rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 3px;
}
.note-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.note-card:hover .note-actions { opacity: 1; }
.note-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.95rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s ease, background 0.2s ease;
}
.note-action-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.06);
}
.note-action-btn.delete:hover { color: var(--danger); }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}
.empty-icon {
    font-size: 3.5rem;
    display: block;
    margin-bottom: 16px;
}
.empty-state h2 {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.empty-state p { font-size: 0.9rem; }

/* ═══════════════════════════════════════════
   Modal
   ═══════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    background: var(--bg-modal);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 560px;
    box-shadow: var(--shadow-modal);
    transform: translateY(16px) scale(0.97);
    transition: transform 0.3s var(--ease-out);
}
.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}
.modal-sm { max-width: 400px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.15rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s ease;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 24px; }

.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
}
.form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}
.form-row .form-group { flex: 1; }
.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    color: var(--text-primary) !important;
    cursor: pointer;
    padding-bottom: 10px;
}
.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 8px;
}

/* ═══════════════════════════════════════════
   Toast Notifications
   ═══════════════════════════════════════════ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 300;
}
.toast {
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    animation: slideInRight 0.35s var(--ease-out), fadeOut 0.3s ease 2.7s forwards;
    display: flex;
    align-items: center;
    gap: 8px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes fadeOut {
    to { opacity: 0; transform: translateX(20px); }
}

/* ═══════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 12px 0 40px rgba(0,0,0,0.5);
    }
    .sidebar-toggle { display: block; }
    .menu-btn { display: block; }
    .main-content { margin-left: 0; }
    .notes-grid {
        grid-template-columns: 1fr;
    }
    .top-bar { padding: 0 16px; }
    .notes-container { padding: 16px; }
    .form-row { flex-direction: column; gap: 0; }
}
