:root {
    --bg: #f3f4f6;
    --card: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --accent: #0f172a;
    --accent-soft: #1e293b;
    --sidebar-w: 244px;
    --radius: 16px;
    --radius-sm: 12px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Sidebar (left-hand navigation) --- */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1.5rem 1rem;
    background: var(--accent);
    color: #fff;
    overflow-y: auto;
}
.sidebar .brand { display: block; padding: 0.25rem 0.5rem 0; margin-bottom: 1.5rem; }
.sidebar .brand:hover { text-decoration: none; }
.brand-logo { width: 100%; max-width: 190px; height: auto; display: block; }
.sidebar-links { display: flex; flex-direction: column; gap: 0.2rem; }
.sidebar-links a {
    color: #cbd5e1;
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.sidebar-links a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); text-decoration: none; }
.sidebar-foot {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 1rem 0.8rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.nav-user { color: #fff; font-weight: 600; font-size: 0.92rem; }
.logout-form { margin: 0; }
.btn-link {
    background: none; border: none; color: #94a3b8;
    cursor: pointer; font: inherit; padding: 0; text-align: left;
    transition: color 0.15s;
}
.btn-link:hover { color: #fff; }

/* --- Main layout --- */
.container {
    max-width: 1080px;
    margin-left: var(--sidebar-w);
    padding: 2.5rem 3rem;
}
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; margin-bottom: 1.5rem;
}
h1 { font-size: 1.7rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 0.5rem; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem 1.75rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

/* --- Auth / login screen --- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.75rem;
    padding: 2rem;
    background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), var(--accent));
}
.auth-logo { width: 280px; max-width: 78vw; height: auto; }
.auth-card { width: 100%; max-width: 380px; margin: 0; }
.auth-card h1 { font-size: 1.4rem; margin-bottom: 1.1rem; }

/* --- Tables --- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    text-align: left; padding: 0.7rem 0.6rem;
    border-bottom: 1px solid var(--border); vertical-align: middle;
}
.table th {
    font-size: 0.75rem; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--muted);
}
.table tbody tr:hover { background: #f8fafc; }
.table tr:last-child td { border-bottom: none; }

.muted { color: var(--muted); font-size: 0.9rem; }

/* --- Badges & chips --- */
.badge {
    display: inline-block; padding: 0.2rem 0.65rem;
    border-radius: 999px; font-size: 0.75rem; font-weight: 600;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-in_progress { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-unpaid { background: #fee2e2; color: #991b1b; }
.badges { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.chip {
    display: inline-block; background: #eef2ff; color: #3730a3;
    border-radius: 8px; padding: 0.15rem 0.55rem;
    margin: 0 0.25rem 0.25rem 0; font-size: 0.82rem; font-weight: 500;
}

/* --- Buttons (rounded / pill) --- */
.btn {
    display: inline-block; cursor: pointer; font: inherit; font-size: 0.9rem; font-weight: 500;
    padding: 0.55rem 1.15rem; border-radius: 999px; border: 1px solid var(--border);
    background: #fff; color: var(--ink); text-decoration: none;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.btn:hover { background: #f8fafc; text-decoration: none; box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-sm { padding: 0.35rem 0.85rem; font-size: 0.82rem; }
.btn-block { display: block; width: 100%; text-align: center; }

/* --- Forms --- */
.form label { display: block; margin-bottom: 0.9rem; font-weight: 600; font-size: 0.9rem; }
.form input, .form select, .form textarea {
    display: block; width: 100%; margin-top: 0.35rem;
    padding: 0.6rem 0.75rem; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font: inherit; font-weight: 400; background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form input:focus, .form select:focus, .form textarea:focus,
.filters input:focus, .filters select:focus,
.inline-form input:focus, .inline-form select:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.form textarea { resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }

.services {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 0.75rem 1rem; margin-bottom: 0.9rem;
}
.services legend { font-weight: 600; font-size: 0.9rem; padding: 0 0.35rem; }
.check {
    display: inline-flex !important; align-items: center; gap: 0.35rem;
    width: 48%; margin-bottom: 0.5rem; font-weight: 400 !important;
}
.check input { width: auto !important; display: inline !important; margin: 0 !important; }

.form-actions { display: flex; gap: 0.6rem; margin-top: 0.5rem; }
.inline-form { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select {
    padding: 0.55rem 0.7rem; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font: inherit;
}

/* --- Filter bar --- */
.filters {
    display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.filters input[type="search"] {
    flex: 1 1 260px; min-width: 200px;
    padding: 0.55rem 0.9rem; border: 1px solid var(--border);
    border-radius: 999px; font: inherit; background: #fff;
}
.filters select {
    padding: 0.55rem 0.8rem; border: 1px solid var(--border);
    border-radius: 999px; font: inherit; background: #fff;
}

/* --- Definition list details --- */
.details { display: grid; grid-template-columns: 140px 1fr; gap: 0.4rem 1rem; margin: 0.5rem 0 0; }
.details dt { color: var(--muted); font-size: 0.85rem; }
.details dd { margin: 0; }

/* --- Alerts --- */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: 0.92rem; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* --- Dashboard stat tiles --- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.85rem; margin-bottom: 1.75rem; }
.stat {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.1rem; text-align: center;
    box-shadow: var(--shadow-sm);
}
.stat-num { display: block; font-size: 1.9rem; font-weight: 700; line-height: 1; }
.stat-label {
    display: block; margin-top: 0.4rem; font-size: 0.75rem;
    color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
}
.stat-pending .stat-num { color: #92400e; }
.stat-progress .stat-num { color: #1e40af; }
.stat-completed .stat-num { color: #166534; }
.stat-unpaid .stat-num { color: #991b1b; }

/* --- Responsive: sidebar collapses to a top bar --- */
@media (max-width: 768px) {
    .sidebar {
        position: static; width: 100%;
        flex-direction: row; align-items: center; flex-wrap: wrap;
        gap: 0.75rem; padding: 0.75rem 1rem;
    }
    .sidebar .brand { margin-bottom: 0; padding: 0; }
    .brand-logo { max-width: 150px; }
    .sidebar-links { flex-direction: row; flex-wrap: wrap; }
    .sidebar-foot {
        margin-top: 0; margin-left: auto;
        flex-direction: row; align-items: center; gap: 1rem;
        border-top: none; padding: 0;
    }
    .container { margin-left: 0; padding: 1.5rem; }
    .grid-2 { grid-template-columns: 1fr; }
    .check { width: 100%; }
    .details { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, 1fr); }
}

/* --- Audit / activity log --- */
.badge-audit-auth { background: #dcfce7; color: #166534; }
.badge-audit-auth-fail { background: #fee2e2; color: #991b1b; }
.badge-audit-request { background: #dbeafe; color: #1e40af; }
.badge-audit-file { background: #ede9fe; color: #5b21b6; }
.badge-audit-admin { background: #fef3c7; color: #92400e; }
.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.82rem;
}
.pager { display: flex; align-items: center; gap: 1rem; margin-top: 1.5rem; }
