:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface-2: #243044;
    --border: #2d3a4f;
    --text: #e8edf4;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

.container {
    width: min(1200px, 100% - 2rem);
    margin: 0 auto;
}

/* Topbar */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.875rem 0;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
    font-weight: 700;
    font-size: 1.1rem;
}

.brand-icon { font-size: 1.4rem; }

.nav {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}

.nav-link {
    color: var(--text-muted);
    padding: 0.5rem 0.875rem;
    border-radius: 8px;
    font-size: 0.925rem;
}

.nav-link:hover, .nav-link.active {
    color: var(--text);
    background: var(--surface-2);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.username {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.main { padding: 2rem 0 3rem; }

/* Auth */
.auth-card {
    max-width: 420px;
    margin: 4rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.auth-header { text-align: center; margin-bottom: 1.5rem; }
.auth-logo { font-size: 3rem; margin-bottom: 0.5rem; }
.auth-header h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.auth-header p { margin: 0; color: var(--text-muted); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="file"],
select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.flex-grow { flex: 1; min-width: 200px; }

.help-text {
    font-size: 0.825rem;
    color: var(--text-muted);
    margin: 0 0 0.5rem;
}

.checkbox-grid, .assign-form {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.checkbox-label input { width: auto; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.125rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
    color: inherit;
}

.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--border); color: var(--text); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
}

.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.825rem; }
.btn-block { width: 100%; }

.btn:disabled,
.btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

input:disabled,
input[disabled] {
    opacity: 0.7;
    cursor: not-allowed;
}

.upload-progress {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.upload-progress-bar-track {
    height: 10px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}

.upload-progress-bar-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--primary), #60a5fa);
    border-radius: 999px;
    transition: width 0.15s ease;
}

.upload-progress-bar-indeterminate {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    border-radius: 999px;
    animation: upload-indeterminate 1.2s ease-in-out infinite;
}

@keyframes upload-indeterminate {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(320%); }
}

.upload-file-info {
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.upload-file-info strong {
    color: var(--text);
    margin-right: 0.5rem;
}

.upload-progress-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    margin-top: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.upload-progress-percent {
    font-weight: 700;
    color: var(--text);
    min-width: 3rem;
}

.upload-progress-speed {
    margin-left: auto;
}

.upload-progress-status {
    margin: 0.625rem 0 0;
    font-size: 0.9rem;
    color: var(--text);
}

.upload-progress-error {
    margin: 0.625rem 0 0;
    padding: 0.75rem 1rem;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    border-radius: 8px;
    color: #fca5a5;
    font-size: 0.875rem;
}

.upload-progress-error[hidden] {
    display: none;
}

.inline-form { display: inline; }

/* Page */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.page-header h1 { margin: 0 0 0.25rem; font-size: 1.75rem; }
.subtitle { margin: 0; color: var(--text-muted); }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.panel h2 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.search-box { flex: 1; min-width: 200px; }
.sort-select { width: auto; min-width: 160px; }

/* Alerts */
.alert {
    padding: 0.875rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    font-size: 0.925rem;
}

.alert-success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: #86efac;
}

.alert-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

/* File grid (mobile) */
.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.file-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s;
}

.file-card:hover { border-color: var(--primary); }

.file-card-preview {
    background: var(--bg);
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-card-body { padding: 1rem; }

.file-card-title {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-card-meta {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.825rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.file-card-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0 0 0.75rem;
}

/* Table (desktop) */
.file-table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

.file-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.file-table th,
.file-table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.file-table th {
    background: var(--surface-2);
    font-weight: 600;
    font-size: 0.825rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.file-table tr:last-child td { border-bottom: none; }
.file-table tr:hover td { background: rgba(255, 255, 255, 0.02); }

.name-cell {
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.preview-cell { width: 72px; }

.actions-cell {
    display: flex;
    gap: 0.375rem;
    flex-wrap: wrap;
    align-items: center;
}

/* Preview / icons */
.preview-thumb {
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    display: block;
}

.preview-thumb img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.preview-thumb-lg img {
    width: 100%;
    height: 140px;
    object-fit: cover;
}

.file-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: var(--surface-2);
    border-radius: 8px;
}

.file-icon-lg {
    width: 100%;
    height: 140px;
    font-size: 3rem;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    background: var(--surface-2);
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.badge-admin { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.badge-user { background: rgba(148, 163, 184, 0.15); color: var(--text-muted); }
.badge-viewer { background: rgba(148, 163, 184, 0.15); color: var(--text-muted); }
.badge-contributor { background: rgba(34, 197, 94, 0.15); color: #86efac; }

.file-age-banner {
    margin-top: 0.75rem;
    max-width: 420px;
}

.file-row-warning td,
.file-row-warning .name-cell {
    background: rgba(239, 68, 68, 0.08);
}

.file-row-delete_soon td,
.file-row-delete_soon .name-cell {
    background: rgba(239, 68, 68, 0.15);
}

.file-age-badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.file-age-warning,
.file-age-delete_soon {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.file-age-text {
    font-size: 0.825rem;
    color: var(--text-muted);
}

.auth-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-brand h1 {
    margin: 0.5rem 0 0.25rem;
    font-size: 1.5rem;
}

.auth-brand .subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.status {
    font-size: 0.825rem;
    font-weight: 500;
}

.status-active { color: var(--success); }
.status-inactive { color: var(--text-muted); }
.status-ok { color: var(--success); }
.status-bad { color: var(--danger); }

.diagnostics-table th {
    text-align: left;
    width: 220px;
    color: var(--text-muted);
    font-weight: 500;
}

.diagnostics-table td code {
    word-break: break-all;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}

.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h2 { color: var(--text); margin: 0 0 0.5rem; }

/* Assign dropdown */
.assign-details { position: relative; display: inline-block; }

.assign-details summary {
    list-style: none;
    cursor: pointer;
}

.assign-details summary::-webkit-details-marker { display: none; }

.assign-form {
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 50;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    min-width: 200px;
    box-shadow: var(--shadow);
    margin-top: 0.25rem;
}

.assign-form input[type="password"] { margin-bottom: 0.5rem; }

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
}

.lightbox[hidden] { display: none; }

.lightbox-image {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    background: none;
    border: none;
    color: #fff;
    font-size: 2.5rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
}

.lightbox-close:hover { opacity: 1; }

/* Responsive */
@media (min-width: 769px) {
    .file-grid { display: none; }
}

@media (max-width: 768px) {
    .file-table-wrap { display: none; }

    .topbar-inner { gap: 0.75rem; }
    .nav { order: 3; width: 100%; }
    .user-menu { margin-left: auto; }

    .form-row { flex-direction: column; }
    .toolbar { flex-direction: column; }
    .sort-select { width: 100%; }
}
