/* ── Variables ─────────────────────────────────────────────── */
:root {
    --bg:           #0e0e0e;
    --bg-surface:   #1a1a1a;
    --bg-raised:    #242424;
    --border:       #2e2e2e;
    --accent:       #abcc21;
    --accent-dim:   #8aaa10;
    --text:         #e8e8e8;
    --text-muted:   #888;
    --text-faint:   #555;
    --danger:       #e05555;
    --success:      #4caf7d;
    --radius:       8px;
    --radius-sm:    4px;
    --font:         'Inter', 'Segoe UI', system-ui, sans-serif;
    --mono:         'JetBrains Mono', 'Fira Code', monospace;
    --shadow:       0 2px 12px rgba(0,0,0,0.4);
    --transition:   0.18s ease;
}

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

html { font-size: 15px; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dim); }

/* ── Typography ─────────────────────────────────────────────── */
h1, h2, h3, h4 { font-weight: 600; line-height: 1.3; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

.mono { font-family: var(--mono); font-size: 0.85rem; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.accent { color: var(--accent); }
.danger { color: var(--danger); }
.success { color: var(--success); }

/* ── Layout ─────────────────────────────────────────────────── */
.page-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-logo img {
    height: 32px;
    width: auto;
}

.topbar-logo span {
    font-size: 0.8rem;
    color: var(--text-muted);
    border-left: 1px solid var(--border);
    padding-left: 12px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ── Sidebar (admin) ────────────────────────────────────────── */
.admin-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: calc(100vh - 60px);
}

.sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    padding: 24px 0;
}

.sidebar-nav { list-style: none; }

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 24px;
    color: var(--text-muted);
    font-size: 0.9rem;
    transition: background var(--transition), color var(--transition);
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background: var(--bg-raised);
    color: var(--text);
}

.sidebar-nav li a.active {
    border-left: 3px solid var(--accent);
    padding-left: 21px;
}

.sidebar-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    padding: 20px 24px 6px;
}

/* ── Main content ───────────────────────────────────────────── */
.main-content {
    padding: 32px;
    overflow-y: auto;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}

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

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: opacity var(--transition), background var(--transition);
    font-family: var(--font);
}

.btn:hover { opacity: 0.88; }
.btn:active { opacity: 0.75; }

.btn-primary {
    background: var(--accent);
    color: #0e0e0e;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
    width: 100%;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 9px 12px;
    font-size: 0.9rem;
    font-family: var(--font);
    transition: border-color var(--transition);
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead th {
    text-align: left;
    padding: 10px 14px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-raised); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-active {
    background: rgba(171, 204, 33, 0.15);
    color: var(--accent);
}

.badge-inactive {
    background: rgba(255,255,255,0.06);
    color: var(--text-faint);
}

.badge-expired {
    background: rgba(224, 85, 85, 0.12);
    color: var(--danger);
}

/* ── File tree (client portal) ──────────────────────────────── */
.file-tree { list-style: none; }

.file-tree li { border-bottom: 1px solid var(--border); }
.file-tree li:last-child { border-bottom: none; }

.tree-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    transition: background var(--transition);
    cursor: default;
}

.tree-row:hover { background: var(--bg-raised); }

.tree-icon {
    font-size: 1rem;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.tree-name {
    flex: 1;
    font-size: 0.9rem;
}

.tree-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-right: 12px;
}

.tree-folder { padding-left: 0; }
.tree-children { padding-left: 24px; }
.tree-children li { border-bottom: 1px solid rgba(255,255,255,0.04); }

.folder-toggle {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 11px 16px;
    font-size: 0.9rem;
    font-family: var(--font);
    transition: background var(--transition);
}

.folder-toggle:hover { background: var(--bg-raised); }

.folder-arrow {
    font-size: 0.65rem;
    color: var(--text-faint);
    transition: transform var(--transition);
}

.folder-arrow.open { transform: rotate(90deg); }

/* ── Upload zone ────────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    color: var(--text-muted);
    transition: border-color var(--transition), background var(--transition);
    cursor: pointer;
    margin-top: 24px;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--accent);
    background: rgba(171, 204, 33, 0.04);
}

.upload-zone p { margin-top: 8px; font-size: 0.85rem; }

.upload-progress {
    margin-top: 16px;
    display: none;
}

.progress-bar-wrap {
    background: var(--bg-raised);
    border-radius: 20px;
    height: 6px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.2s ease;
    border-radius: 20px;
}

/* ── Preview overlay ────────────────────────────────────────── */
.preview-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 999;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.preview-overlay.open { display: flex; }

.preview-box {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 900px;
    max-height: 90vh;
    width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.preview-body {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    min-height: 300px;
}

.preview-body img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.preview-body iframe {
    width: 100%;
    height: 70vh;
    border: none;
    background: #fff;
}

/* ── Login page ─────────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 380px;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo img { height: 36px; width: auto; }

.login-card h2 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 1.1rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* ── Client portal layout ───────────────────────────────────── */
.portal-wrap {
    max-width: 780px;
    margin: 0 auto;
    padding: 40px 24px;
}

.portal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.portal-header img { height: 30px; width: auto; }

.portal-meta { text-align: right; }
.portal-meta h2 { font-size: 1rem; margin-bottom: 4px; }
.portal-meta p { font-size: 0.8rem; color: var(--text-muted); }

.portal-expiry {
    display: inline-block;
    margin-top: 32px;
    font-size: 0.78rem;
    color: var(--text-faint);
    border-top: 1px solid var(--border);
    padding-top: 16px;
    width: 100%;
}

/* ── Toast notifications ────────────────────────────────────── */
.toast-wrap {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9999;
}

.toast {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 0.85rem;
    max-width: 300px;
    animation: toast-in 0.2s ease;
    box-shadow: var(--shadow);
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 500;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    padding: 28px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

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

/* ── Utilities ──────────────────────────────────────────────── */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.text-right { text-align: right; }
.w-full { width: 100%; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    .admin-layout {
        grid-template-columns: 1fr;
    }
    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 12px 0;
    }
    .main-content { padding: 20px 16px; }
    .portal-header { flex-direction: column; gap: 16px; }
    .portal-meta { text-align: left; }
}