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

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    background: #f0f4f8;
    color: #1a2540;
    min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
    background: linear-gradient(135deg, #003087 0%, #00518a 100%);
    color: #fff;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 58px;
    box-shadow: 0 2px 8px rgba(0,0,0,.35);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: .5px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.header-logo {
    height: 42px;
    width: auto;
    display: block;
    flex-shrink: 0;
}

header .header-sub {
    font-size: .75rem;
    opacity: .75;
    margin-top: 2px;
}

header nav a {
    color: rgba(255,255,255,.85);
    text-decoration: none;
    margin-left: 20px;
    font-size: .85rem;
    transition: color .15s;
}
header nav a:hover { color: #fff; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 20px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #003087;
    margin-bottom: 20px;
    border-bottom: 2px solid #003087;
    padding-bottom: 8px;
}

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,.1);
    padding: 20px 24px;
    margin-bottom: 20px;
}

.card h2 {
    font-size: 1rem;
    font-weight: 600;
    color: #003087;
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: .5px;
}

/* ── Masterclass Grid (index page) ──────────────────────────────────────────── */
.masterclass-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-top: 8px;
}

.masterclass-card {
    background: #fff;
    border: 2px solid #d6e4f7;
    border-radius: 8px;
    padding: 18px 20px;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, box-shadow .15s, transform .1s;
    display: block;
}
.masterclass-card:hover {
    border-color: #003087;
    box-shadow: 0 4px 16px rgba(0,48,135,.15);
    transform: translateY(-2px);
}
.masterclass-card .mc-name {
    font-size: 1rem;
    font-weight: 600;
    color: #003087;
    margin-bottom: 6px;
}
.masterclass-card .mc-meta {
    font-size: .8rem;
    color: #667;
}
.masterclass-card .mc-date {
    font-size: .75rem;
    color: #999;
    margin-top: 8px;
}

