:root {
    --bg: #0f172a;
    --card: #ffffff;
    --ink: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --error: #dc2626;
    --ok-bg: #ecfdf5;
    --ok-ink: #065f46;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: linear-gradient(160deg, #1e293b, #0f172a);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    line-height: 1.5;
}

.card {
    background: var(--card);
    width: 100%;
    max-width: 1040px;
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
}

/* Left column: image + headline + body, centered. */
.intro {
    padding: 40px 40px 32px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: #f8fafc;
    border-right: 1px solid var(--border);
}

.intro .hero {
    display: block;
    width: 100%;
    max-height: 300px;
    object-fit: cover;
    border-radius: 12px;
    margin: 8px 0 20px;
}

/* Right column: the form. */
.form-panel {
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

h1 {
    margin: 0 0 14px;
    font-size: 2rem;
    letter-spacing: -0.02em;
}

.body-text {
    color: var(--muted);
    font-size: 1.05rem;
}

/* Single column on narrower screens. */
@media (max-width: 780px) {
    .card { grid-template-columns: 1fr; max-width: 480px; }
    .intro { border-right: none; border-bottom: 1px solid var(--border); padding: 32px 28px; }
    .form-panel { padding: 28px; }
    h1 { font-size: 1.7rem; }
}

/* Forms */
.signup { display: flex; flex-direction: column; gap: 16px; }

.signup label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9rem; }

.signup input[type="text"],
.signup input[type="email"],
.signup input[type="number"],
.signup input[type="password"],
.signup select,
.signup textarea {
    font: inherit;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    width: 100%;
    background: #fff;
    color: var(--ink);
}

.signup textarea { resize: vertical; }

.signup input:focus,
.signup select:focus,
.signup textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.signup .consent {
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
    font-weight: 400;
    color: var(--muted);
    font-size: 0.88rem;
}

.signup .consent input { margin-top: 3px; }

/* Date of birth: three separate boxes (DD / MM / YYYY). */
.signup .dob-field { display: flex; flex-direction: column; gap: 6px; }
.dob-label { font-weight: 600; font-size: 0.9rem; }
.dob-row { display: flex; gap: 10px; }
.dob-row input { flex: 1; width: 100%; text-align: center; letter-spacing: 0.05em; }
.dob-row input[name="dob_y"] { flex: 1.5; }

button, .btn {
    font: inherit;
    font-weight: 600;
    background: var(--brand);
    color: #fff;
    border: none;
    padding: 13px 18px;
    border-radius: 9px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.15s;
}

button:hover, .btn:hover { background: var(--brand-dark); }

.err { color: var(--error); font-weight: 500; font-size: 0.82rem; }

.error-banner {
    background: #fef2f2;
    color: var(--error);
    padding: 12px 14px;
    border-radius: 9px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.thanks { text-align: center; padding: 20px 0; }
.thanks h2 { color: var(--ok-ink); margin: 0 0 8px; }

.notice {
    background: var(--ok-bg);
    color: var(--ok-ink);
    padding: 12px 16px;
    border-radius: 9px;
    margin: 0 0 20px;
}

/* Admin */
.admin-body {
    display: block;
    background: #f1f5f9;
    color: var(--ink);
    align-items: stretch;
    padding: 0;
}

.admin-topbar {
    background: #0f172a;
    color: #fff;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.admin-brand { display: flex; align-items: center; gap: 28px; }
.admin-brand strong { padding: 16px 0; }
.admin-topbar a { color: #cbd5e1; text-decoration: none; }
.admin-topbar a:hover { color: #fff; }

.admin-nav { display: flex; gap: 4px; }
.admin-nav a {
    padding: 18px 14px;
    font-weight: 600;
    font-size: 0.92rem;
    border-bottom: 3px solid transparent;
}
.admin-nav a.active { color: #fff; border-bottom-color: var(--brand); }

.admin-actions { display: flex; gap: 18px; font-size: 0.9rem; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-head h1 { margin: 0; font-size: 1.5rem; }

.dash-section { margin: 30px 0 14px; font-size: 1.15rem; }
.dash-section .muted { font-weight: 400; font-size: 0.9rem; }

/* Stat cards */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.stat-num { font-size: 2.2rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.stat-lbl { color: var(--muted); font-size: 0.9rem; }

/* Two-up panels on wide screens */
.panel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
}

/* Filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 14px;
}
.filters label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.82rem; }
.filters input, .filters select {
    font: inherit;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
}
.filters input[type="number"] { width: 90px; }
.filter-actions { display: flex; gap: 10px; }
.btn.ghost { background: #eef2ff; color: var(--brand-dark); }
.btn.ghost:hover { background: #e0e7ff; }

.custom-range { display: flex; gap: 14px; align-items: flex-end; }
/* Keep the age inputs together as a unit (wraps to its own line as a pair). */
.age-range { display: flex; gap: 14px; align-items: flex-end; }

.panel-full { margin-top: 24px; }

.zoom-ctrls { display: flex; gap: 8px; }
.zoom-ctrls .btn { padding: 4px 12px; font-size: 1rem; line-height: 1.4; min-width: 40px; }

/* Line chart (Over time) */
.chart-scroll { overflow-x: auto; width: 100%; }
.line-chart { display: block; height: 300px; }
.line-chart .grid { stroke: #eef2f7; stroke-width: 1; }
.line-chart .area { fill: rgba(79, 70, 229, 0.10); stroke: none; }
.line-chart .line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line-chart .dot { fill: var(--brand); }
.line-chart .yl { fill: var(--muted); font-size: 11px; text-anchor: end; }
.line-chart .xl { fill: var(--muted); font-size: 10px; text-anchor: start; }

/* Horizontal bar charts */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 44px; align-items: center; gap: 10px; }
.bar-label { font-size: 0.86rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: #eef2f7; border-radius: 6px; height: 20px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), #6366f1); border-radius: 6px; min-width: 2px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.86rem; }

.admin-wrap {
    width: 100%;
    max-width: 1500px;
    margin: 28px auto;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Keep data-entry forms a comfortable reading width even on wide screens
   (tables still use the full panel width to avoid horizontal scrolling). */
.panel > .signup { max-width: 680px; }

.panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
}
.panel h2 { margin: 0 0 18px; }

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.panel-head h2 { margin: 0; }

.preview {
    max-width: 220px;
    border-radius: 9px;
    border: 1px solid var(--border);
}

.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: #f8fafc; }

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

td.nowrap { white-space: nowrap; }
td.ua { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.82rem; }

.pager { display: flex; gap: 12px; align-items: center; margin-top: 16px; }
.pager-info { color: var(--muted); font-size: 0.9rem; }
.btn.disabled { opacity: 0.45; pointer-events: none; }

.card.admin { max-width: 380px; }
