/**
 * RediaFile AI — Modern Vanilla CSS Theme
 * Clean, accessible, responsive design
 */

:root {
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --primary-light: #e0f2fe;
    --primary-text: #0369a1;
    --accent: #0d9488;
    --accent-hover: #0f766e;
    
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-muted: #f1f5f9;
    --bg-hover: #e2e8f0;
    
    --border: #e2e8f0;
    --border-subtle: #cbd5e1;
    --border-focus: #38bdf8;
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    
    --badge-source-bg: #f0fdf4;
    --badge-source-text: #166534;
    --badge-source-border: #bbf7d0;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.03);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    font-size: 15px;
    line-height: 1.6;
    height: 100vh;
    display: flex;
    overflow: hidden;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--primary-hover);
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    font-size: 14px;
}

input, textarea, select {
    font-family: inherit;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    background: var(--bg-surface);
    color: var(--text-main);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

/* Application Layout */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* Main Left Navigation Bar */
.main-nav {
    width: 250px;
    background: #0f172a;
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-right: 1px solid #1e293b;
    flex-shrink: 0;
    user-select: none;
}

.nav-header {
    padding: 20px 18px;
    border-bottom: 1px solid #1e293b;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #ffffff;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #0284c7, #0d9488);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 16px;
}

.brand-badge {
    background: rgba(2, 132, 199, 0.25);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.3);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 4px;
}

.nav-menu {
    list-style: none;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: #94a3b8;
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: all 0.15s ease;
}

.nav-item a:hover {
    background: #1e293b;
    color: #f8fafc;
}

.nav-item.active a {
    background: #0284c7;
    color: #ffffff;
    font-weight: 600;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

.nav-footer {
    padding: 16px;
    border-top: 1px solid #1e293b;
    background: #0b1120;
}

.user-profile {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #0284c7;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.user-details {
    overflow: hidden;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: #f8fafc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-cloud-tag {
    font-size: 11px;
    color: #38bdf8;
    display: block;
}

.logout-btn {
    color: #94a3b8;
    padding: 6px;
    border-radius: 6px;
    transition: color 0.15s ease, background 0.15s ease;
}

.logout-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* App Main Content Area */
.app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-main);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all 0.15s ease;
    white-space: nowrap;
}

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

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

.btn-secondary {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-main);
}

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

.btn-sm {
    padding: 5px 10px;
    font-size: 13px;
    border-radius: 6px;
}

.btn-icon {
    padding: 7px;
    border-radius: 6px;
    color: var(--text-muted);
}

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

/* Flash Alerts */
.flash-container {
    padding: 12px 24px 0 24px;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* Cards & Surfaces */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 9999px;
}

.badge-source {
    background: var(--badge-source-bg);
    color: var(--badge-source-text);
    border: 1px solid var(--badge-source-border);
    cursor: default;
}

.badge-info {
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
}

/* Modal Windows */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(15px);
    transition: transform 0.2s ease;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

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

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-muted);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Loading Spinners */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

.spinner-dark {
    border-color: rgba(2, 132, 199, 0.2);
    border-top-color: var(--primary);
}

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

/* Responsive Mobile Layout */
.mobile-nav-toggle {
    display: none;
    padding: 8px;
    font-size: 20px;
}

@media (max-width: 768px) {
    .main-nav {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transition: left 0.25s ease;
    }

    .main-nav.open {
        left: 0;
    }

    .mobile-nav-toggle {
        display: block;
    }
}

/* =========================================
   Mobile Responsive Layer
   ========================================= */

.mobile-header { display: none; }

.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.nav-overlay.active { display: block; opacity: 1; }

.nav-close-btn {
    display: none;
    position: absolute;
    top: 14px;
    right: 14px;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: #94a3b8;
    background: transparent;
    z-index: 10;
    cursor: pointer;
}
.nav-close-btn:hover { background: #1e293b; color: #f8fafc; }

.main-nav { position: relative; }

body.nav-open { overflow: hidden; }

@supports (height: 100dvh) {
    body,
    .app-container {
        height: 100dvh;
    }
}

@media (max-width: 768px) {

    .mobile-header {
        display: flex;
        align-items: center;
        gap: 10px;
        position: fixed;
        top: 0; left: 0; right: 0;
        height: 56px;
        padding: 0 12px;
        background: #0f172a;
        border-bottom: 1px solid #1e293b;
        z-index: 1000;
    }
    .mobile-header .brand-link { color: #fff; font-weight: 700; }

    .mobile-nav-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 8px;
        color: #f8fafc;
        background: transparent;
        border-radius: 8px;
    }
    .mobile-nav-toggle:active { background: #1e293b; }

    .app-container {
        display: block;
        padding-top: 56px;
        height: 100vh;
        height: 100dvh;
    }

    .main-nav {
        position: fixed;
        top: 0; left: -280px; bottom: 0;
        width: 260px; max-width: 80vw;
        z-index: 1001;
        transition: left 0.25s ease;
        box-shadow: 2px 0 16px rgba(0, 0, 0, 0.25);
        overflow-y: auto;
    }
    .main-nav.open { left: 0; }

    .nav-close-btn { display: flex; }
    .main-nav .nav-header { padding-right: 48px; }

    .app-content {
        width: 100%;
        height: calc(100vh - 56px);
        height: calc(100dvh - 56px);
        overflow-y: auto;
        overflow-x: hidden;
        padding: 12px;
    }

    .chat-container { flex-direction: column; height: auto; min-height: 100%; }
    .conv-sidebar   { width: 100%; max-height: 38vh; border-right: none; border-bottom: 1px solid var(--border); }
    .chat-main      { width: 100%; min-height: 0; }

    .files-page     { padding: 14px; }
    .files-toolbar  { flex-direction: column; align-items: stretch; }
    .search-wrapper { max-width: 100%; }

    .files-table th:nth-child(3),
    .files-table td:nth-child(3),
    .files-table th:nth-child(5),
    .files-table td:nth-child(5) {
        display: none;
    }

    .generate-page  { flex-direction: column; height: auto; }
    .generate-workspace { padding: 16px; }
    .form-grid      { grid-template-columns: 1fr; }

    .usage-page     { padding: 14px; }
    .metrics-grid   { grid-template-columns: 1fr; }

    .modal-content  { width: 94%; max-width: 94%; max-height: 90vh; }
}

@media (max-width: 480px) {
    .chat-header        { flex-direction: column; align-items: flex-start; gap: 8px; }
    .quick-prompts      { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .quick-prompt-btn   { flex-shrink: 0; }
    .input-toolbar      { flex-wrap: wrap; gap: 8px; }
    .files-table td,
    .files-table th     { padding: 10px 10px; }
}


.cloud-auth-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
}

.cloud-auth-title {
    font-size: 12px;
    line-height: 1.4;
    color: #cfd3dc;
    margin: 0 0 4px 0;
}

.cloud-auth-recommended {
    font-size: 11px;
    line-height: 1.4;
    color: #8b93a7;
    margin: 0 0 8px 0;
}

.cloud-auth-alt {
    font-size: 11px;
    line-height: 1.4;
    color: #8b93a7;
    margin: 4px 0 0 0;
    text-align: center;
}