/**
 * flux v3 - Modern Encrypted Notes
 * Clean, minimal design with smooth animations
 */

/* ============================================================================
   CSS Variables & Base Styles
   ============================================================================ */

/* ============================================================================
   Theme Configuration - Customize colors by editing these variables
   Based on Flux brand identity
   ============================================================================ */

:root {
    /* Primary brand colors - Purple from logo shield */
    --primary: #8B7AB8;                /* Main accent color (purple shield) */
    --primary-hover: #7565A3;          /* Darker purple for hover */
    --primary-light: #E8E4F3;          /* Light purple background */

    /* Secondary brand colors - Steel blue from logo */
    --secondary: #5B8DB8;              /* Steel blue (document area) */
    --secondary-hover: #4A7BA0;        /* Darker blue */
    --secondary-light: #D9E8F5;        /* Light blue background */

    /* Status colors */
    --danger: #dc2626;                 /* Delete/warning actions */
    --danger-hover: #b91c1c;           /* Hover state for danger buttons */
    --success: #16a34a;                /* Success messages */

    /* Text colors - Navy from logo */
    --text-primary: #2C3E50;           /* Main text (dark navy from logo) */
    --text-secondary: #5B6B7D;         /* Muted text, labels */

    /* Background colors */
    --bg-primary: #ffffff;             /* Main background (sidebar, modals) */
    --bg-secondary: #F7F9FB;           /* Page background (subtle blue-gray) */
    --bg-tertiary: #E8EDF2;            /* Hover states, disabled elements */

    /* Borders and dividers */
    --border: #D1DCE5;                 /* Border color (subtle blue-gray) */

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(44, 62, 80, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(44, 62, 80, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(44, 62, 80, 0.1);

    /* Login screen gradient - Purple to Blue from logo */
    --login-gradient-start: #8B7AB8;   /* Purple from shield */
    --login-gradient-end: #5B8DB8;     /* Steel blue from document */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--text-primary);
    background: var(--bg-secondary);
}

/* ============================================================================
   Loading Screen
   ============================================================================ */

.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-content p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============================================================================
   Screen Management
   ============================================================================ */

.app-container {
    height: 100%;
    overflow: hidden;
}

.screen {
    display: none;
    height: 100%;
    width: 100%;
}

.screen.active {
    display: flex;
}

/* ============================================================================
   Login Screen
   ============================================================================ */

#login-screen {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--login-gradient-start) 0%, var(--login-gradient-end) 100%);
}

.login-container {
    background: var(--bg-primary);
    padding: 3rem;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.logo-image {
    width: 200px;
    height: auto;
    max-width: 100%;
}

.logo svg {
    color: var(--primary);
}

.logo h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 14px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-form input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.2s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ============================================================================
   Main Screen Layout
   ============================================================================ */

#main-screen {
    display: none;
}

#main-screen.active {
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto 1fr;
    height: 100%;
}

/* ============================================================================
   Mobile Header
   ============================================================================ */

.mobile-header {
    display: none;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    align-items: center;
    justify-content: space-between;
    grid-column: 1 / -1;
}

.mobile-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================================================
   Sidebar
   ============================================================================ */

