/* style.css - Optimized & Consolidated */

:root {
    /* --- Palette --- */
    --bg-body: #f8fafc;       /* Slate 50 */
    --bg-surface: #ffffff;
    --bg-subtle: #f1f5f9;     /* Slate 100 */
    
    --text-primary: #0f172a;  /* Slate 900 */
    --text-secondary: #64748b;/* Slate 500 */
    --text-tertiary: #94a3b8; /* Slate 400 */
    
    --primary: #4f46e5;       /* Indigo 600 */
    --primary-hover: #4338ca; /* Indigo 700 */
    --primary-light: #e0e7ff; /* Indigo 50 - Active State BG */
    
    --border: #e2e8f0;        /* Slate 200 */
    
    --danger: #ef4444;        /* Red 500 */
    --danger-bg: #fef2f2;     /* Red 50 */
    --success: #10b981;       /* Emerald 500 */
    --success-bg: #ecfdf5;    /* Emerald 50 */

    /* --- Metrics --- */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-float: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --header-height: 60px;
    --sidebar-width: 280px;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* --- Resets & Base --- */
* { box-sizing: border-box; }

body {
    font-family: var(--font-family);
    background-color: var(--bg-body);
    color: var(--text-primary);
    margin: 0;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin-top: 0; color: var(--text-primary); letter-spacing: -0.01em; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
.hidden { display: none !important; }

/* --- Layouts --- */
.container-center {
    display: flex; justify-content: center; align-items: center;
    min-height: 100vh; padding: 1rem;
}

.layout-admin {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
    align-items: start;
}

/* --- Components: Cards & Banners --- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 2rem;
}
.card-body { padding: 1.5rem; }

/* Friendly "Soft Blue" Alert Banner */
.banner-alert {
    background-color: #eff6ff; /* Blue 50 */
    border: 1px solid #bfdbfe; /* Blue 200 */
    color: #1e40af;            /* Blue 800 */
    padding: 0.85rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    display: flex; align-items: flex-start; gap: 12px; line-height: 1.5;
}
.banner-alert .material-symbols-outlined {
    color: #3b82f6; /* Blue 500 */
    font-size: 1.25rem; margin-top: 1px; flex-shrink: 0;
}

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500; font-size: 0.9rem;
    cursor: pointer; transition: all 0.2s;
    gap: 6px; border: 1px solid transparent;
    white-space: nowrap;
}
.btn-block { width: 100%; justify-content: flex-start; }
.btn-icon { padding: 0.5rem; line-height: 0; }

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

.btn-secondary { background: white; border-color: var(--border); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-subtle); border-color: #cbd5e1; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-subtle); color: var(--text-primary); }

.btn-danger-solid { background: var(--danger); color: white; }
.btn-danger-solid:hover { background: #dc2626; }

.btn-success-anim {
    background-color: var(--success) !important;
    border-color: var(--success) !important;
    color: white !important;
    pointer-events: none;
    transform: scale(1.02);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.btn-label { display: none; margin-left: 6px; }

/* --- Forms --- */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: 0.75rem; font-weight: 700; color: var(--text-secondary); margin-bottom: 0.4rem; letter-spacing: 0.02em; text-transform: uppercase; }

input:not([type=checkbox]), select {
    width: 100%; padding: 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem; font-family: inherit;
    background-color: white; color: var(--text-primary);
    appearance: none;
}
select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat; background-position: right 0.7rem center; background-size: 1rem; padding-right: 2.5rem;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.input-success { border-color: var(--success) !important; background-color: var(--success-bg) !important; color: var(--success) !important; transition: all 0.3s ease; }

/* Custom Checkbox */
.check-wrapper { display: flex; align-items: center; cursor: pointer; }
.custom-checkbox {
    width: 20px; height: 20px;
    border: 2px solid var(--border); border-radius: 4px;
    display: grid; place-content: center;
    background: white; transition: all 0.2s;
}
.custom-checkbox::before {
    content: ""; width: 10px; height: 10px;
    background: white; transform: scale(0); transition: 0.15s;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
input[type="checkbox"]:checked + .custom-checkbox { background: var(--primary); border-color: var(--primary); }
input[type="checkbox"]:checked + .custom-checkbox::before { transform: scale(1); }
input[type="checkbox"] { display: none; }

/* --- Sidebar (Refined) --- */
.mobile-header { display: none; height: var(--header-height); background: var(--bg-surface); border-bottom: 1px solid var(--border); align-items: center; padding: 0 1rem; position: sticky; top: 0; z-index: 40; }
.mobile-menu-btn { background: transparent; border: none; padding: 0.5rem; margin-left: -0.5rem; cursor: pointer; color: var(--text-primary); display: flex; align-items: center; }

.sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    overflow-y: auto; z-index: 50; transition: transform 0.3s ease;
}
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); z-index: 45; opacity: 0; transition: opacity 0.3s; }
.logo { font-weight: 700; font-size: 1.1rem; margin-bottom: 2rem; display: flex; align-items: center; gap: 10px; color: var(--primary); cursor: pointer; user-select: none; }

