:root {
    --bg-base: #f4f6f8;
    --bg-surface: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-hover: #f3f4f6;
    
    --text-main: #1f2937;
    --text-muted: #6b7280;
    
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #eff6ff;
    
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
    --success: #10b981;
    
    --border: #e5e7eb;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-base: #0f172a;
        --bg-surface: #1e293b;
        --bg-sidebar: #1e293b;
        --bg-hover: #334155;
        
        --text-main: #f8fafc;
        --text-muted: #94a3b8;
        
        --primary: #3b82f6;
        --primary-hover: #60a5fa;
        --primary-light: #1e3a8a;
        
        --border: #334155;
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    transition: background-color 0.3s, color 0.3s;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.hidden { display: none !important; }

/* Typography */
h1, h2, h3 { color: var(--text-main); }
.text-muted { color: var(--text-muted); }

/* Buttons & Inputs */
.btn {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 20px;
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-icon {
    padding: 8px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    justify-content: center;
    font-size: 1.2em;
}

.hidden-desktop { display: none; }

.btn:hover { background: var(--bg-hover); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background: var(--primary-hover);
    color: white;
}

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fee2e2; border-color: var(--danger); color: var(--danger-hover);}
@media (prefers-color-scheme: dark) {
    .btn-danger:hover { background: rgba(239, 68, 68, 0.2); }
}

.input-field {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s;
    font-size: 1em;
}

.input-field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }

/* --- Auth Screen --- */
#authScreen {
    position: fixed;
    inset: 0;
    background: var(--bg-base);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

/* Blur effect applied to appScreen when locking */
.app-blur { filter: blur(10px); transition: filter 0.1s; }

.auth-box {
    background: var(--bg-surface);
    padding: 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    text-align: center;
    border: 1px solid var(--border);
    animation: slideUp 0.5s ease-out;
}

.auth-box h1 {
    font-size: 2em;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-box p { margin-bottom: 24px; }
.auth-box .input-field { margin-bottom: 20px; text-align: center; letter-spacing: 2px; font-size: 1.2em;}
.auth-box .btn-primary { width: 100%; justify-content: center; padding: 14px; font-size: 1.1em; border-radius: var(--radius-md); }

/* --- App Layout --- */
#appScreen {
    display: flex;
    height: 100vh;
    overflow: hidden;
    transition: filter 0.2s;
}

/* Sidebar Backdrop */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 45;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 50;
    flex-shrink: 0;
    overflow: hidden; /* For smooth collapsing */
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.3s, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-content, .brand, .sidebar-footer {
    width: 260px; /* Keep children at fixed width so layout doesn't squash during collapse */
}

/* Sidebar Collapsed State (Desktop) */
@media (min-width: 769px) {
    .sidebar.collapsed {
        width: 0;
        border-right-color: transparent;
    }
}

.brand {
    font-size: 1.3em;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 70px;
    padding: 0 20px;
    box-sizing: border-box;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 8px var(--success);
    transition: background 0.3s;
}
.status-dot.saving { background: var(--warning); box-shadow: 0 0 8px var(--warning); animation: pulse 1s infinite; }

.sidebar-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
}

.section-title {
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.folder-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }

.folder-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.folder-item:hover { background: var(--bg-hover); }
.folder-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
@media (prefers-color-scheme: dark) { .folder-item.active { background: var(--primary-light); color: #fff; } }

.folder-item .folder-actions { display: none; }
.folder-item:hover .folder-actions { display: flex; gap: 5px; }
.folder-actions button { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1.1em; transition: color 0.2s; }
.folder-actions button:hover { color: var(--danger); }

.add-folder-btn {
    background: none; border: none; color: var(--primary); cursor: pointer;
    font-size: 1.2em; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; transition: background 0.2s;
}
.add-folder-btn:hover { background: var(--primary-light); }

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
}

/* Toggle Switch */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    color: var(--text-muted);
}
.toggle-container input { display: none; }
.slider {
    position: relative;
    width: 36px;
    height: 20px;
    background-color: var(--border);
    border-radius: 20px;
    transition: .4s;
}
.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: .4s;
}
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(16px); }


/* Main Content Area */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    z-index: 30;
    gap: 15px;
    height: 70px;
    box-sizing: border-box;
}

#btnMobileMenu {
    display: none;
}

.sidebar.collapsed ~ .main-content #btnMobileMenu {
    display: inline-flex;
}

.header-title h2 { font-size: 1.2em; font-weight: 700; }

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.search-container { position: relative; display: flex; align-items: center;}
.search-container input {
    padding: 8px 36px 8px 36px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-base);
    color: var(--text-main);
    outline: none;
    width: 250px;
    transition: border-color 0.2s, width 0.3s;
}
.search-container input:focus { border-color: var(--primary); width: 300px; }
.search-icon { position: absolute; left: 12px; color: var(--text-muted); }
.btn-clear {
    position: absolute; right: 8px; background: none; border: none;
    font-size: 1.2em; color: var(--text-muted); cursor: pointer;
    border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
}
.btn-clear:hover { background: var(--bg-hover); color: var(--text-main); }

.main-scroll {
    flex-grow: 1;
    overflow-y: auto;
    padding: 30px;
    position: relative;
}