.sidebar {
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header {
    padding: 0.875rem 0.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 10;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.section {
    padding: 0.625rem 0.75rem;
    flex-shrink: 0;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.section-header h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.section-toggle {
    background: none;
    border: none;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    cursor: pointer;
    padding: 0;
    transition: opacity 0.2s;
}

.section-toggle:hover {
    opacity: 0.7;
}

.section-toggle .chevron {
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.section.collapsed .chevron {
    transform: rotate(-90deg);
}

.section-toggle h3 {
    margin: 0;
}

.section-content {
    overflow: visible;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.section.collapsed .section-content {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
}

/* ============================================================================
   Items (Bookmarks & Notes)
   ============================================================================ */

.item-list {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.625rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}

.item:hover {
    background: var(--bg-tertiary);
}

.item-icon {
    flex-shrink: 0;
    color: var(--text-secondary);
}

.item-name {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-delete {
    opacity: 0;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    color: var(--text-secondary);
    transition: all 0.15s;
    flex-shrink: 0;
}

.item:hover .item-delete {
    opacity: 1;
}

.item-delete:hover {
    background: var(--danger);
    color: white;
}

/* Tag groups (collapsible) */
.tag-group {
    margin-top: 0.375rem;
}

.tag-header {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--primary);
    padding: 0.375rem 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    transition: opacity 0.2s;
}

.tag-header:hover {
    opacity: 0.7;
}

.tag-header .chevron {
    color: var(--primary);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.tag-group.collapsed .chevron {
    transform: rotate(-90deg);
}

.tag-content {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.tag-group.collapsed .tag-content {
    max-height: 0;
    opacity: 0;
}

.empty-state {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============================================================================
   Main Content Area
   ============================================================================ */

.main-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-secondary);
    min-height: 0; /* Allows proper flex shrinking */
}

.view {
    display: none;
    height: 100%;
    width: 100%;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* ============================================================================
   Welcome View
   ============================================================================ */

#welcome-view {
    align-items: center;
    justify-content: center;
}

.welcome-content {
    text-align: center;
    max-width: 400px;
}

.welcome-icon {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.welcome-content h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.welcome-content p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============================================================================
   Editor View
   ============================================================================ */

#editor-view {
    display: none;
}

#editor-view.active {
    display: flex;
}

.editor-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    padding: 1rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.note-title-input {
    flex: 1;
    min-width: 200px;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.2s;
}

.note-title-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.editor-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.note-tags-input {
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    width: 200px;
    transition: all 0.2s;
}

.note-tags-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.editor {
    flex: 1;
    overflow: hidden;
    background: var(--bg-primary);
    min-height: 0; /* Allows flex shrinking on mobile */
}

.ace_editor {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.98);
}

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

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border);
}

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

.btn-danger:hover {
    background: var(--danger-hover);
}

.icon-btn {
    background: none;
    border: none;
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* ============================================================================
   Modals
   ============================================================================ */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s;
}

.modal.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    animation: slideUp 0.2s;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.15s;
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal form {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* ============================================================================
   Gallery View
   ============================================================================ */

.gallery-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    padding: 1rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.gallery-name-input {
    flex: 1;
    min-width: 200px;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    background: var(--bg-secondary);
}

.gallery-actions {
    display: flex;
    gap: 0.5rem;
}

.gallery-grid {
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    grid-auto-rows: minmax(200px, auto);
    gap: 1rem;
    overflow-y: auto;
    align-content: start;
}

.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.gallery-empty svg {
    opacity: 0.5;
    margin-bottom: 1rem;
}

.gallery-empty p {
    margin: 0.5rem 0;
}

.gallery-help {
    font-size: 13px;
    opacity: 0.7;
}

.gallery-item {
    position: relative;
    width: 100%;
    padding-bottom: 100%; /* Creates 1:1 aspect ratio */
    background: var(--bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border-style: solid;
    border-color:  var(--bg-primary);
    border-width: 10px 1px;
    box-shadow: var(--shadow-sm);
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.gallery-item img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.gallery-item-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--danger);
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 2;
}

.gallery-item:hover .gallery-item-delete {
    opacity: 1;
}

.gallery-item-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1;
}

/* ============================================================================
   Image Viewer (Fullscreen)
   ============================================================================ */

.image-viewer {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.image-viewer.active {
    display: flex;
}

.image-viewer-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to bottom, rgba(0,0,0,0.5), transparent);
    z-index: 10;
}

.image-viewer-header span {
    color: white;
    font-size: 14px;
}

.image-viewer-header .icon-btn {
    color: white;
}

.image-viewer-header .icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.image-viewer-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: auto;
}

.image-viewer-content img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
}

.image-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
}

.image-loading .spinner {
    border-color: rgba(255, 255, 255, 0.3);
    border-top-color: white;
}

.image-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    z-index: 10;
}

.image-nav-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.image-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.image-nav-btn.prev {
    left: 1rem;
}

.image-nav-btn.next {
    right: 1rem;
}

/* ============================================================================
   Responsive Design
   ============================================================================ */

@media (max-width: 768px) {
    #main-screen.active {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .mobile-header {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        bottom: 0;
        width: 280px;
        z-index: 100;
        box-shadow: var(--shadow-lg);
        transition: left 0.3s ease;
    }

    .sidebar.mobile-open {
        left: 0;
    }

    .editor-header {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .note-title-input {
        font-size: 14px;
        padding: 0.5rem;
        min-width: auto;
    }

    .editor-actions {
        flex-wrap: wrap;
        width: 100%;
    }

    .note-tags-input {
        flex: 1;
        min-width: 120px;
        font-size: 13px;
        padding: 0.5rem;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 13px;
    }

    .btn .btn-text {
        display: none;
    }

    .btn svg {
        margin: 0;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .gallery-header {
        padding: 0.5rem;
    }

    .gallery-name-input {
        font-size: 14px;
        padding: 0.5rem;
    }

    .image-nav-btn {
        width: 40px;
        height: 40px;
    }

    .login-container {
        margin: 1rem;
        padding: 2rem;
    }
}

/* ============================================================================
   Scrollbar Styling
   ============================================================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