.nav-label {
    font-size: 0.75rem; text-transform: uppercase; font-weight: 700;
    color: var(--text-tertiary); margin-top: 2rem; margin-bottom: 0.75rem; letter-spacing: 0.05em;
}
.nav-group { flex: 1; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }

.zone-item {
    padding: 0.75rem 1rem; border-radius: var(--radius-md);
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; transition: all 0.2s ease; border: 1px solid transparent;
    color: var(--text-primary);
}
.zone-item:hover { background: var(--bg-subtle); }
.zone-item.active { background: var(--primary-light); color: var(--primary); }
.zone-info { display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.zone-name { font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zone-meta { font-size: 0.75rem; color: var(--text-secondary); }
.zone-item.active .zone-meta { color: var(--primary); opacity: 0.9; }

.sidebar-footer { margin-top: auto; padding-top: 1rem; display: grid; gap: 0.5rem; border-top: 1px solid var(--border);}

/* --- Main Content --- */
.main-content { padding: 2rem; overflow-y: auto; position: relative; }

.header-hero {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 1.5rem; padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border); gap: 1rem;
}
.hero-title-group { display: flex; gap: 1rem; align-items: center; min-width: 0; }
.hero-icon { width: 52px; height: 52px; border-radius: 12px; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.hero-title { font-size: 1.5rem; font-weight: 700; line-height: 1.2; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hero-meta { font-size: 0.9rem; color: var(--text-secondary); }
.hero-actions { display: flex; align-items: center; gap: 0.75rem; }
.hero-actions form { margin: 0; display: flex; }

/* --- Control Bar & View Toggles --- */
.control-bar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.5rem; padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.view-toggles {
    display: flex; background: white;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    overflow: hidden;
}
.view-toggles .btn {
    border: none; border-radius: 0; background: transparent;
    color: var(--text-tertiary); padding: 0.4rem 0.8rem; margin: 0;
}
.view-toggles .btn:not(:last-child) { border-right: 1px solid var(--border); }
.view-toggles .btn.active {
    color: var(--bg-subtle); background: var(--primary);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.03);
}
.view-toggles .btn:hover:not(.active) { background: #f8fafc; color: var(--text-secondary); }

/* --- Utility Classes (extracted from inline styles) --- */
.text-center { text-align: center; }
.mb-2 { margin-bottom: 2rem; }
.card-narrow { width: 100%; max-width: 380px; }
.card-upload { width: 100%; max-width: 440px; }
.alert-error {
    padding: 0.5rem; border-radius: 6px; margin-bottom: 1rem;
    text-align: center; background: var(--danger); color: white;
}
.alert-success {
    background: var(--success-bg); color: var(--success);
    padding: 1rem; border-radius: var(--radius-sm); margin-bottom: 1.5rem;
}
.btn-center { justify-content: center; }
.btn-new-folder { margin-bottom: 1.5rem; }
.mobile-header-title { font-weight: 700; color: var(--primary); }
.form-inline { margin: 0; }
.empty-state {
    padding: 4rem; text-align: center; color: var(--text-secondary);
}
.empty-state-icon { font-size: 4rem; opacity: 0.2; }
.empty-state-text { margin-top: 1rem; }
.empty-select-folder {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 80vh; color: var(--text-secondary);
}
.hero-icon-lg { font-size: 2rem; }
.icon-sm { font-size: 1rem; }
.icon-muted { color: var(--text-tertiary); }
.icon-xl { font-size: 3rem; }
.check-label-inline { margin: 0; }
.check-label-text {
    margin-left: 8px; font-weight: 600; font-size: 0.8rem;
    letter-spacing: 0.05em; color: var(--text-secondary); text-transform: uppercase;
}
.check-label-normal {
    margin-top: 0.75rem; text-transform: none; font-weight: 400;
    color: var(--text-primary); font-size: 0.95rem;
}
.check-label-inner { margin-left: 8px; }
.form-hint { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }
.file-name-cell { display: flex; align-items: center; gap: 8px; }
.file-size-cell { width: 120px; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.actions-header-cell { text-align: right; width: 100%; }
.btn-danger-ghost,
.btn-danger-ghost:hover {
    color: var(--danger);
}
.btn-danger-ghost:hover {
    background: var(--danger-bg);
}
.btn-danger-ghost-grid,
.btn-danger-ghost-grid:hover {
    color: var(--danger);
    height: 100%;
}
.btn-danger-ghost-grid:hover {
    background: var(--danger-bg);
}
.th-check { width: 40px; }
.th-name { width: 100%; }
.th-actions { text-align: right; }
.welcome-title { margin-bottom: 0.5rem; }
.welcome-sub { margin-top: 0; margin-bottom: 2rem; }
.passcode-input-center { text-align: center; font-size: 1.1rem; letter-spacing: 0.05em; }
.continue-btn { justify-content: center; padding: 0.8rem; }
.icon-arrow { font-size: 1.1rem; margin-left: 4px; }
.auth-message { text-align: center; margin-top: 1rem; min-height: 1.2em; }
.upload-header { margin-bottom: 1.5rem; }
.upload-title { margin: 0; margin-bottom: 0.25rem; }
.expiry-display { margin-top: 0; margin-bottom: 0; color: var(--text-secondary); font-size: 0.9rem; display: none; }
.expiry-display.visible { display: block; }
.drop-zone-icon { font-size: 3rem; color: var(--text-tertiary); margin-bottom: 1rem; }
.drop-zone-title { font-weight: 500; color: var(--text-primary); margin-bottom: 0.25rem; }
.drop-zone-sub { font-size: 0.85rem; color: var(--text-secondary); }
.file-row-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.file-row-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.file-row-meta { display: flex; gap: 8px; }
.icon-close { font-size: 1rem; }

/* utility-bar and progress-stack - moved from index.html <style> */
.utility-bar { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.progress-stack { margin-top: 1.5rem; max-height: 300px; overflow-y: auto; }

/* --- User Upload UI --- */
.login-logo { display: block; margin: 0.5rem auto; max-height: 64px; width: auto; }
.drop-zone {
    border: 2px dashed var(--border); border-radius: var(--radius-lg);
    padding: 3rem 1.5rem; text-align: center; cursor: pointer;
    transition: all 0.2s ease; background: #fafafa; margin-bottom: 1.5rem;
}
.drop-zone:hover { border-color: #94a3b8; background: var(--bg-subtle); }
.drop-zone.dragover { border-color: var(--primary); background: var(--primary-light); }

.file-row { background: white; padding: 0.75rem; border-radius: var(--radius-md); border: 1px solid var(--border); margin-bottom: 0.5rem; box-shadow: var(--shadow-sm); }
.file-status { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); }
.progress-track { height: 6px; background: var(--bg-subtle); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); width: 0%; transition: width 0.2s linear; }
.progress-fill.done { background: var(--success); }
.progress-fill.error { background: var(--danger); }

.btn-cancel-upload {
    background: none; border: none; cursor: pointer; color: var(--text-tertiary);
    padding: 4px; display: flex; align-items: center; justify-content: center;
    border-radius: 50%; transition: all 0.2s;
}
.btn-cancel-upload:hover { background-color: var(--danger-bg); color: var(--danger); }

/* --- Tables & Grid --- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 0.75rem 1rem; font-size: 0.75rem; text-transform: uppercase; color: var(--text-tertiary); border-bottom: 1px solid var(--border); }
td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.selected { background-color: var(--primary-light); }
.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }
.file-name-link { font-weight: 500; color: var(--text-primary); }
.file-name-link:hover { color: var(--primary); text-decoration: underline; }

.grid-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.5rem; }
.grid-item {
    border: 1px solid var(--border); border-radius: var(--radius-md);
    overflow: hidden; background: white; transition: box-shadow 0.2s;
    position: relative; display: flex; flex-direction: column; cursor: pointer;
}
.grid-item:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.grid-item.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.grid-check { position: absolute; top: 14px; left: 14px; z-index: 10; } /* Fixed positioning */

.thumb {
    height: 130px; width: 100%; object-fit: cover;
    background: var(--bg-subtle); color: var(--text-tertiary);
    display: flex; align-items: center; justify-content: center;
}
.grid-info { padding: 0.8rem; flex: 1; display: flex; flex-direction: column; }
.grid-text { font-weight: 500; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid-meta { font-size: 0.75rem; color: var(--text-secondary); }
.grid-actions { margin-top: auto; padding-top: 0.75rem; display: flex; gap: 8px; }
.grid-actions .btn-grow .btn-label { display: inline; }
.grid-actions .btn-grow { flex: 1; justify-content: center; }
.grid-actions .btn-icon { flex: 0 0 auto; }

/* --- Bulk Bar (Fixed) --- */
.bulk-bar {
    position: fixed; bottom: 2rem; left: 50%;
    transform: translateX(-50%) translateY(150%);
    background: var(--text-primary); color: white;
    padding: 0.75rem 1.5rem; border-radius: 50px;
    display: flex; align-items: center; gap: 1.5rem;
    box-shadow: var(--shadow-float); z-index: 100;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    width: 90%; max-width: 500px;
}
.bulk-bar.visible { transform: translateX(-50%) translateY(0); }
.bulk-count { font-weight: 600; font-size: 0.9rem; white-space: nowrap; }
.bulk-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.bulk-actions form { margin: 0; display: flex; }

.btn-bulk {
    background: rgba(255,255,255,0.15); color: white; border: none;
    padding: 0.5rem 1rem; border-radius: 20px;
    font-size: 0.85rem; font-weight: 500; cursor: pointer;
    display: flex; align-items: center; gap: 6px; transition: background 0.2s; white-space: nowrap;
}
.btn-bulk:hover { background: rgba(255,255,255,0.25); }
.btn-bulk.danger:hover { background: var(--danger); }

/* --- Modals --- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px); z-index: 999;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; visibility: hidden; transition: all 0.2s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
    background: white; width: 100%; max-width: 420px;
    border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
    transform: scale(0.95); transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 {margin-bottom:0;}
.modal-body { padding: 1.5rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* --- Animations --- */
.fade-in { animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* --- Responsive --- */
@media (max-width: 768px) {
    .layout-admin { display: block; }
    .main-content { padding: 1rem; }
    .mobile-header { display: flex; }
    .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 280px; transform: translateX(-100%); box-shadow: 4px 0 10px rgba(0,0,0,0.1); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; opacity: 1; }
    .header-hero { flex-direction: column; align-items: stretch; gap: 1rem; }
    .hero-actions { justify-content: space-between; width: 100%; }
    
    table, thead, tbody, th, td, tr { display: block; }
    thead { display: none; }
    tr { background: white; border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 1rem; padding: 1rem; box-shadow: var(--shadow-sm); position: relative; }
    td { padding: 0.25rem 0; border: none; }
    td:first-child { position: absolute; top: 1rem; left: 1rem; width: auto; padding: 0; }
    td:nth-child(2) { font-weight: 500; font-size: 1rem; margin-bottom: 0.25rem; padding-left: 2rem; }
    td:nth-child(3) { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 0.75rem; padding-left: 2rem; }
    td:last-child { padding-top: 0.75rem; margin-top: 0.5rem; }
    .actions-cell { justify-content: space-between; width: 100%; gap: 1rem; }
    .actions-cell .btn .btn-label { display: inline; }
    .actions-cell .btn { flex: 1; justify-content: center; border-color: var(--border); background: white; }
    .btn-label { display: inline; }
    /* Grid view: show text labels on Download/Delete buttons on mobile */
    .grid-actions .btn .btn-label { display: inline; }
    .grid-actions .btn { flex: 1; justify-content: center; }
}