/* Grid & Cards */
.grid {
    display: grid;
    /* Responsive grid: min 280px on desktop, adapts dynamically */
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    align-items: start;
}

.card {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    min-height: 200px;
}

.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); }
.card.pinned { border-top: 4px solid var(--warning); border-top-left-radius: var(--radius-md); border-top-right-radius: var(--radius-md);}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.card-badges { display: flex; gap: 6px; }
.badge {
    background: var(--bg-base);
    color: var(--text-muted);
    font-size: 0.75em;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
    border: 1px solid transparent;
}
.badge:hover { background: var(--bg-hover); border-color: var(--border); }
.badge.active-pin { background: var(--warning); color: #fff; box-shadow: 0 2px 5px rgba(245, 158, 11, 0.4); }
.badge.active-arc { background: var(--text-muted); color: #fff; }

select.badge {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 20px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 8px;
    border: 1px solid transparent;
    outline: none;
    color: var(--text-muted);
    font-family: inherit;
}

select.badge option {
    background: var(--bg-surface);
    color: var(--text-main);
}

.card-body {
    background: transparent;
    border: none;
    color: var(--text-main);
    width: 100%;
    resize: none; /* Removed manual resize */
    overflow: hidden; /* Removed scrollbar */
    outline: none;
    flex-grow: 1;
    font-size: 1.05em;
    line-height: 1.6;
    min-height: 100px; /* Minimum height */
}
.card-body::placeholder { color: var(--text-muted); opacity: 0.6; }

.card-footer {
    display: flex;
    flex-direction: column;
    margin-top: auto; /* Push footer to bottom of card */
    padding-top: 12px;
    border-top: 1px solid var(--border);
    gap: 12px;
}

.card-stats {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75em;
    color: var(--text-muted);
    font-weight: 500;
    width: 100%;
}

.card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    width: 100%;
    flex-wrap: wrap;
}
.action-btn {
    background: var(--bg-base);
    border: none;
    cursor: pointer;
    color: var(--text-main);
    font-weight: 600;
    font-size: 0.85em;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}
.action-btn:hover { background: var(--border); }

.action-btn.copy-btn.copied {
    background: var(--success);
    color: white;
}

.action-btn.del { color: var(--danger); }
.action-btn.del:hover { background: rgba(239, 68, 68, 0.1); }

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60%;
    color: var(--text-muted);
    text-align: center;
    animation: fadeIn 0.5s;
}
.empty-state-icon { font-size: 4em; margin-bottom: 20px; opacity: 0.5; }
.empty-state h3 { font-size: 1.5em; margin-bottom: 8px; color: var(--text-main); }

/* Modals & Dialogs */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; z-index: 2000; backdrop-filter: blur(4px);
}
.modal {
    background: var(--bg-surface); padding: 24px; border-radius: var(--radius-lg); width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); animation: slideDown 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal h3 { margin-bottom: 16px; }
.modal .input-field { margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Toast */
#toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text-main);
    color: var(--bg-surface);
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 500;
    z-index: 3000;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Animations */
@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.3); opacity: 0.6; } 100% { transform: scale(1); opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-20px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ==========================================
   MOBILE SUPPORT 
   ========================================== */
@media (max-width: 768px) {
    .hidden-desktop { display: inline-flex; }
    
    /* Sidebar acts as off-canvas drawer */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }

    header { padding: 10px 15px; }
    #btnMobileMenu { display: inline-flex; }
    .main-scroll { padding: 15px; }
    
    .header-actions { gap: 8px; }
    
    .search-container input { width: 140px; }
    .search-container input:focus { width: 200px; }

    /* FAB for Mobile */
    .fab-mobile {
        position: fixed;
        bottom: 24px;
        right: 24px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
        z-index: 40;
        box-shadow: var(--shadow-lg);
    }
    .fab-mobile .fab-text { display: none; }
    .fab-mobile .fab-icon { display: block !important; }
    
    .grid { grid-template-columns: 1fr; }
}

.fab-icon { display: none; }

/* ==========================================
   IMAGE CARD & LIGHTBOX SUPPORT 
   ========================================== */
.card-image-wrapper {
    position: relative;
    width: 100%;
    margin-bottom: 15px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    aspect-ratio: 16 / 10;
    background: var(--bg-hover);
    border: 1px solid var(--border);
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: zoom-in;
    transition: transform 0.3s ease;
}

.card-image-wrapper:hover .card-image {
    transform: scale(1.03);
}

.btn-remove-image, .btn-download-image {
    position: absolute;
    top: 8px;
    background: rgba(15, 23, 42, 0.75); /* Modern dark slate backdrop */
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.btn-remove-image {
    right: 8px;
}

.btn-download-image {
    left: 8px;
}

.btn-remove-image:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
    transform: scale(1.1);
}

.btn-download-image:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(1.1);
}

#closeLightbox:hover {
    color: #ffffff !important;
}

#lightboxModal:not(.hidden) #lightboxImage {
    transform: scale(1) !important;
}

/* WCAG Accessible Focus Outlines */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.badge:focus-visible,
.folder-item:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* Spinner Animation for Uploading state */
@keyframes spin {
    to { transform: rotate(360deg); }
}
.spinner {
    animation: spin 1s linear infinite;
}

