:root {
    --bg: #0f172a;
    --surface: #0b1224;
    --card: #121b34;
    --accent: #4ade80;
    --accent-strong: #22c55e;
    --muted: #94a3b8;
    --text: #e2e8f0;
    --danger: #ef4444;
    --border: #1f2a44;
    --shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
    --radius: 12px;
    --radius-sm: 8px;
    font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
    margin: 0;
    background: radial-gradient(circle at 15% 20%, rgba(34,197,94,0.14), transparent 25%),
                radial-gradient(circle at 80% 0%, rgba(56,189,248,0.12), transparent 30%),
                var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: 80px; /* keep content clear of fixed footer on small screens */
}

a { color: var(--text); text-decoration: none; }
.link { color: var(--accent); font-weight: 600; }
.link.danger { color: var(--danger); }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: rgba(11, 18, 36, 0.9);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand {
    font-weight: 800;
    letter-spacing: 0.5px;
}
.nav a {
    margin-right: 16px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: background 0.2s ease, color 0.2s ease;
}
.nav a:last-child { margin-right: 0; }
.nav a.active, .nav a:hover {
    background: rgba(74, 222, 128, 0.12);
    color: var(--accent);
}
.user {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}
.logout { color: var(--danger); }

.container {
    max-width: 1200px;
    width: 100%;
    margin: 28px auto 140px;
    padding: 0 24px;
}
.container > section {
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

h1, h3 { margin: 0 0 12px 0; }
p { color: var(--muted); }

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

/* Ensure stack spacing after grids */
.panel + .panel {
    margin-top: 16px;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 16px;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 720px;
    width: 100%;
    max-height: 80vh;
    overflow: auto;
    box-shadow: var(--shadow);
    padding: 18px;
}
.modal header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}
.modal .close {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    cursor: pointer;
}
.reply-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.panel-header.contact-header h1 {
    margin: 0;
}
.panel-header.contact-header p {
    margin: 4px 0 0 0;
}
.panel-header.contact-header .btn {
    flex-shrink: 0;
    width: auto;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.card {
    background: var(--card);
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.card strong { font-size: 26px; }
.card p { margin: 0 0 4px 0; color: var(--muted); }

.grid.two {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
}

label {
    display: block;
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 10px;
}

input, select, textarea, button {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #0d1425;
    color: var(--text);
    font-size: 15px;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    outline: none;
}

textarea { resize: vertical; }

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    border: none;
    color: #052e16;
    font-weight: 700;
    cursor: pointer;
    margin-top: 8px;
    transition: transform 0.1s ease, box-shadow 0.2s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(34, 197, 94, 0.3); }
.btn:active { transform: translateY(0); }
.btn.w-100 { width: 100%; }
.btn.btn-compact {
    padding: 8px 12px;
    margin-top: 0;
    font-size: 14px;
    width: auto;
    flex: 0 0 auto;
}
.btn.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.search-hit {
    background: rgba(74, 222, 128, 0.3);
    padding: 0 2px;
    border-radius: 4px;
}
.btn.is-loading {
    opacity: 0.75;
    cursor: wait;
}

.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.bar-row {
    display: grid;
    grid-template-columns: 140px 1fr 50px;
    align-items: center;
    gap: 10px;
}
.bar-row .label { color: var(--text); font-weight: 600; }
.bar-track {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 999px;
    height: 12px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}
.bar-row .count {
    text-align: right;
    color: var(--text);
    font-weight: 700;
}

.flash {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    border: 1px solid var(--border);
}
.flash.success { background: rgba(34,197,94,0.12); color: var(--accent); }
.flash.error { background: rgba(239,68,68,0.12); color: var(--danger); }

.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
th, td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 600; }
tr:hover td { background: rgba(255,255,255,0.02); }

.pill {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 12px;
}

.pill_role {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(0, 128, 255, 0.434);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 12px;
}

.list { list-style: none; padding: 0; margin: 0; }
.list li {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    background: #0d1527;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }

.actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.inline-form { display: inline; }

.login-page {
    min-height: 100vh;
}
.login-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    min-height: calc(100vh - 60px);
}
.login-card {
    width: 360px;
    background: #0d1425;
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    text-align: center;
}

.app-footer {
    background: rgba(11, 18, 36, 0.9);
    border-top: 1px solid var(--border);
    padding: 12px 24px;
    color: var(--muted);
    position: fixed;
    width: 100%;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
}
.footer-content {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.footer-content .muted { color: var(--muted); }

@media (max-width: 768px) {
    .container {
        padding: 0 16px;
        margin: 16px auto 160px;
    }
    .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
    .nav { display: flex; flex-wrap: wrap; gap: 6px; }
    .nav a { margin: 0; }
    .panel-header { flex-direction: column; align-items: flex-start; }
    .grid.two, .field-grid, .stats {
        grid-template-columns: 1fr;
    }
    .login-main {
        padding: 16px;
        min-height: calc(100vh - 80px);
    }
    .login-card {
        width: 100%;
        max-width: 420px;
    }
    .footer-content {
        flex-direction: column;
        align-items: flex-start;
        padding: 0 16px;
        gap: 6px;
    }
    body {
        padding-bottom: 140px; /* extra clearance for the fixed footer on very small screens */
    }
}