/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --danger: #f85149;
    --success: #3fb950;
    --warning: #d29922;
    --radius: 6px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    --mono: 'SF Mono', 'Fira Code', monospace;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* === Login === */
.login-container {
    max-width: 400px;
    margin: 10vh auto;
    padding: 2rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.login-header { text-align: center; margin-bottom: 2rem; }
.lock-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.login-header h1 { font-size: 1.4rem; font-weight: 600; }
.subtitle { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.25rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.form-group input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
}
.form-group input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,166,255,0.15); }

.cf-turnstile { margin: 1rem 0; display: flex; justify-content: center; }

.error-msg {
    background: rgba(248,81,73,0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 0.5rem 0.8rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--bg-tertiary);
    color: var(--text);
    text-decoration: none;
}
.btn:hover { border-color: var(--text-muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger { background: rgba(248,81,73,0.15); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(248,81,73,0.25); }

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

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; padding: 0.7rem; }

/* === Nav === */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.5rem; }
.nav-brand { font-weight: 600; margin-right: 1rem; font-size: 0.95rem; }
.nav-link {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.nav-link:hover { color: var(--text); background: var(--bg-tertiary); }
.nav-link.active { color: var(--text); background: var(--bg-tertiary); }

#user-display { font-size: 0.85rem; color: var(--text-muted); }

/* === Files layout === */
.files-layout { display: flex; min-height: calc(100vh - 50px); }

.sidebar {
    width: 260px;
    padding: 1rem;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.sidebar h3 { font-size: 0.8rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.8rem; letter-spacing: 0.05em; }

.folder-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.1s;
    margin-bottom: 2px;
}
.folder-item:hover { background: var(--bg-tertiary); }
.folder-item.active { background: var(--bg-tertiary); color: var(--accent); }
.folder-item .folder-icon { font-size: 1rem; }
.folder-item .folder-count { margin-left: auto; color: var(--text-muted); font-size: 0.75rem; }
.folder-category {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin-top: 1rem;
    margin-bottom: 0.3rem;
    padding: 0 0.7rem;
}
.folder-category:first-child { margin-top: 0; }

.content { flex: 1; padding: 1.5rem; overflow-y: auto; }
.content-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.content-header h2 { font-size: 1.1rem; font-weight: 600; }

/* === File grid === */
.file-grid { display: flex; flex-direction: column; gap: 0.5rem; }

.file-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.7rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s;
}
.file-item:hover { border-color: var(--text-muted); }
.file-icon { font-size: 1.4rem; flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 0.9rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.1rem; }
.file-actions { display: flex; gap: 0.3rem; }

/* === Drop zone === */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
    transition: all 0.2s;
    margin-top: 1rem;
}
.drop-zone.dragover { border-color: var(--accent); background: rgba(88,166,255,0.05); color: var(--accent); }

/* === Progress === */
.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0.3rem;
}
.progress-fill { height: 100%; background: var(--accent); transition: width 0.3s; width: 0; }
#progress-text { font-size: 0.75rem; color: var(--text-muted); }

/* === Tables === */
.table-container { margin-top: 1rem; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 0.6rem 0.8rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: var(--bg-secondary); }

/* === Audit === */
.audit-header { display: flex; justify-content: space-between; align-items: center; padding: 1.5rem 1.5rem 0; }
.audit-filters { display: flex; gap: 0.5rem; padding: 1rem 1.5rem; }
.audit-filters select {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
}

.page { padding: 1.5rem; }
#page-files { padding: 0; }

.pagination { display: flex; gap: 0.3rem; padding: 1rem 1.5rem; justify-content: center; }
.pagination button {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
}
.pagination button.active { background: var(--accent); border-color: var(--accent); }

/* === Modal === */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
}
.modal h3 { margin-bottom: 1rem; font-size: 1.1rem; }
.modal .form-group { margin-bottom: 0.8rem; }
.modal .btn-row { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* === Badge === */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 500;
}
.badge-admin { background: rgba(88,166,255,0.15); color: var(--accent); }
.badge-lawyer { background: rgba(63,185,80,0.15); color: var(--success); }
.badge-readonly { background: rgba(139,148,158,0.15); color: var(--text-muted); }
.badge-active { background: rgba(63,185,80,0.15); color: var(--success); }
.badge-inactive { background: rgba(248,81,73,0.15); color: var(--danger); }

/* === Upload label === */
.upload-label { cursor: pointer; }

/* === File Preview === */
.preview-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
}
.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1.2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.preview-title {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 1rem;
}
.preview-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.preview-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 1rem;
}
.preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
    border-radius: var(--radius);
}
.preview-text {
    max-width: 900px;
    font-family: var(--mono);
}
.preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}

/* === View button === */
.btn-view { background: rgba(88,166,255,0.15); color: var(--accent); border-color: var(--accent); }
.btn-view:hover { background: rgba(88,166,255,0.25); }

.file-name-link:hover { color: var(--accent); text-decoration: underline; }

/* === Responsive === */
@media (max-width: 768px) {
    .files-layout { flex-direction: column; }
    .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
    .topbar { flex-wrap: wrap; gap: 0.5rem; }
}