.empty-state {
    text-align: center;
    color: #888;
    padding: 40px 0;
    font-size: .95rem;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 16px;
    border-radius: 5px;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background .15s, opacity .15s;
    text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: #003087; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #004bb5; }
.btn-success   { background: #1a7a3c; color: #fff; }
.btn-success:hover:not(:disabled) { background: #218a45; }
.btn-danger    { background: #c0392b; color: #fff; }
.btn-danger:hover:not(:disabled)  { background: #e03425; }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #5a6268; }
.btn-warning { background: #e67e22; color: #fff; }
.btn-warning:hover:not(:disabled) { background: #d35400; }
.btn-outline {
    background: transparent;
    border: 1.5px solid #003087;
    color: #003087;
}
.btn-outline:hover { background: #003087; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: .78rem; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 14px;
}
.form-group label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    margin-bottom: 5px;
    color: #445;
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 10px;
    border: 1.5px solid #cdd5e0;
    border-radius: 5px;
    font-size: .9rem;
    transition: border-color .15s;
    background: #fff;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #003087;
    box-shadow: 0 0 0 3px rgba(0,48,135,.12);
}
.form-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}
.form-row .form-group { flex: 1; margin-bottom: 0; }

/* ── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
    padding: 10px 14px;
    border-radius: 5px;
    font-size: .85rem;
    margin-bottom: 14px;
    display: none;
}
.alert-error   { background: #fdecea; color: #c0392b; border: 1px solid #f5c6c0; }
.alert-success { background: #edfaef; color: #1a7a3c; border: 1px solid #b7e8c3; }
.alert.show    { display: block; }

/* ── Admin Table ────────────────────────────────────────────────────────────── */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .87rem;
}
.admin-table th {
    background: #003087;
    color: #fff;
    padding: 9px 12px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}
.admin-table td {
    padding: 9px 12px;
    border-bottom: 1px solid #e8edf4;
    vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #f5f8ff; }
.admin-table tr.archived-row td { color: #999; font-style: italic; background: #fafafa; }
.admin-table tr.archived-row:hover td { background: #f2f2f2; }

/* ── Dataset Selector ───────────────────────────────────────────────────────── */
.dataset-bar {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,.1);
    padding: 14px 20px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.dataset-bar label { font-weight: 600; font-size: .9rem; }
.dataset-bar select {
    padding: 6px 10px;
    border: 1.5px solid #cdd5e0;
    border-radius: 5px;
    font-size: .9rem;
    background: #fff;
    min-width: 150px;
}
.dataset-bar select:focus { outline: none; border-color: #003087; }

.save-status {
    font-size: .8rem;
    padding: 4px 10px;
    border-radius: 12px;
    margin-left: auto;
}
.save-status.saving  { background: #fff3cd; color: #856404; }
.save-status.saved   { background: #d4edda; color: #155724; }
.save-status.error   { background: #f8d7da; color: #721c24; }
.save-status.hidden  { visibility: hidden; }

/* ── Event Table ────────────────────────────────────────────────────────────── */
.event-table-wrap {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,.1);
    overflow: auto;
    max-height: calc(100vh - 220px);
}

table.event-table {
    border-collapse: collapse;
    font-size: .82rem;
    min-width: 900px;
    width: 100%;
}

table.event-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

table.event-table thead tr:first-child th {
    background: #003087;
    color: #fff;
    padding: 8px 6px;
    text-align: center;
    border-right: 1px solid rgba(255,255,255,.2);
    font-size: .8rem;
    white-space: nowrap;
}
table.event-table thead tr:first-child th.group-fs {
    background: #00518a;
}
table.event-table thead tr:first-child th.group-ps {
    background: #1a5276;
}

table.event-table thead tr:nth-child(2) th {
    background: #e8edf8;
    color: #003087;
    padding: 6px 4px;
    text-align: center;
    border-right: 1px solid #d0d8ea;
    border-bottom: 2px solid #003087;
    font-weight: 700;
    font-size: .78rem;
    white-space: nowrap;
}

table.event-table tbody tr:nth-child(odd)  td { background: #fafbff; }
table.event-table tbody tr:nth-child(even) td { background: #fff; }
table.event-table tbody tr:hover td { background: #edf3ff; }

table.event-table td {
    padding: 3px 4px;
    text-align: center;
    border-right: 1px solid #e8edf4;
    border-bottom: 1px solid #e8edf4;
    vertical-align: middle;
}

td.event-num {
    font-weight: 700;
    color: #003087;
    min-width: 34px;
    background: #f0f4fc !important;
    border-right: 2px solid #003087 !important;
    font-size: .8rem;
}

td.radio-cell {
    min-width: 34px;
    max-width: 50px;
}
td.radio-cell input[type="radio"] {
    cursor: pointer;
    width: 14px;
    height: 14px;
    accent-color: #003087;
}

td.mass-cell { min-width: 80px; }
.mass-input {
    width: 72px;
    padding: 2px 5px;
    border: 1.5px solid #cdd5e0;
    border-radius: 4px;
    font-size: .82rem;
    text-align: right;
    background: #f5f7fa;
    color: #999;
    transition: border-color .15s, background .15s, color .15s;
}
.mass-input:not(:disabled) {
    background: #fff;
    color: #1a2540;
    border-color: #003087;
}
.mass-input:focus { outline: none; box-shadow: 0 0 0 2px rgba(0,48,135,.2); }
.mass-input:disabled { cursor: not-allowed; }

td.clear-cell { min-width: 32px; }
.btn-clear-row {
    background: none;
    border: none;
    color: #c0392b;
    cursor: pointer;
    font-size: .9rem;
    padding: 2px 5px;
    border-radius: 3px;
    line-height: 1;
    opacity: .5;
    transition: opacity .15s;
}
.btn-clear-row:hover { opacity: 1; background: #fdecea; }

/* Totals row */
tfoot tr.totals-row td {
    background: #d6e4f7 !important;
    font-weight: 700;
    color: #003087;
    border-top: 2px solid #003087;
    padding: 5px 4px;
    font-size: .82rem;
    position: sticky;
    bottom: 0;
    z-index: 5;
}
tfoot tr.totals-row td.totals-label {
    text-align: right;
    padding-right: 8px;
    background: #b8d0f0 !important;
    border-right: 2px solid #003087 !important;
}

/* ── Summary Page ───────────────────────────────────────────────────────────── */
.summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
@media (max-width: 720px) { .summary-grid { grid-template-columns: 1fr; } }

.totals-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .87rem;
}
.totals-table th {
    background: #003087;
    color: #fff;
    padding: 8px 12px;
    text-align: left;
}
.totals-table td {
    padding: 7px 12px;
    border-bottom: 1px solid #e8edf4;
}
.totals-table tr:last-child td { border-bottom: none; }
.totals-table tr:hover td { background: #f5f8ff; }
.totals-table td:last-child {
    font-weight: 700;
    color: #003087;
    text-align: right;
}

.histogram-controls {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.histogram-controls .form-group {
    margin-bottom: 0;
    min-width: 100px;
}
.histogram-controls label { font-size: .8rem; }
.histogram-controls input {
    padding: 6px 8px;
    border: 1.5px solid #cdd5e0;
    border-radius: 5px;
    font-size: .87rem;
    width: 90px;
}
.histogram-controls input:focus {
    outline: none;
    border-color: #003087;
    box-shadow: 0 0 0 2px rgba(0,48,135,.12);
}

.chart-container {
    position: relative;
    height: 340px;
}

.summary-back {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    text-decoration: none;
    color: #003087;
    font-size: .88rem;
    font-weight: 600;
    margin-bottom: 14px;
}
.summary-back:hover { text-decoration: underline; }

/* ── Login Modal ────────────────────────────────────────────────────────────── */
.login-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.login-box {
    background: #fff;
    border-radius: 10px;
    padding: 32px 36px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 40px rgba(0,0,0,.25);
}
.login-box h2 { color: #003087; margin-bottom: 20px; font-size: 1.15rem; }
.login-box .form-group { margin-bottom: 16px; }
.login-box .form-group input {
    font-size: .95rem;
    padding: 10px 12px;
}

/* ── Particle statistics ────────────────────────────────────────────────────── */
.stats-section-title {
    font-size: .82rem;
    font-weight: 700;
    color: #003087;
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 10px;
}

.stat-ratio-row td {
    background: #edf3ff;
    font-weight: 700;
    border-top: 1px solid #c5d6f0;
}

/* ── Index masterclass table ────────────────────────────────────────────────── */
.mc-name-cell {
    font-weight: 600;
    color: #1a2540;
}


/* ── Misc ───────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: .74rem;
    font-weight: 700;
}
.badge-blue     { background: #d6e4f7; color: #003087; }
.badge-green    { background: #d4edda; color: #155724; }
.badge-archived { background: #f5e6d3; color: #7a4f1d; }

.spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid #cdd5e0;
    border-top-color: #003087;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row td {
    text-align: center;
    padding: 30px;
    color: #888;
    font-size: .9rem;
}

/* ── Aggregation action bar (index page) ────────────────────────────────────── */
.agg-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 18px;
    background: #e8f0fe;
    border: 1.5px solid #aac4f5;
    border-radius: 8px;
    margin-top: 12px;
    font-size: .9rem;
    font-weight: 600;
    color: #003087;
}
.agg-bar .agg-label { flex: 1; }

.cb-col { width: 36px; text-align: center; }
.mc-select-cb {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #003087;
    vertical-align: middle;
}

/* ── Responsive tweaks ──────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    header h1 { font-size: 1rem; }
    .container { padding: 14px 10px; }
    .form-row { flex-direction: column; }
    .dataset-bar { flex-direction: column; align-items: flex-start; }
}
