:root {
    --d3s-red: #e3011e;
    --d3s-red-dark: #b8001a;
    --d3s-red-tint: #fdecee;
    --ink: #1f2328;
    --muted: #6b7280;
    --line: #e5e7eb;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

h1:focus { outline: none; }
h1 { font-size: 1.6rem; margin: 0 0 1.25rem; font-weight: 600; }
h2 { font-size: 1.2rem; margin: 2rem 0 .75rem; font-weight: 600; }
h1::after { content: ""; display: block; width: 48px; height: 3px; margin-top: .5rem; background: var(--d3s-red); border-radius: 2px; }

a { color: var(--d3s-red); }

/* ---------- Header / navigation ---------- */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .25rem 1.25rem;
    padding: .6rem 1.5rem;
    background: var(--surface);
    border-bottom: 3px solid var(--d3s-red);
    box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: .75rem; color: var(--ink); text-decoration: none; margin-right: .5rem; }
.brand img { height: 30px; width: auto; display: block; }
.brand span { font-weight: 600; font-size: 1.05rem; padding-left: .75rem; border-left: 1px solid var(--line); color: var(--muted); }

.nav-toggle { display: none; }
.nav-burger { display: none; margin-left: auto; cursor: pointer; padding: 1rem .6rem; border-radius: 8px; }
.nav-burger span, .nav-burger span::before, .nav-burger span::after {
    display: block; width: 22px; height: 2px; background: var(--ink); border-radius: 2px; content: ""; position: relative;
}
.nav-burger span::before { position: absolute; top: -7px; }
.nav-burger span::after { position: absolute; top: 7px; }

.nav-links { display: flex; align-items: center; gap: .25rem; flex: 1; }
.nav-links a {
    padding: .5rem .85rem;
    border-radius: 8px;
    color: var(--ink);
    text-decoration: none;
    font-weight: 500;
}
.nav-links a:hover { background: var(--d3s-red-tint); color: var(--d3s-red-dark); }
.nav-links a.active { background: var(--d3s-red); color: #fff; }

.logout-form { margin-left: auto; }

.content { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* ---------- Buttons & form controls ---------- */
button {
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    padding: .5rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--d3s-red);
    background: var(--d3s-red);
    color: #fff;
    transition: background .15s;
}
button:hover { background: var(--d3s-red-dark); border-color: var(--d3s-red-dark); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(227, 1, 30, .3); outline-offset: 1px; }
button.secondary, .logout-form button { background: transparent; color: var(--ink); border-color: #cbd0d7; }
button.secondary:hover, .logout-form button:hover { background: var(--bg); border-color: #9ca3af; }
button.danger { background: transparent; color: var(--d3s-red); }
button.danger:hover { background: var(--d3s-red-tint); }

input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=submit]), select {
    font: inherit;
    width: 100%;
    padding: .5rem .7rem;
    border: 1px solid #cbd0d7;
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
}
input[type=checkbox] { width: 1.15rem; height: 1.15rem; accent-color: var(--d3s-red); }

label { display: block; font-size: .875rem; font-weight: 500; color: var(--muted); }
label > input, label > select { margin-top: .25rem; }

/* ---------- Cards, forms ---------- */
.card, .filters {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
.card h2 { margin-top: 0; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem 1.25rem;
    align-items: end;
}
.form-grid .actions { grid-column: 1 / -1; display: flex; gap: .5rem; flex-wrap: wrap; }
.form-grid label.inline { display: flex; align-items: center; gap: .6rem; padding-bottom: .5rem; }
.form-grid label.inline input { width: auto; margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.filters label { flex: 1 1 160px; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; margin-bottom: 1.5rem; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--line); }
thead th { background: #fafafb; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: #fcfcfd; }
tbody tr:last-child td { border-bottom: 0; }
tfoot th { background: var(--d3s-red-tint); color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 1rem; border-bottom: 0; }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.badge { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--line); color: var(--ink); }
.badge.ok { background: #e6f6ea; color: #16723a; }
.badge.warn { background: #fff4d6; color: #8a5a00; }
.badge.bad { background: var(--d3s-red-tint); color: var(--d3s-red-dark); }

.empty { color: var(--muted); padding: 1.5rem; text-align: center; background: var(--surface); border: 1px dashed #cbd0d7; border-radius: var(--radius); }

/* ---------- Login ---------- */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
    background: linear-gradient(160deg, #fff 0%, #fff 55%, var(--d3s-red-tint) 100%);
}
.login-box {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    padding: 2rem;
    border-radius: 14px;
    border-top: 4px solid var(--d3s-red);
    box-shadow: 0 10px 30px rgba(16, 24, 40, .12);
}
.login-logo { display: block; height: 44px; margin: 0 auto 1.25rem; }
.login-box h1 { text-align: center; font-size: 1.3rem; }
.login-box h1::after { margin-left: auto; margin-right: auto; }
.login-box label { margin-bottom: 1rem; }
.login-box button { width: 100%; padding: .65rem 1rem; margin-top: .5rem; }

/* ---------- Validation / errors ---------- */
.error { color: var(--d3s-red-dark); background: var(--d3s-red-tint); border-radius: 8px; padding: .6rem .9rem; }
.success { color: #16723a; background: #e6f6ea; border-radius: 8px; padding: .6rem .9rem; }
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; font-size: .85rem; }

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1rem 1rem 1.5rem;
    color: white;
}
.blazor-error-boundary::after { content: "An error has occurred." }

/* ---------- Responsive ---------- */
@media (max-width: 800px) {
    .top-nav { padding: .25rem 1rem; }
    .nav-burger { display: block; }
    .nav-links, .logout-form { display: none; width: 100%; }
    .nav-toggle:checked ~ .nav-links { display: flex; flex-direction: column; align-items: stretch; order: 3; padding-top: .25rem; }
    .nav-toggle:checked ~ .logout-form { display: block; order: 4; margin: 0 0 .5rem; }
    .logout-form button { width: 100%; }
    .content { padding: 1rem; }
    h1 { font-size: 1.35rem; }
}

@media (max-width: 640px) {
    .brand span { display: none; }

    /* Tables become stacked cards; <td data-label="..."> supplies the caption. */
    table.data-table, .data-table tbody, .data-table tfoot, .data-table tr, .data-table td, .data-table th { display: block; width: 100%; }
    .data-table thead { position: absolute; left: -9999px; }
    .data-table tr { padding: .6rem 1rem; border-bottom: 1px solid var(--line); }
    .data-table tbody tr:last-child { border-bottom: 0; }
    .data-table td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .3rem 0; border: 0; text-align: right; }
    .data-table td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; flex: 0 0 40%; }
    .data-table td:empty { display: none; }
    .data-table td.actions-cell { justify-content: flex-end; }
    .data-table td.actions-cell::before { display: none; }
    .data-table tfoot tr { display: flex; flex-wrap: wrap; justify-content: space-between; background: var(--d3s-red-tint); border-bottom: 0; }
    .data-table tfoot th { width: auto; padding: .2rem 0; background: transparent; }
    .data-table tfoot th[colspan] { flex: 1; }
    .data-table tfoot th:empty { display: none; }
    .table-wrap { overflow: visible; }
    .filters label { flex-basis: 100%; }
    .filters button, .form-grid .actions button { flex: 1; }
}
