:root {
    --rm-bg: #f4f5f7;
    --rm-surface: #ffffff;
    --rm-text: #24272c;
    --rm-muted: #68707b;
    --rm-border: #dfe3e8;
    --rm-primary: #b51f2e;
    --rm-primary-dark: #8f1723;
    --rm-header: #17191d;
    --rm-header-text: #f5f6f7;
    --rm-error-bg: #fce8e8;
    --rm-error-text: #8b1c1c;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--rm-bg);
    color: var(--rm-text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
}

.container {
    width: min(1440px, calc(100% - 20px));
    margin: 0 auto;
}

.topbar {
    background: var(--rm-header);
    color: var(--rm-header-text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.topbar-inner {
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.brand-logo {
    display: block;
    max-height: 54px;
    max-width: 260px;
    object-fit: contain;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.main-nav a,
.nav-button {
    border: 0;
    background: transparent;
    color: var(--rm-header-text);
    cursor: pointer;
    font: inherit;
    padding: 10px 14px;
    text-decoration: none;
    border-radius: 5px;
}

.main-nav a:hover,
.main-nav a.active,
.nav-button:hover {
    background: rgba(255, 255, 255, .1);
}

.nav-form {
    margin: 0;
}

.hero {
    background: linear-gradient(180deg, #ffffff 0%, #eef0f3 100%);
    border-bottom: 1px solid var(--rm-border);
    padding: 72px 0 64px;
    text-align: center;
}

.hero-logo {
    display: block;
    max-width: min(520px, 90%);
    max-height: 180px;
    object-fit: contain;
    margin: 0 auto 22px;
}

.hero h1 {
    margin: 0;
    font-size: clamp(2rem, 5vw, 3.6rem);
}

.hero-subtitle {
    color: var(--rm-muted);
    font-size: 1.15rem;
    margin: 12px auto 28px;
}

.button {
    display: inline-block;
    padding: 11px 20px;
    border-radius: 6px;
    border: 0;
    cursor: pointer;
    font-weight: 700;
    text-decoration: none;
}

.button-primary {
    background: var(--rm-primary);
    color: #fff;
}

.button-primary:hover {
    background: var(--rm-primary-dark);
}

.button-full {
    width: 100%;
}

.home-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    padding: 38px 0 56px;
}

.card,
.auth-card {
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .04);
}

.card {
    padding: 24px;
}

.card h2 {
    margin-top: 0;
}

.auth-section {
    min-height: calc(100vh - 150px);
    display: grid;
    place-items: center;
    padding: 48px 16px;
}

.auth-card {
    width: min(430px, 100%);
    padding: 30px;
}

.auth-card h1 {
    margin: 0;
}

.muted {
    color: var(--rm-muted);
}

.auth-form {
    display: grid;
    gap: 10px;
    margin-top: 24px;
}

.auth-form input[type="email"],
.auth-form input[type="text"],
.auth-form input[type="password"] {
    width: 100%;
    border: 1px solid #cdd3da;
    border-radius: 6px;
    padding: 11px 12px;
    margin-bottom: 8px;
    font: inherit;
}

.auth-form input:focus {
    outline: 2px solid rgba(181, 31, 46, .18);
    border-color: var(--rm-primary);
}

.checkbox-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 5px 0 12px;
}

.alert {
    border-radius: 6px;
    padding: 11px 12px;
    margin-top: 18px;
}

.alert-error {
    background: var(--rm-error-bg);
    color: var(--rm-error-text);
}

.dashboard {
    padding: 38px 0 56px;
}

.dashboard > .card {
    margin-bottom: 18px;
}

.status {
    font-weight: 700;
}

.status-admin {
    color: #166534;
}

.status-disabled {
    color: #991b1b;
}

.site-footer {
    color: var(--rm-muted);
    text-align: center;
    padding: 22px 0;
    border-top: 1px solid var(--rm-border);
}

.site-footer-line {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: .88rem;
}

.site-footer a {
    color: var(--rm-text);
    text-decoration: none;
}

.site-footer a:hover {
    color: var(--rm-primary);
    text-decoration: underline;
}

.site-footer strong {
    font-weight: 700;
}

.site-footer-product {
    color: var(--rm-primary);
}

.site-footer-separator {
    color: var(--rm-muted);
}

@media (max-width: 620px) {
    .site-footer-line {
        gap: 4px;
        font-size: .8rem;
    }
}

@media (max-width: 760px) {
    .topbar-inner {
        align-items: flex-start;
        flex-direction: column;
        padding: 12px 0;
    }

    .brand-logo {
        max-width: 210px;
    }

    .main-nav {
        width: 100%;
        flex-wrap: wrap;
    }

    .home-grid {
        grid-template-columns: 1fr;
    }

    .hero {
        padding: 48px 0;
    }
}


/* Administration */
.admin-section {
    padding: 38px 0 56px;
}

.narrow-section {
    max-width: 920px;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.page-header h1 {
    margin: 0;
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.admin-tile {
    display: block;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    padding: 24px;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .04);
}

.admin-tile:hover {
    border-color: #b8bec6;
    box-shadow: 0 5px 16px rgba(0, 0, 0, .08);
}

.admin-tile h2 {
    margin-top: 0;
}

.table-card,
.form-card,
.danger-card {
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .04);
}

.table-card {
    overflow: hidden;
}

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

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 13px 14px;
    text-align: left;
    border-bottom: 1px solid var(--rm-border);
    vertical-align: middle;
}

.data-table th {
    background: #f8f9fa;
    font-size: .9rem;
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.table-actions {
    text-align: right !important;
    white-space: nowrap;
}

.empty-cell {
    text-align: center !important;
    color: var(--rm-muted);
    padding: 30px !important;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    background: #eceff2;
    font-size: .82rem;
    margin: 2px 4px 2px 0;
}

.badge-ok {
    background: #e2f4e7;
    color: #166534;
}

.badge-off {
    background: #eceff2;
    color: #626a75;
}

.form-card,
.danger-card {
    padding: 24px;
}

.danger-card {
    margin-top: 22px;
    border-color: #efc8c8;
}

.danger-card h2 {
    margin-top: 0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.field {
    display: grid;
    gap: 7px;
}

.field-full {
    grid-column: 1 / -1;
}

.field label,
.form-card > label {
    font-weight: 700;
}

.field input,
.field select,
.membership-row select {
    width: 100%;
    border: 1px solid #cdd3da;
    border-radius: 6px;
    padding: 10px 11px;
    font: inherit;
    background: #fff;
}

.field input:focus,
.field select:focus,
.membership-row select:focus {
    outline: 2px solid rgba(181, 31, 46, .18);
    border-color: var(--rm-primary);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

.button-secondary {
    background: #e9ecef;
    color: #262a2f;
}

.button-secondary:hover {
    background: #dfe3e7;
}

.button-danger {
    background: #a61d2a;
    color: #fff;
}

.button-danger:hover {
    background: #831720;
}

.button-small {
    padding: 7px 11px;
    font-size: .9rem;
}

.alert-success {
    background: #e4f5e9;
    color: #166534;
    margin-bottom: 18px;
}

.error-list {
    margin: 0;
    padding-left: 20px;
}

.option-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.section-divider {
    border-top: 1px solid var(--rm-border);
    margin: 26px 0;
}

.membership-list {
    display: grid;
    gap: 9px;
}

.membership-row {
    display: grid;
    grid-template-columns: 1fr 180px;
    gap: 16px;
    align-items: center;
    border: 1px solid var(--rm-border);
    border-radius: 7px;
    padding: 10px 12px;
}

.membership-name {
    margin: 0;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 22px;
    color: var(--rm-muted);
}

.pagination a {
    color: var(--rm-primary);
    font-weight: 700;
    text-decoration: none;
}

.pagination-disabled {
    opacity: .5;
}

@media (max-width: 760px) {
    .page-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .admin-grid,
    .form-grid,
    .option-grid {
        grid-template-columns: 1fr;
    }

    .membership-row {
        grid-template-columns: 1fr;
    }

    .form-actions {
        justify-content: stretch;
        flex-direction: column-reverse;
    }

    .form-actions .button {
        text-align: center;
    }
}


.header-actions,
.tile-actions,
.serial-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.tile-actions {
    margin-top: 18px;
}

.field textarea {
    width: 100%;
    border: 1px solid #cdd3da;
    border-radius: 6px;
    padding: 10px 11px;
    font: inherit;
    background: #fff;
    resize: vertical;
}

.field textarea:focus {
    outline: 2px solid rgba(181, 31, 46, .18);
    border-color: var(--rm-primary);
}

.serial-input-row input {
    flex: 1 1 280px;
}

.serial-input-row .button {
    white-space: nowrap;
}

code {
    font-family: Consolas, "Courier New", monospace;
    font-size: .92em;
}

@media (max-width: 760px) {
    .header-actions {
        width: 100%;
    }
}


.inline-form {
    display: inline-block;
    margin: 0;
}


.quick-entry-card,
.copy-entry-card {
    margin-bottom: 22px;
}

.quick-entry-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.quick-entry-heading h2,
.copy-entry-card h2 {
    margin-top: 0;
    margin-bottom: 4px;
}

.quick-entry-grid {
    display: grid;
    grid-template-columns:
        minmax(200px, 1.8fr)
        72px
        minmax(120px, .9fr)
        minmax(120px, .9fr)
        minmax(130px, 1fr)
        minmax(120px, 1fr)
        minmax(110px, .85fr)
        minmax(170px, 1.35fr)
        78px
        auto;
    gap: 8px;
    align-items: end;
}

.quick-entry-grid .field {
    min-width: 0;
}

.quick-entry-grid input,
.quick-entry-grid select,
.copy-entry-form select {
    width: 100%;
    border: 1px solid #cdd3da;
    border-radius: 6px;
    padding: 8px 8px;
    font: inherit;
    background: #fff;
}

.quick-entry-grid input,
.quick-entry-grid select,
.quick-entry-grid label {
    font-size: .84rem;
}

.quick-entry-grid .quick-class {
    max-width: 78px;
}

.quick-submit {
    padding-bottom: 1px;
}

.service-park-filter-grid {
    grid-template-columns: minmax(140px, 180px) minmax(320px, 520px) auto;
    justify-content: start;
}

@media (max-width: 760px) {
    .service-park-filter-grid {
        grid-template-columns: 1fr;
    }
}

.copy-entry-form {
    display: grid;
    grid-template-columns: minmax(260px, 2fr) minmax(200px, 1fr) auto;
    gap: 12px;
    align-items: end;
}

.copy-entry-action {
    padding-bottom: 1px;
}

.order-actions {
    white-space: nowrap;
}

.order-button {
    width: 30px;
    height: 30px;
    border: 1px solid var(--rm-border);
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
    font-weight: 700;
}

.order-button:hover {
    background: #f0f2f4;
}

@media (max-width: 1100px) {
    .quick-entry-grid {
        grid-template-columns: repeat(4, minmax(140px, 1fr));
    }
}

@media (max-width: 760px) {
    .quick-entry-heading {
        flex-direction: column;
    }

    .quick-entry-grid,
    .copy-entry-form {
        grid-template-columns: 1fr;
    }
}


/* Public classifications */
.public-section {
    padding: 38px 0 56px;
}

.public-rally-grid {
    display: grid;
    gap: 16px;
}

.public-rally-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    padding: 20px 22px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .04);
}

.public-rally-card h2 {
    margin: 0 0 5px;
}

.public-rally-card p {
    margin: 4px 0;
}

.classification-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 20px;
}

.classification-header h1 {
    margin: 6px 0 0;
}

.classification-back,
.home-card-link {
    color: var(--rm-primary);
    font-weight: 700;
    text-decoration: none;
}

.classification-back:hover,
.home-card-link:hover {
    text-decoration: underline;
}

.classification-stage-picker {
    display: grid;
    gap: 6px;
    min-width: min(360px, 100%);
}

.classification-stage-picker label {
    font-weight: 700;
}

.classification-stage-picker select {
    width: 100%;
    border: 1px solid #cdd3da;
    border-radius: 6px;
    padding: 10px 11px;
    font: inherit;
    background: #fff;
}

.classification-stage-nav {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    margin-bottom: 12px;
}

.classification-stage-title {
    text-align: center;
    font-size: 1.15rem;
    font-weight: 700;
}

.live-status {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 8px 0 18px;
    font-size: .92rem;
}

.live-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #238636;
    box-shadow: 0 0 0 3px rgba(35, 134, 54, .12);
}

.classification-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.classification-panel {
    min-width: 0;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .04);
}

.classification-panel-header {
    padding: 16px 18px;
    border-bottom: 1px solid var(--rm-border);
    background: #f8f9fa;
}

.classification-panel-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.classification-table {
    width: 100%;
    border-collapse: collapse;
}

.classification-table th,
.classification-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--rm-border);
    text-align: left;
    vertical-align: middle;
}

.classification-table th {
    background: #fbfbfc;
    font-size: .85rem;
}

.classification-table tbody tr:last-child td {
    border-bottom: 0;
}

.classification-position {
    width: 58px;
    font-weight: 700;
}

.classification-time,
.classification-gap {
    white-space: nowrap;
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

.classification-note {
    margin-top: 2px;
    color: var(--rm-muted);
    font-size: .76rem;
}

.home-rally-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid var(--rm-border);
}

.home-rally-row:last-of-type {
    border-bottom: 0;
}

.home-card-link {
    display: inline-block;
    margin-top: 16px;
}

@media (max-width: 900px) {
    .classification-grid {
        grid-template-columns: 1fr;
    }

    .classification-header {
        align-items: stretch;
        flex-direction: column;
    }
}

@media (max-width: 620px) {
    .public-rally-card {
        align-items: stretch;
        flex-direction: column;
    }

    .classification-stage-nav {
        grid-template-columns: 1fr 1fr;
    }

    .classification-stage-title {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .classification-table th,
    .classification-table td {
        padding: 9px 8px;
    }
}


/* Classification table: legacy-inspired dense layout */
.classification-table th {
    vertical-align: middle;
}

.classification-table th span {
    font-size: .72rem;
    font-weight: 600;
}

.classification-table .col-pos {
    width: 52px;
}

.classification-table .col-flag {
    width: 42px;
    text-align: center;
}

.classification-table .col-maker {
    width: 92px;
    text-align: center;
}

.classification-table .col-time {
    width: 105px;
}

.classification-table .col-gap {
    width: 105px;
}

.classification-driver {
    min-width: 0;
}

.driver-name-full,
.driver-name-short {
    line-height: 1.15;
}

.driver-surname {
    letter-spacing: .01em;
}

.driver-name-short {
    display: none;
}

.classification-vehicle {
    margin-top: 3px;
    font-size: .78rem;
    color: var(--rm-muted);
    line-height: 1.15;
}

.nationality-flag {
    display: block;
    max-width: 28px;
    max-height: 20px;
    object-fit: contain;
    margin: 0 auto;
    border: 1px solid rgba(0, 0, 0, .12);
}

.maker-logo {
    display: block;
    max-width: 50px;
    max-height: 26px;
    object-fit: contain;
    margin: 0 auto;
}

.classification-tires {
    display: block;
    margin-top: 3px;
    color: var(--rm-muted);
    font-size: .68rem;
    line-height: 1.1;
    text-align: center;
}

.classification-tires-empty {
    visibility: hidden;
}

.classification-tires-inline {
    display: none;
    margin-top: 2px;
    color: var(--rm-muted);
    font-size: .7rem;
    line-height: 1.1;
}

.classification-primary-time {
    font-weight: 700;
}

.classification-penalty,
.classification-gap-previous {
    margin-top: 2px;
    font-size: .76rem;
    line-height: 1.1;
}

.classification-penalty {
    color: #9a3412;
}

.classification-penalty-empty {
    visibility: hidden;
}

.classification-ti {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 4px;
    border-radius: 4px;
    background: #fff1c2;
    color: #6d4c00;
    font-size: .68rem;
    font-weight: 700;
    vertical-align: 1px;
}

.classification-row-in-progress {
    font-style: italic;
}

.classification-in-progress {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 999px;
    background: #fff1c2;
    color: #6d4c00;
    font-size: .78rem;
    font-style: normal;
    font-weight: 700;
    white-space: nowrap;
}

.classification-table tbody tr:nth-child(even) {
    background: #f7fbf8;
}

.classification-table tbody tr:hover {
    background: #eef6f1;
}

/* First responsive step: remove province flags. */
@media (max-width: 1180px) {
    .classification-table .col-flag {
        display: none;
    }
}

/* Second step: remove maker logos and tighten secondary text. */
@media (max-width: 980px) {
    .classification-table .col-maker {
        display: none;
    }

    .classification-tires-inline {
        display: block;
    }

    .classification-table .col-time,
    .classification-table .col-gap {
        width: 92px;
    }

    .classification-vehicle {
        font-size: .73rem;
    }
}

/* Compact/mobile layout: COGNOME N., tighter timings, car kept on second line. */
@media (max-width: 680px) {
    .classification-table th,
    .classification-table td {
        padding: 8px 6px;
    }

    .driver-name-full {
        display: none;
    }

    .driver-name-short {
        display: block;
    }

    .classification-table .col-pos {
        width: 38px;
    }

    .classification-table .col-time,
    .classification-table .col-gap {
        width: 72px;
        font-size: .86rem;
    }

    .classification-table .col-gap th,
    .classification-table .col-time th {
        font-size: .76rem;
    }

    .classification-vehicle {
        max-width: 180px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .classification-penalty,
    .classification-gap-previous {
        font-size: .68rem;
    }
}

/* Very narrow: keep only essential driver text and times. */
@media (max-width: 480px) {
    .classification-vehicle {
        display: none;
    }

    .classification-table .col-pos {
        width: 32px;
    }

    .classification-table .col-time,
    .classification-table .col-gap {
        width: 64px;
    }
}


/* Manual timing matrix */
.manual-times-section {
    padding: 38px 0 56px;
}

.manual-times-toolbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 12px;
    padding: 12px 14px;
    border: 1px solid var(--rm-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
    backdrop-filter: blur(5px);
}

.manual-times-separator {
    margin: 0 6px;
    color: var(--rm-muted);
}

.manual-times-message {
    margin-bottom: 12px;
    border-radius: 6px;
    padding: 10px 12px;
}

.manual-message-success {
    background: #e4f5e9;
    color: #166534;
}

.manual-message-error {
    background: #fce8e8;
    color: #8b1c1c;
}

.manual-times-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin: 10px 0 12px;
    font-size: .88rem;
    color: var(--rm-muted);
}

.legend-box {
    display: inline-block;
    width: 13px;
    height: 13px;
    margin-right: 5px;
    border: 1px solid var(--rm-border);
    border-radius: 3px;
    vertical-align: -2px;
}

.legend-saved {
    background: #eef8f0;
}

.legend-dirty {
    background: #fff7d6;
}

.legend-conflict {
    background: #fde8e8;
}

.manual-times-wrap {
    overflow: auto;
    max-height: calc(100vh - 230px);
    border: 1px solid var(--rm-border);
    border-radius: 8px;
    background: #fff;
}

.manual-times-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    min-width: max-content;
    table-layout: auto;
}

.manual-times-table th,
.manual-times-table td {
    border-right: 1px solid var(--rm-border);
    border-bottom: 1px solid var(--rm-border);
    vertical-align: top;
}

.manual-times-table thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    min-width: 108px;
    width: auto;
    padding: 7px 8px;
    background: #f5f6f8;
    text-align: center;
}

.manual-times-table thead th small {
    display: block;
    margin-top: 2px;
    color: var(--rm-muted);
    font-weight: 400;
    white-space: nowrap;
}

.manual-times-table .manual-driver-header,
.manual-times-table .manual-driver-cell {
    position: sticky;
    left: 0;
    z-index: 8;
    min-width: 200px;
    max-width: 200px;
    background: #fff;
    text-align: left;
}

.manual-times-table .manual-driver-header {
    z-index: 12;
    background: #f5f6f8;
}

.manual-driver-cell {
    padding: 10px 12px;
}

.manual-driver-cell small {
    display: block;
    margin-top: 3px;
    color: var(--rm-muted);
}

.manual-time-cell {
    min-width: 108px;
    width: auto;
    padding: 6px;
    background: #fff;
    transition: background .15s ease, box-shadow .15s ease;
}

.manual-time-cell.has-server-value {
    background: #f6fbf7;
}

.manual-time-cell.is-dirty {
    background: #fff8da;
    box-shadow: inset 0 0 0 2px #e9bd27;
}

.manual-time-cell.has-conflict {
    background: #fdeaea;
    box-shadow: inset 0 0 0 2px #c83c3c;
}

.manual-time-cell.just-synced {
    animation: manual-sync-flash 1.2s ease;
}

.manual-time-cell.just-saved {
    animation: manual-save-flash 1.2s ease;
}

.manual-time-cell label {
    display: grid;
    grid-template-columns: 30px 1fr;
    gap: 6px;
    align-items: center;
    margin-bottom: 5px;
    font-size: .78rem;
}

.manual-time-cell label > span {
    color: var(--rm-muted);
}

.manual-time-input {
    width: 100%;
    min-width: 50px;
    border: 1px solid #cdd3da;
    border-radius: 5px;
    padding: 6px 7px;
    font: inherit;
    font-variant-numeric: tabular-nums;
}

.manual-time-input:focus {
    outline: 2px solid rgba(181, 31, 46, .15);
    border-color: var(--rm-primary);
}

.manual-ti-row {
    display: flex !important;
    grid-template-columns: none !important;
    justify-content: flex-end;
    gap: 5px !important;
    margin: 3px 0 0 !important;
}

.manual-server-value {
    margin-top: 6px;
    padding: 5px 6px;
    border-radius: 4px;
    background: #fff;
    color: #8b1c1c;
    font-size: .7rem;
    line-height: 1.25;
}

.manual-times-help {
    margin-top: 10px;
    font-size: .88rem;
}

@keyframes manual-sync-flash {
    0%, 100% { background: #f6fbf7; }
    50% { background: #dff3e4; }
}

@keyframes manual-save-flash {
    0%, 100% { background: #f6fbf7; }
    50% { background: #ccebd4; }
}

@media (max-width: 760px) {
    .manual-times-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .manual-times-table .manual-driver-header,
    .manual-times-table .manual-driver-cell {
        min-width: 190px;
        max-width: 190px;
    }

    .manual-times-table thead th,
    .manual-time-cell {
        min-width: 145px;
    }
}


.manual-cell-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 3px;
}

.manual-delete-button {
    border: 0;
    background: transparent;
    color: #9b1c1c;
    cursor: pointer;
    padding: 2px 0;
    font: inherit;
    font-size: .74rem;
    font-weight: 700;
}

.manual-delete-button:disabled {
    color: #aab0b7;
    cursor: default;
}

.manual-time-cell.is-delete {
    background: #fdeaea;
    box-shadow: inset 0 0 0 2px #c83c3c;
}

.manual-time-cell.is-delete .manual-time-input,
.manual-time-cell.is-delete .manual-ti-row {
    opacity: .45;
}

.manual-delete-state {
    margin-top: 5px;
    color: #8b1c1c;
    font-size: .7rem;
    font-weight: 700;
}


.manual-time-cell .manual-time-input {
    padding: 5px 6px;
    font-size: .86rem;
}

.manual-time-cell label {
    font-size: .72rem;
}

.manual-times-table thead th small {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 760px) {
    .container {
        width: min(100% - 12px, 1440px);
    }

    .manual-times-table .manual-driver-header,
    .manual-times-table .manual-driver-cell {
        min-width: 170px;
        max-width: 170px;
    }

    .manual-times-table thead th,
    .manual-time-cell {
        min-width: 115px;
    }
}


/* Distinct classification color schemes */
.classification-panel-stage .classification-panel-header {
    background: #dfeee2;
}

.classification-panel-stage .classification-table tbody tr:nth-child(odd) {
    background: #ffffff;
}

.classification-panel-stage .classification-table tbody tr:nth-child(even) {
    background: #f2f8f3;
}

.classification-panel-stage .classification-table tbody tr:hover {
    background: #e8f3ea;
}

.classification-panel-overall .classification-panel-header {
    background: #dbeaf6;
}

.classification-panel-overall .classification-table tbody tr:nth-child(odd) {
    background: #ffffff;
}

.classification-panel-overall .classification-table tbody tr:nth-child(even) {
    background: #f1f7fc;
}

.classification-panel-overall .classification-table tbody tr:hover {
    background: #e7f1f9;
}


/* Extra-compact manual timing inputs */
.manual-time-input {
    width: min(100%, 68px);
    max-width: 68px;
}


/* =========================================================
   Theme system
   ========================================================= */
:root {
    color-scheme: light;
    --rm-bg: #f4f5f7;
    --rm-surface: #ffffff;
    --rm-surface-soft: #f8f9fa;
    --rm-surface-alt: #eef1f4;
    --rm-text: #24272c;
    --rm-muted: #68707b;
    --rm-border: #dfe3e8;
    --rm-primary: #b51f2e;
    --rm-primary-dark: #8f1723;
    --rm-header: #17191d;
    --rm-header-text: #f5f6f7;
    --rm-input: #ffffff;
    --rm-hover: #f0f2f4;
    --rm-shadow: rgba(0, 0, 0, .06);
}

html[data-theme="dark"] {
    color-scheme: dark;
    --rm-bg: #111418;
    --rm-surface: #1a1e23;
    --rm-surface-soft: #20252b;
    --rm-surface-alt: #272d34;
    --rm-text: #edf0f3;
    --rm-muted: #a8b0ba;
    --rm-border: #343b44;
    --rm-primary: #d44755;
    --rm-primary-dark: #bc3441;
    --rm-header: #0b0d10;
    --rm-header-text: #f7f8f9;
    --rm-input: #15191e;
    --rm-hover: #262c33;
    --rm-shadow: rgba(0, 0, 0, .28);
}

html[data-theme="dark"] body {
    background: var(--rm-bg);
    color: var(--rm-text);
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .auth-card,
html[data-theme="dark"] .admin-tile,
html[data-theme="dark"] .table-card,
html[data-theme="dark"] .form-card,
html[data-theme="dark"] .danger-card,
html[data-theme="dark"] .classification-panel,
html[data-theme="dark"] .public-rally-card,
html[data-theme="dark"] .manual-times-wrap,
html[data-theme="dark"] .manual-times-toolbar {
    background: var(--rm-surface);
    border-color: var(--rm-border);
    color: var(--rm-text);
}

html[data-theme="dark"] .data-table th,
html[data-theme="dark"] .classification-table th,
html[data-theme="dark"] .manual-times-table thead th,
html[data-theme="dark"] .manual-times-table .manual-driver-header {
    background: var(--rm-surface-soft);
    color: var(--rm-text);
}

html[data-theme="dark"] .data-table td,
html[data-theme="dark"] .classification-table td,
html[data-theme="dark"] .manual-times-table td,
html[data-theme="dark"] .manual-driver-cell {
    border-color: var(--rm-border);
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .field input,
html[data-theme="dark"] .field select,
html[data-theme="dark"] .membership-row select,
html[data-theme="dark"] .quick-entry-grid input,
html[data-theme="dark"] .quick-entry-grid select,
html[data-theme="dark"] .copy-entry-form select,
html[data-theme="dark"] .manual-time-input,
html[data-theme="dark"] .classification-stage-picker select {
    background: var(--rm-input);
    color: var(--rm-text);
    border-color: var(--rm-border);
}

html[data-theme="dark"] .button-secondary,
html[data-theme="dark"] .order-button,
html[data-theme="dark"] .calendar-nav {
    background: var(--rm-surface-alt);
    color: var(--rm-text);
    border-color: var(--rm-border);
}

html[data-theme="dark"] .button-secondary:hover,
html[data-theme="dark"] .order-button:hover,
html[data-theme="dark"] .calendar-nav:hover {
    background: var(--rm-hover);
}

.theme-toggle {
    width: 38px;
    height: 38px;
    display: inline-grid;
    place-items: center;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 999px;
    background: rgba(255,255,255,.07);
    color: var(--rm-header-text);
    cursor: pointer;
    font-size: 1rem;
}

.theme-toggle:hover {
    background: rgba(255,255,255,.13);
}

.theme-toggle-dark {
    display: none;
}

html[data-theme="dark"] .theme-toggle-light {
    display: none;
}

html[data-theme="dark"] .theme-toggle-dark {
    display: inline;
}

/* =========================================================
   Public home dashboard
   ========================================================= */
.home-dashboard {
    padding: 28px 0 56px;
}

.home-dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 20px;
}

.home-championships-panel { display:flex; flex-direction:column; }
.home-championships-panel .home-results-table-wrap { flex:1; }
.home-calendar-wide { grid-column:1 / -1; }
.home-calendar-layout { display:grid; grid-template-columns:minmax(320px, 0.9fr) minmax(0, 1.6fr); align-items:stretch; }
.home-calendar-month { min-width:0; padding-bottom:10px; }
.home-calendar-agenda { min-width:0; border-left:1px solid var(--rm-border); }
.home-calendar-agenda h3 { margin:0; padding:18px 18px 12px; font-size:1rem; }
.home-calendar-agenda .calendar-events { margin:0; border-top:1px solid var(--rm-border); padding:0 16px 16px; }
.calendar-agenda-row { display:grid; grid-template-columns:98px minmax(0,1fr) auto; align-items:center; gap:12px; padding:13px 3px; border-bottom:1px solid var(--rm-border); }
.calendar-agenda-row:last-child { border-bottom:0; }
.calendar-agenda-details { min-width:0; }
.calendar-agenda-details a { text-decoration:none; color:var(--rm-text); }
.calendar-agenda-details a:hover { color:var(--rm-primary); }
.calendar-agenda-details small { display:block; margin-top:4px; color:var(--rm-muted); }
.calendar-agenda-actions { white-space:nowrap; }
@media(max-width:900px) {
    .home-calendar-layout { grid-template-columns:minmax(0,1fr); }
    .home-calendar-agenda { border-left:0; border-top:1px solid var(--rm-border); }
}
@media(max-width:520px) {
    .calendar-agenda-row { grid-template-columns:78px minmax(0,1fr); }
    .calendar-agenda-actions { grid-column:2; }
}


.home-panel {
    min-width: 0;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 12px;
    box-shadow: 0 3px 12px var(--rm-shadow);
    overflow: hidden;
}

.home-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--rm-border);
}

.home-panel-header h1,
.home-panel-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.home-panel-header p {
    margin: 4px 0 0;
}

.home-panel-link {
    color: var(--rm-primary);
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.home-panel-link:hover {
    text-decoration: underline;
}

.home-results-filters {
    display: grid;
    grid-template-columns: 100px minmax(150px, 190px) minmax(180px, 1fr);
    gap: 10px;
    padding: 14px 16px;
    background: var(--rm-surface-soft);
    border-bottom: 1px solid var(--rm-border);
}

.home-results-filters label {
    display: grid;
    gap: 4px;
    font-size: .76rem;
    color: var(--rm-muted);
    font-weight: 700;
}

.home-results-filters select,
.home-results-filters input {
    width: 100%;
    min-width: 0;
    height: 36px;
    padding: 6px 8px;
    border: 1px solid var(--rm-border);
    border-radius: 6px;
    background: var(--rm-input);
    color: var(--rm-text);
    font: inherit;
    font-weight: 400;
}

.home-results-table-wrap {
    overflow-x: auto;
}

.home-results-table {
    width: 100%;
    border-collapse: collapse;
}

.home-results-table th,
.home-results-table td {
    padding: 11px 13px;
    border-bottom: 1px solid var(--rm-border);
    text-align: left;
    vertical-align: middle;
}

.home-results-table th {
    background: var(--rm-surface-soft);
    color: var(--rm-muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.home-results-table tbody tr:hover {
    background: var(--rm-hover);
}

.home-result-date {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.home-result-location {
    margin-top: 2px;
    font-size: .78rem;
}

.home-result-action {
    width: 1%;
    text-align: right !important;
    white-space: nowrap;
}

.home-results-empty {
    padding: 28px 20px;
    text-align: center;
    color: var(--rm-muted);
}

.home-calendar-panel {
    display: flex;
    flex-direction: column;
}

.calendar-toolbar {
    display: grid;
    grid-template-columns: 36px 1fr 36px;
    align-items: center;
    gap: 8px;
    padding: 14px 16px 8px;
}

.calendar-toolbar strong {
    text-align: center;
    text-transform: capitalize;
}

.calendar-nav {
    width: 34px;
    height: 34px;
    border: 1px solid var(--rm-border);
    border-radius: 7px;
    background: var(--rm-surface-alt);
    color: var(--rm-text);
    cursor: pointer;
    font-size: 1.25rem;
}

.calendar-weekdays,
.home-calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    padding-left: 16px;
    padding-right: 16px;
}

.calendar-weekdays {
    padding-top: 4px;
    padding-bottom: 4px;
    color: var(--rm-muted);
    font-size: .7rem;
    text-align: center;
    font-weight: 700;
    text-transform: uppercase;
}

.home-calendar {
    padding-bottom: 14px;
}

.calendar-day {
    position: relative;
    min-height: 42px;
    display: grid;
    place-items: center;
    border-radius: 7px;
    color: var(--rm-text);
    text-decoration: none;
    font-size: .88rem;
}

.calendar-day.has-event {
    background: rgba(181, 31, 46, .09);
    color: var(--rm-primary);
    font-weight: 700;
}

.calendar-day.has-event:hover {
    background: rgba(181, 31, 46, .16);
}

.calendar-day.is-today {
    box-shadow: inset 0 0 0 1px var(--rm-primary);
}

.calendar-day-empty {
    min-height: 42px;
}

.calendar-event-dot {
    position: absolute;
    bottom: 5px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--rm-primary);
}

.calendar-events {
    margin-top: auto;
    border-top: 1px solid var(--rm-border);
    padding: 10px 16px 14px;
}

.calendar-events > p {
    margin: 8px 0;
    font-size: .84rem;
}

.calendar-event-row {
    display: grid;
    grid-template-columns: 52px 1fr;
    gap: 10px;
    padding: 8px 4px;
    border-bottom: 1px solid var(--rm-border);
    color: var(--rm-text);
    text-decoration: none;
}

.calendar-event-row:last-child {
    border-bottom: 0;
}

.calendar-event-row:hover strong {
    color: var(--rm-primary);
}

.calendar-event-row small {
    display: block;
    margin-top: 2px;
    color: var(--rm-muted);
}

.calendar-event-date {
    color: var(--rm-primary);
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.home-counters {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-top: 20px;
}

.home-counter {
    display: grid;
    gap: 2px;
    padding: 18px 20px;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.home-counter-value {
    font-size: clamp(1.55rem, 3vw, 2.15rem);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.home-counter-label {
    margin-top: 5px;
    color: var(--rm-muted);
    font-size: .88rem;
}

.home-stats-preview {
    margin-top: 20px;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 12px;
    box-shadow: 0 3px 12px var(--rm-shadow);
    overflow: hidden;
}

.home-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
}

.home-stat-card {
    border-right: 1px solid var(--rm-border);
}

.home-stat-card:last-child {
    border-right: 0;
}

.home-stat-card a {
    min-height: 140px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 7px;
    padding: 20px;
    color: var(--rm-text);
    text-decoration: none;
}

.home-stat-card a:hover {
    background: var(--rm-hover);
}

.home-stat-title {
    color: var(--rm-primary);
    font-weight: 700;
}

.home-stat-card strong {
    font-size: 1.7rem;
}

@media (max-width: 980px) {
    .home-dashboard-grid {
        grid-template-columns: 1fr;
    }

    .home-counters {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 680px) {
    .home-results-filters {
        grid-template-columns: 1fr;
    }

    .home-results-table th:nth-child(3),
    .home-results-table td:nth-child(3) {
        display: none;
    }

    .home-counters,
    .home-stats-grid {
        grid-template-columns: 1fr;
    }

    .home-stat-card {
        border-right: 0;
        border-bottom: 1px solid var(--rm-border);
    }

    .home-stat-card:last-child {
        border-bottom: 0;
    }
}

/* Dark theme fixes for specific existing components */
html[data-theme="dark"] .classification-panel-stage .classification-panel-header {
    background: #203127;
}

html[data-theme="dark"] .classification-panel-stage .classification-table tbody tr:nth-child(odd) {
    background: var(--rm-surface);
}

html[data-theme="dark"] .classification-panel-stage .classification-table tbody tr:nth-child(even) {
    background: #18261e;
}

html[data-theme="dark"] .classification-panel-overall .classification-panel-header {
    background: #1e2d3a;
}

html[data-theme="dark"] .classification-panel-overall .classification-table tbody tr:nth-child(odd) {
    background: var(--rm-surface);
}

html[data-theme="dark"] .classification-panel-overall .classification-table tbody tr:nth-child(even) {
    background: #17232d;
}

html[data-theme="dark"] .manual-time-cell {
    background: var(--rm-surface);
}

html[data-theme="dark"] .manual-time-cell.has-server-value {
    background: #18261e;
}

html[data-theme="dark"] .manual-time-cell.is-dirty {
    background: #332d16;
}

html[data-theme="dark"] .manual-time-cell.has-conflict,
html[data-theme="dark"] .manual-time-cell.is-delete {
    background: #351c1e;
}


/* Public classifications list */
.public-classifications-list .nowrap {
    white-space: nowrap;
}

.public-classifications-list .compact-secondary {
    margin-top: 2px;
    font-size: .78rem;
}

.public-classification-actions {
    min-width: 260px;
}

.button-live {
    background: #238636;
    color: #fff;
}

.button-live:hover {
    background: #1f7731;
}

html[data-theme="dark"] .button-live {
    background: #2f9e44;
    color: #fff;
}

html[data-theme="dark"] .button-live:hover {
    background: #27853a;
}

/* Final classification */
.final-classification-panel {
    max-width: 1360px;
    margin: 0 auto;
}

.final-classification-panel .final-col-vehicle {
    min-width: 220px;
}

.final-vehicle {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.final-vehicle-logo {
    flex: 0 0 auto;
    max-width: 46px;
    max-height: 26px;
}

.final-vehicle span {
    min-width: 0;
}

.final-vehicle-identity {
    flex: 0 0 auto;
    min-width: 58px;
    text-align: center;
}

.final-vehicle-identity .classification-tires {
    margin-top: 2px;
    text-align: center;
}

@media (max-width: 760px) {
    .final-classification-panel .final-col-vehicle {
        min-width: 170px;
    }

    .final-vehicle {
        gap: 6px;
        font-size: .78rem;
    }

    .final-vehicle-logo {
        max-width: 34px;
        max-height: 20px;
    }
}

/* Chronological */
.chronological-card {
    overflow: hidden;
}

.chronological-wrap {
    overflow-x: auto;
}

.chronological-table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
}

.chronological-table th,
.chronological-table td {
    padding: 9px 10px;
    border-right: 1px solid var(--rm-border);
    border-bottom: 1px solid var(--rm-border);
    vertical-align: middle;
}

.chronological-table th {
    background: var(--rm-surface-soft);
    font-size: .8rem;
    text-align: center;
    white-space: nowrap;
}

.chronological-table th small {
    display: block;
    margin-top: 2px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--rm-muted);
    font-weight: 400;
}

.chronological-table tbody tr:nth-child(odd) {
    background: var(--rm-surface);
}

.chronological-table tbody tr:nth-child(even) {
    background: #f1f7fc;
}

html[data-theme="dark"] .chronological-table tbody tr:nth-child(even) {
    background: #17232d;
}

.chronological-table tbody tr:hover {
    background: var(--rm-hover);
}

.crono-pos,
.crono-num,
.crono-stage-cell {
    text-align: center;
}

.crono-pos {
    width: 42px;
}

.crono-num {
    width: 50px;
}

.crono-driver {
    min-width: 200px;
    white-space: nowrap;
}

.crono-driver small {
    display: block;
    margin-top: 2px;
    color: var(--rm-muted);
}

.crono-stage-cell {
    min-width: 92px;
}

.crono-time {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.crono-time.is-best {
    color: #1d4ed8;
}

.crono-time.is-imposed {
    color: #c26a00;
    text-decoration: underline;
}

.crono-ti {
    margin-left: 3px;
    font-size: .68rem;
}

.crono-penalty {
    margin-top: 2px;
    color: #b42318;
    font-size: .72rem;
    font-weight: 700;
}

.crono-positions {
    margin-top: 3px;
    color: var(--rm-muted);
    font-size: .7rem;
}

.crono-total,
.crono-gap {
    min-width: 92px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.crono-total small,
.crono-gap small {
    display: block;
    margin-top: 2px;
    color: var(--rm-muted);
}

.chronological-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 10px;
    font-size: .82rem;
}

.legend-best {
    color: #1d4ed8;
}

.legend-penalty {
    color: #b42318;
}

.legend-imposed {
    color: #c26a00;
    text-decoration: underline;
}

@media (max-width: 760px) {
    .public-classification-actions {
        min-width: 190px;
    }

    .public-classifications-list th:nth-child(3),
    .public-classifications-list td:nth-child(3) {
        display: none;
    }
}


/* Public statistics */
.statistics-page {
    padding-bottom: 56px;
}

.statistics-filter-card {
    margin-bottom: 18px;
    padding: 16px;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.statistics-filter-grid {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.4fr) 120px;
    gap: 12px;
}

.statistics-filter-grid label {
    display: grid;
    gap: 5px;
    color: var(--rm-muted);
    font-size: .78rem;
    font-weight: 700;
}

.statistics-filter-grid select,
.statistics-filter-grid input {
    width: 100%;
    height: 38px;
    padding: 7px 9px;
    border: 1px solid var(--rm-border);
    border-radius: 6px;
    background: var(--rm-input);
    color: var(--rm-text);
    font: inherit;
    font-weight: 400;
}

.statistics-counters {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 18px;
}

.statistics-counter {
    display: grid;
    gap: 4px;
    padding: 18px 20px;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.statistics-counter strong {
    font-size: clamp(1.6rem, 3vw, 2.15rem);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.statistics-counter span {
    color: var(--rm-muted);
    font-size: .86rem;
}

.statistics-status {
    margin: -4px 0 14px;
    font-size: .82rem;
}

.statistics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.statistics-card {
    min-width: 0;
    overflow: hidden;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.statistics-card-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border: 0;
    border-bottom: 1px solid var(--rm-border);
    background: var(--rm-surface-soft);
    color: var(--rm-text);
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    text-align: left;
}

.statistics-card-header:hover {
    background: var(--rm-hover);
}

.statistics-card-arrow {
    transition: transform .18s ease;
}

.statistics-card-header[aria-expanded="false"] .statistics-card-arrow {
    transform: rotate(180deg);
}

.statistics-card-content[hidden] {
    display: none;
}

.statistics-table {
    width: 100%;
    border-collapse: collapse;
}

.statistics-table th,
.statistics-table td {
    padding: 9px 11px;
    border-bottom: 1px solid var(--rm-border);
    text-align: left;
    vertical-align: middle;
}

.statistics-table th {
    background: var(--rm-surface-soft);
    color: var(--rm-muted);
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .02em;
}

.statistics-table tbody tr:hover {
    background: var(--rm-hover);
}

.statistics-position {
    width: 48px;
    text-align: center !important;
    font-weight: 800;
}

.statistics-value {
    width: 90px;
    text-align: right !important;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
    .statistics-grid {
        grid-template-columns: 1fr;
    }

    .statistics-counters {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 620px) {
    .statistics-filter-grid,
    .statistics-counters {
        grid-template-columns: 1fr;
    }

    .statistics-table th:nth-child(3),
    .statistics-table td:nth-child(3) {
        display: none;
    }
}


/* Public classifications filters */
.classification-list-filters {
    display: grid;
    grid-template-columns: 110px minmax(180px, 240px) minmax(240px, 1fr) auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 10px;
    padding: 14px 16px;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.classification-list-filters label {
    display: grid;
    gap: 5px;
    color: var(--rm-muted);
    font-size: .78rem;
    font-weight: 700;
}

.classification-list-filters select,
.classification-list-filters input {
    width: 100%;
    height: 38px;
    min-width: 0;
    padding: 7px 9px;
    border: 1px solid var(--rm-border);
    border-radius: 6px;
    background: var(--rm-input);
    color: var(--rm-text);
    font: inherit;
    font-weight: 400;
}

.classification-filter-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.classification-list-summary {
    margin: 0 0 8px 2px;
    font-size: .82rem;
}

@media (max-width: 860px) {
    .classification-list-filters {
        grid-template-columns: 1fr 1fr;
    }

    .classification-search-field {
        grid-column: 1 / -1;
    }

    .classification-filter-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 560px) {
    .classification-list-filters {
        grid-template-columns: 1fr;
    }

    .classification-search-field,
    .classification-filter-actions {
        grid-column: auto;
    }
}


/* Responsive stage selector */
.classification-stage-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.classification-stage-button {
    min-width: 58px;
    padding: 8px 11px;
    border: 1px solid var(--rm-border);
    border-radius: 7px;
    background: var(--rm-surface);
    color: var(--rm-text);
    cursor: pointer;
    font: inherit;
    font-weight: 700;
}

.classification-stage-button:hover {
    background: var(--rm-hover);
}

.classification-stage-button.active {
    background: var(--rm-primary);
    border-color: var(--rm-primary);
    color: #fff;
}

.classification-leg-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    margin: -2px 0 14px;
}

.classification-leg-button {
    min-width: 46px;
    padding: 6px 10px;
    border: 1px solid var(--rm-primary);
    border-radius: 999px;
    background: var(--rm-surface);
    color: var(--rm-primary);
    cursor: pointer;
    font: inherit;
    font-size: .82rem;
    font-weight: 800;
}

.classification-leg-button:hover {
    background: var(--rm-hover);
}

.classification-leg-button.active {
    background: var(--rm-primary);
    color: #fff;
}

.classification-stage-nav {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
}

.classification-stage-nav > [hidden] {
    display: none !important;
}

@media (min-width: 901px) {
    .classification-stage-picker {
        display: none;
    }
}

@media (max-width: 900px) {
    .classification-stage-buttons {
        display: none;
    }

    .classification-stage-picker {
        display: grid;
    }

    .classification-leg-buttons {
        margin-top: 8px;
    }
}

@media (max-width: 620px) {
    .classification-stage-nav {
        grid-template-columns: 1fr 1fr;
    }

    .classification-stage-title {
        grid-column: 1 / -1;
        grid-row: 1;
        text-align: center;
    }

    #previous-stage {
        grid-column: 1;
    }

    #next-stage {
        grid-column: 2;
    }
}


/* Refined stage navigation */
.classification-stage-buttons {
    justify-content: center;
    gap: 6px;
}

.classification-stage-button {
    min-width: 52px;
    padding: 6px 9px;
    font-size: .84rem;
}

.classification-stage-nav {
    grid-template-columns: auto minmax(0, 1fr) auto;
    justify-items: center;
}

.classification-stage-nav .button {
    width: auto;
    min-width: 0;
    justify-self: start;
    padding-left: 12px;
    padding-right: 12px;
}

.classification-stage-nav #next-stage {
    justify-self: end;
}

.classification-stage-title {
    width: 100%;
    text-align: center;
}


/* Keep stage title centered even when previous/next buttons are hidden */
.classification-stage-nav #previous-stage {
    grid-column: 1;
    justify-self: start;
}

.classification-stage-nav .classification-stage-title {
    grid-column: 2;
    justify-self: stretch;
    text-align: center;
}

.classification-stage-nav #next-stage {
    grid-column: 3;
    justify-self: end;
}

@media (max-width: 620px) {
    .classification-stage-nav .classification-stage-title {
        grid-column: 1 / -1;
    }
}


/* Stable two-row stage navigation */
.classification-stage-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
        "title title"
        "prev next";
    gap: 10px 12px;
    align-items: center;
}

.classification-stage-nav .classification-stage-title {
    grid-area: title;
    width: 100%;
    text-align: center;
    justify-self: stretch;
}

.classification-stage-nav #previous-stage {
    grid-area: prev;
    justify-self: start;
    width: auto;
}

.classification-stage-nav #next-stage {
    grid-area: next;
    justify-self: end;
    width: auto;
}

.classification-stage-nav > [hidden] {
    display: none !important;
}

@media (max-width: 620px) {
    .classification-stage-nav {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "title title"
            "prev next";
    }

    .classification-stage-nav .classification-stage-title {
        grid-column: auto;
        grid-row: auto;
    }

    .classification-stage-nav #previous-stage,
    .classification-stage-nav #next-stage {
        grid-column: auto;
    }
}


/* Service park marker inside public stage navigation */
.classification-service-button {
    min-width: 44px;
    padding: 6px 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed #c78a22;
    border-radius: 7px;
    background: #fff4da;
    color: #8a5700;
    font-size: .82rem;
    font-weight: 800;
    cursor: pointer;
    user-select: none;
    text-decoration: none;
}

html[data-theme="dark"] .classification-service-button {
    border-color: #b77a20;
    background: #332812;
    color: #f0bd61;
}


/* Rally service park configuration */
.service-park-config {
    padding: 16px 18px;
    border: 1px solid var(--rm-border);
    border-radius: 9px;
    background: var(--rm-surface-soft);
}

.service-park-config + .service-park-config {
    margin-top: -2px;
}

.service-park-config-header {
    margin-bottom: 12px;
}

.service-park-toggle {
    margin: 0;
    font-weight: 700;
}

.service-park-config-grid {
    display: grid;
    grid-template-columns: minmax(160px, .7fr) minmax(260px, 1.3fr);
    gap: 16px;
    align-items: end;
}

.service-park-position-note {
    min-height: 42px;
    display: flex;
    align-items: center;
    font-size: .84rem;
}

html[data-theme="dark"] .service-park-config {
    background: var(--rm-surface-soft);
    border-color: var(--rm-border);
}

@media (max-width: 760px) {
    .service-park-config-grid {
        grid-template-columns: 1fr;
    }
}


/* RaceManager table headers */
.data-table thead th,
.home-results-table thead th,
.statistics-table thead th,
.classification-table thead th,
.chronological-table thead th {
    background: #0e135c;
    color: #ffffff;
    border-color: rgba(255, 255, 255, .16);
}

.data-table thead th,
.home-results-table thead th,
.statistics-table thead th {
    color: #ffffff;
}

.classification-table thead th span,
.chronological-table thead th span,
.chronological-table thead th small {
    color: rgba(255, 255, 255, .82);
}

html[data-theme="dark"] .data-table thead th,
html[data-theme="dark"] .home-results-table thead th,
html[data-theme="dark"] .statistics-table thead th,
html[data-theme="dark"] .classification-table thead th,
html[data-theme="dark"] .chronological-table thead th,
html[data-theme="dark"] .manual-times-table thead th {
    background: #0e135c;
    color: #ffffff;
}


/* RaceManager section headers */
.statistics-card-header,
.home-panel-header {
    background: #0e135c;
    color: #ffffff;
    border-bottom-color: rgba(255, 255, 255, .16);
}

.statistics-card-header:hover {
    background: #12186f;
}

.statistics-card-header .statistics-card-arrow,
.home-panel-header .muted,
.home-panel-header p,
.home-panel-header .home-panel-link {
    color: #ffffff;
}

.home-panel-header .muted,
.home-panel-header p {
    opacity: .82;
}

.home-panel-header .home-panel-link {
    opacity: .95;
}

.home-panel-header .home-panel-link:hover {
    opacity: 1;
}

html[data-theme="dark"] .statistics-card-header,
html[data-theme="dark"] .home-panel-header {
    background: #0e135c;
    color: #ffffff;
}


/* =========================================================
   Back-office shell
   ========================================================= */
.management-shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
    padding-top: 18px;
    padding-bottom: 56px;
}

.management-sidebar {
    position: sticky;
    top: 16px;
    overflow: hidden;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.management-sidebar-title {
    display: grid;
    gap: 1px;
    padding: 14px 15px;
    background: #0e135c;
    color: #fff;
}

.management-sidebar-title strong {
    font-size: 1rem;
}

.management-sidebar-title span {
    font-size: .74rem;
    opacity: .78;
}

.management-menu {
    display: grid;
}

.management-menu > a,
.management-menu-group > a {
    display: block;
    padding: 9px 13px;
    border-bottom: 1px solid var(--rm-border);
    color: var(--rm-text);
    text-decoration: none;
    font-size: .88rem;
    font-weight: 700;
}

.management-menu > a:hover,
.management-menu-group > a:hover {
    background: var(--rm-hover);
}

.management-menu > a.active,
.management-menu-group > a.active {
    position: relative;
    background: rgba(14, 19, 92, .10);
    color: #0e135c;
}

.management-menu > a.active::before,
.management-menu-group > a.active::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--rm-primary);
}

html[data-theme="dark"] .management-menu > a.active,
html[data-theme="dark"] .management-menu-group > a.active {
    background: rgba(255,255,255,.07);
    color: #fff;
}

.management-menu-group {
    display: grid;
}

.management-menu-heading {
    padding: 11px 13px 6px;
    background: var(--rm-surface-soft);
    color: var(--rm-muted);
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.management-current-club {
    padding: 9px 13px;
    background: #f0f2fb;
    border-bottom: 1px solid var(--rm-border);
    color: #0e135c;
    font-size: .82rem;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

html[data-theme="dark"] .management-current-club {
    background: #20243a;
    color: #dfe4ff;
}

.management-workspace {
    min-width: 0;
}

.management-workspace > .container,
.management-workspace > section.container {
    width: 100%;
    max-width: none;
    margin: 0;
}

.management-workspace .admin-section,
.management-workspace .dashboard {
    padding-top: 0;
}

.management-menu-toggle {
    display: none;
}

.management-dashboard-panel {
    overflow: hidden;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.management-dashboard-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 13px 16px;
    background: #0e135c;
    color: #fff;
}

.management-dashboard-panel-header h2 {
    margin: 0;
    font-size: 1.05rem;
}

.management-dashboard-panel-header p {
    margin: 2px 0 0;
    color: rgba(255,255,255,.78);
    font-size: .82rem;
}

.management-rallies-table th,
.management-rallies-table td {
    padding-top: 10px;
    padding-bottom: 10px;
}

.management-quick-actions {
    min-width: 390px;
}

.management-club-shortcuts {
    margin-top: 18px;
}

.management-club-shortcuts h2 {
    margin: 0 0 9px;
    font-size: 1rem;
}

.management-club-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.management-club-list a {
    min-width: 180px;
    display: grid;
    gap: 1px;
    padding: 9px 12px;
    border: 1px solid var(--rm-border);
    border-radius: 7px;
    background: var(--rm-surface);
    color: var(--rm-text);
    text-decoration: none;
}

.management-club-list a:hover {
    border-color: #aeb5bf;
    background: var(--rm-hover);
}

.management-club-list span {
    color: var(--rm-muted);
    font-size: .76rem;
}

@media (max-width: 1050px) {
    .management-shell {
        grid-template-columns: 190px minmax(0, 1fr);
        gap: 12px;
    }

    .management-quick-actions {
        min-width: 330px;
    }
}

@media (max-width: 760px) {
    .management-shell {
        display: block;
        padding-top: 10px;
    }

    .management-menu-toggle {
        display: inline-flex;
        margin-bottom: 10px;
        padding: 8px 12px;
        border: 1px solid var(--rm-border);
        border-radius: 6px;
        background: var(--rm-surface);
        color: var(--rm-text);
        font: inherit;
        font-weight: 700;
        cursor: pointer;
    }

    .management-sidebar {
        display: none;
        position: static;
        margin-bottom: 12px;
    }

    .management-sidebar.is-open {
        display: block;
    }

    .management-quick-actions {
        min-width: 280px;
    }
}


/* =========================================================
   Classic RaceManager-style application header
   ========================================================= */
.app-header {
    background: #101229;
    border-bottom: 3px solid #e6b400;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

.app-header-inner {
    min-height: 104px;
    display: grid;
    grid-template-columns: auto minmax(260px, 1fr) auto;
    align-items: center;
    gap: 22px;
}

.app-header-brand {
    min-width: 0;
}

.app-header-logo {
    max-height: 84px;
    max-width: 300px;
}

.app-header-title {
    min-width: 0;
    color: #fff;
    line-height: 1.1;
}

.app-header-name {
    font-size: clamp(1.2rem, 2.2vw, 1.75rem);
    font-weight: 800;
    font-style: italic;
    letter-spacing: .02em;
    white-space: nowrap;
}

.app-header-name span {
    color: #e33b49;
}

.app-header-subtitle {
    margin-top: 6px;
    color: #f1d95b;
    font-size: .98rem;
    font-style: italic;
    font-weight: 700;
}

.app-header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    color: #fff;
}

.app-header-user {
    min-width: 220px;
    text-align: right;
    font-size: .82rem;
    line-height: 1.35;
}

.app-header-clock {
    margin-top: 2px;
    color: #f1d95b;
    font-family: Consolas, "Courier New", monospace;
    font-size: .8rem;
    font-weight: 700;
}

.app-header-nav-wrap {
    background: #0b0d1f;
    border-top: 1px solid rgba(255,255,255,.08);
}

.app-header-nav {
    min-height: 42px;
    justify-content: flex-end;
}

.app-header-nav a,
.app-header-nav .nav-button {
    padding-top: 8px;
    padding-bottom: 8px;
}

.management-club-context {
    padding: 10px 12px 12px;
    border-bottom: 1px solid var(--rm-border);
    background: var(--rm-surface-soft);
}

.management-club-context label,
.management-club-label {
    display: block;
    margin-bottom: 5px;
    color: var(--rm-muted);
    font-size: .7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.management-club-context select {
    width: 100%;
    padding: 7px 8px;
    border: 1px solid var(--rm-border);
    border-radius: 6px;
    background: var(--rm-input);
    color: var(--rm-text);
    font: inherit;
    font-size: .84rem;
}

.management-club-context strong {
    display: block;
    color: var(--rm-text);
    font-size: .88rem;
}

.management-dashboard-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}

@media (max-width: 900px) {
    .app-header-inner {
        grid-template-columns: auto 1fr;
        grid-template-areas:
            "logo title"
            "user user";
        gap: 10px 16px;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .app-header-brand {
        grid-area: logo;
    }

    .app-header-title {
        grid-area: title;
    }

    .app-header-right {
        grid-area: user;
        justify-content: space-between;
    }

    .app-header-user {
        min-width: 0;
        text-align: left;
    }
}

@media (max-width: 620px) {
    .app-header-inner {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .app-header-logo {
        max-height: 70px;
        max-width: 230px;
    }

    .app-header-name {
        white-space: normal;
    }

    .app-header-right {
        align-items: flex-end;
    }

    .app-header-nav {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .management-dashboard-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }
}


/* Historic RaceManager title font */
@font-face {
    font-family: 'ArtBrush';
    src: url('/fonts/Artbrush.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

.app-header-name,
.app-header-subtitle {
    font-family: 'ArtBrush', cursive;
    font-weight: normal;
}


/* Stronger visual separation for management menu section headings */
.management-menu-heading {
    background: #d9dce6;
    color: #3f4654;
    border-top: 1px solid var(--rm-border);
    border-bottom: 1px solid var(--rm-border);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .05em;
}

html[data-theme="dark"] .management-menu-heading {
    background: #2a2f3f;
    color: #d8dcea;
}


/* Driver association workflow */
.driver-link-direct-card {
    margin-bottom: 16px;
}

.driver-link-direct-form,
.compact-filter-bar {
    display: flex;
    align-items: end;
    gap: 12px;
    flex-wrap: wrap;
}

.driver-link-direct-form .field,
.compact-filter-bar .field {
    min-width: 220px;
    flex: 1 1 240px;
}

.compact-filter-bar {
    padding: 12px 14px;
    border-bottom: 1px solid var(--rm-border);
    background: var(--rm-surface-soft);
}

.driver-link-active-panel {
    margin-top: 18px;
}

@media (max-width: 700px) {
    .driver-link-direct-form,
    .compact-filter-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .driver-link-direct-form .field,
    .compact-filter-bar .field {
        width: 100%;
        min-width: 0;
    }
}


/* Self-service rally registration */
.self-entry-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--rm-border);
}

.self-entry-summary > div {
    display: grid;
    gap: 2px;
}

.self-entry-note {
    margin-top: 14px;
}

.self-entry-note p {
    margin-top: 2px;
    margin-bottom: 10px;
}

@media (max-width: 700px) {
    .self-entry-summary {
        grid-template-columns: 1fr;
    }
}


/* Wider back-office workspace */
.management-shell.container {
    width: 90%;
    max-width: none;
}

@media (max-width: 760px) {
    .management-shell.container {
        width: min(100% - 12px, 1440px);
    }
}


/* Public entries visual identity */
.public-entry-col-number {
    width: 5%;
}

.public-entry-col-driver {
    width: 22%;
}

.public-entry-col-club {
    width: 28%;
}

.public-entry-col-vehicle {
    width: 35%;
}

.public-entry-col-class {
    width: 10%;
}

.public-entry-driver,
.public-entry-vehicle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.public-entry-driver {
    white-space: nowrap;
}

.public-entry-club,
.public-entry-vehicle-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.25;
}

.public-entry-team,
.public-entry-slot-brand {
    display: block;
    margin-top: 2px;
    color: var(--rm-muted);
    font-size: .82rem;
}

.public-entry-flag {
    flex: 0 0 auto;
}

.public-entry-maker {
    flex: 0 0 auto;
    max-width: 42px;
    max-height: 24px;
}

.public-entry-maker-block {
    flex: 0 0 auto;
    min-width: 52px;
    text-align: center;
}

.public-entry-maker-block .classification-tires {
    margin-top: 2px;
}

@media (max-width: 700px) {
    .public-entry-maker {
        display: none;
    }

    .public-entry-col-driver,
    .public-entry-col-club,
    .public-entry-col-vehicle,
    .public-entry-col-class {
        width: auto;
    }

    .public-entry-driver {
        white-space: normal;
    }
}

/* Compact public home statistics */
.home-stats-compact {
    margin-top: 22px;
    overflow: hidden;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.home-stats-compact .home-panel-header {
    padding-top: 13px;
    padding-bottom: 13px;
}

.home-stats-compact .home-panel-header h2 {
    margin: 0;
    font-size: 1.05rem;
}

.home-stats-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
}

.home-stat-summary-card {
    min-height: 104px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 18px 14px;
    text-align: center;
    border-right: 1px solid var(--rm-border);
}

.home-stat-summary-card:last-child {
    border-right: 0;
}

.home-stat-summary-card .home-stat-title {
    color: var(--rm-primary);
    font-size: .9rem;
    font-weight: 700;
}

.home-stat-summary-card strong {
    color: var(--rm-text);
    font-size: 1.65rem;
    line-height: 1;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 760px) {
    .home-stats-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .home-stat-summary-card:nth-child(2) {
        border-right: 0;
    }

    .home-stat-summary-card:nth-child(-n+2) {
        border-bottom: 1px solid var(--rm-border);
    }
}

@media (max-width: 460px) {
    .home-stats-summary-grid {
        grid-template-columns: 1fr;
    }

    .home-stat-summary-card {
        border-right: 0;
        border-bottom: 1px solid var(--rm-border);
    }

    .home-stat-summary-card:last-child {
        border-bottom: 0;
    }
}

/* Rally and club images */
.image-upload-preview {
    margin-top: 10px;
    padding: 10px;
    border: 1px solid var(--rm-border);
    border-radius: 8px;
    background: var(--rm-surface-soft);
}

.image-upload-preview img {
    display: block;
    max-width: 260px;
    max-height: 130px;
    object-fit: contain;
}

.rally-identity-header {
    display: grid;
    grid-template-columns: minmax(120px, 180px) minmax(0, 1fr) minmax(120px, 180px);
    align-items: center;
    gap: 18px;
    margin-bottom: 18px;
    padding: 16px 18px;
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    background: var(--rm-surface);
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.rally-identity-main {
    min-width: 0;
    text-align: center;
}

.rally-identity-main h1 {
    margin: 4px 0 2px;
}

.rally-identity-main p {
    margin: 3px 0 0;
}

.rally-identity-event {
    margin-top: 2px;
    color: var(--rm-text);
    font-weight: 700;
}

.rally-identity-side {
    min-height: 86px;
    display: flex;
    align-items: center;
}

.rally-identity-rally {
    justify-content: flex-start;
}

.rally-identity-club {
    justify-content: flex-end;
}

.rally-identity-side img {
    display: block;
    max-width: 170px;
    max-height: 86px;
    object-fit: contain;
}

.classification-page-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    margin: -6px 0 18px;
}

@media (max-width: 760px) {
    .rally-identity-header {
        grid-template-columns: 80px minmax(0, 1fr) 80px;
        gap: 10px;
        padding: 12px;
    }

    .rally-identity-side img {
        max-width: 78px;
        max-height: 58px;
    }

    .rally-identity-side {
        min-height: 58px;
    }
}

@media (max-width: 520px) {
    .rally-identity-header {
        grid-template-columns: 1fr 1fr;
    }

    .rally-identity-main {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .rally-identity-rally {
        grid-column: 1;
        grid-row: 2;
    }

    .rally-identity-club {
        grid-column: 2;
        grid-row: 2;
    }
}

/* Searchable quick driver selector (Tom Select) */
.quick-entry-grid .quick-driver .ts-wrapper {
    width: 100%;
}

.quick-entry-grid .quick-driver .ts-control {
    min-height: 37px;
    padding: 8px;
    border: 1px solid #cdd3da;
    border-radius: 6px;
    background: var(--rm-input, #fff);
    color: var(--rm-text);
    font: inherit;
    font-size: .84rem;
    box-shadow: none;
}

.quick-entry-grid .quick-driver .ts-wrapper.focus .ts-control {
    border-color: var(--rm-primary);
    box-shadow: 0 0 0 2px rgba(181, 31, 46, .12);
}

.quick-entry-grid .quick-driver .ts-dropdown {
    z-index: 50;
    border-color: var(--rm-border);
    background: var(--rm-surface);
    color: var(--rm-text);
    font-size: .84rem;
}

.quick-entry-grid .quick-driver .ts-dropdown .option,
.quick-entry-grid .quick-driver .ts-dropdown .optgroup-header {
    padding: 7px 9px;
}

.quick-entry-grid .quick-driver .ts-dropdown .active {
    background: var(--rm-hover);
    color: var(--rm-text);
}

.quick-entry-grid .quick-driver .ts-dropdown .optgroup-header {
    color: var(--rm-muted);
    font-size: .75rem;
    font-weight: 800;
}

html[data-theme="dark"] .quick-entry-grid .quick-driver .ts-control,
html[data-theme="dark"] .quick-entry-grid .quick-driver .ts-dropdown {
    background: var(--rm-input);
    color: var(--rm-text);
}

/* Global driver duplicate management */
.driver-merge-select-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr)) auto;
    gap: 14px;
    align-items: end;
}

.driver-merge-comparison {
    margin-top: 18px;
}

.driver-merge-comparison-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.driver-merge-comparison-grid > div {
    min-width: 0;
}

.driver-merge-card {
    margin: 0;
    border: 1px solid var(--rm-border);
    border-radius: 8px;
    overflow: hidden;
}

.driver-merge-card > div {
    display: grid;
    grid-template-columns: 145px minmax(0, 1fr);
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--rm-border);
}

.driver-merge-card > div:last-child {
    border-bottom: 0;
}

.driver-merge-card dt {
    color: var(--rm-muted);
    font-size: .8rem;
    font-weight: 700;
}

.driver-merge-card dd {
    margin: 0;
}

.driver-merge-owner-field {
    max-width: 520px;
    margin-top: 18px;
}

.driver-merge-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin: 16px 0;
    padding: 12px 14px;
    border: 1px solid var(--rm-border);
    border-radius: 8px;
    background: var(--rm-surface-soft);
}

.driver-merge-summary strong {
    width: 100%;
}

.driver-merge-summary span::before {
    content: '• ';
}

.driver-merge-warning {
    margin-top: 16px;
}

.driver-duplicates-card {
    margin-top: 18px;
}

@media (max-width: 850px) {
    .driver-merge-select-form,
    .driver-merge-comparison-grid {
        grid-template-columns: 1fr;
    }
}

/* Driver statistics modal */
.driver-stats-link {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.driver-stats-link:hover {
    color: var(--rm-primary);
    text-decoration: underline;
}

.driver-stats-modal {
    width: min(980px, calc(100vw - 28px));
    max-height: calc(100vh - 28px);
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: var(--rm-surface);
    color: var(--rm-text);
    box-shadow: 0 18px 60px rgba(0,0,0,.35);
}

.driver-stats-modal::backdrop {
    background: rgba(0,0,0,.62);
}

.driver-stats-modal-shell {
    max-height: calc(100vh - 28px);
    overflow: auto;
}

.driver-stats-modal-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr) 112px;
    align-items: center;
    gap: 18px;
    min-height: 132px;
    padding: 16px 58px 16px 20px;
    background: #0e135c;
    color: #fff;
}

.driver-stats-modal-header h2 {
    margin: 2px 0 2px;
    color: #fff;
}

.driver-stats-modal-title {
    min-width: 0;
    text-align: center;
}

.driver-stats-profile-image-wrap,
.driver-stats-nationality-flag-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

.driver-stats-profile-image {
    width: 96px;
    height: 96px;
    display: block;
    object-fit: cover;
    border: 3px solid rgba(255,255,255,.82);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.28);
}

.driver-stats-profile-image.is-fallback {
    object-fit: contain;
    padding: 8px;
}

.driver-stats-nationality-flag {
    display: block;
    max-width: 104px;
    max-height: 92px;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,.22);
}

.driver-stats-modal-header .muted {
    color: rgba(255,255,255,.78);
}

.driver-stats-modal-kicker {
    color: #f1d95b;
    font-size: .74rem;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.driver-stats-close {
    position: absolute;
    top: 12px;
    right: 12px;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255,255,255,.35);
    border-radius: 50%;
    background: transparent;
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.driver-stats-loading {
    padding: 28px 20px;
    color: var(--rm-muted);
    text-align: center;
}

#driver-stats-content {
    padding: 18px 20px 22px;
}

.driver-stats-summary {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
}

.driver-stats-summary article {
    position: relative;
    display: grid;
    gap: 4px;
    align-content: center;
    min-height: 92px;
    padding: 12px 10px;
    border: 1px solid var(--rm-border);
    border-radius: 9px;
    background: var(--rm-surface-soft);
    text-align: center;
}

.driver-stats-summary article strong {
    color: var(--rm-primary);
    font-size: 1.45rem;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.driver-stats-summary article span {
    color: var(--rm-muted);
    font-size: .76rem;
    font-weight: 700;
}

.driver-stats-help {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 21px;
    height: 21px;
    padding: 0;
    border: 1px solid var(--rm-border);
    border-radius: 50%;
    background: var(--rm-surface);
    color: var(--rm-muted);
    font-size: .72rem;
    font-weight: 800;
    cursor: pointer;
}

.driver-stats-secondary {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 22px;
    margin-top: 12px;
    padding: 10px 12px;
    border: 1px solid var(--rm-border);
    border-radius: 8px;
    background: var(--rm-surface-soft);
    font-size: .84rem;
}

.driver-stats-ace-explanation {
    margin-top: 12px;
    padding: 12px 14px;
    border-left: 4px solid var(--rm-primary);
    border-radius: 6px;
    background: var(--rm-surface-soft);
    font-size: .86rem;
    line-height: 1.45;
}

.driver-stats-palmares {
    margin-top: 20px;
}

.driver-stats-palmares h3 {
    margin: 0 0 10px;
}

.driver-stats-palmares-table .driver-stats-position {
    color: var(--rm-primary);
    font-weight: 800;
    text-align: center;
}

@media (max-width: 900px) {
    .driver-stats-summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .driver-stats-modal {
        width: calc(100vw - 12px);
        max-height: calc(100vh - 12px);
    }

    .driver-stats-modal-header {
        grid-template-columns: 72px minmax(0, 1fr) 72px;
        gap: 8px;
        min-height: 100px;
        padding: 12px 44px 12px 10px;
    }

    .driver-stats-profile-image {
        width: 64px;
        height: 64px;
        border-width: 2px;
    }

    .driver-stats-nationality-flag {
        max-width: 68px;
        max-height: 58px;
    }

    .driver-stats-modal-header h2 {
        font-size: 1rem;
    }

    .driver-stats-modal-kicker,
    .driver-stats-modal-header .muted {
        font-size: .68rem;
    }

    .driver-stats-modal-shell {
        max-height: calc(100vh - 12px);
    }

    .driver-stats-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .driver-stats-modal-header,
    #driver-stats-content {
        padding-left: 12px;
        padding-right: 12px;
    }
}

.crono-driver-name {
    display: flex;
    align-items: center;
    gap: 6px;
}

.crono-nationality-flag {
    flex: 0 0 auto;
    max-width: 22px;
    max-height: 16px;
    margin: 0;
}

/* Chronological position progression chart */
.chronological-position-chart-card {
    margin-top: 18px;
    padding: 16px 18px 18px;
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    background: var(--rm-surface);
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.chronological-position-chart-card .classification-panel-header {
    margin-bottom: 12px;
}

.chronological-position-chart-card .classification-panel-header h2 {
    margin: 0;
}

.chronological-position-chart-card .classification-panel-header p {
    margin: 4px 0 0;
}

.chronological-position-chart-wrap {
    position: relative;
    min-height: 420px;
    height: min(58vh, 620px);
}

@media (max-width: 760px) {
    .chronological-position-chart-card {
        padding: 12px;
    }

    .chronological-position-chart-wrap {
        min-height: 360px;
        height: 52vh;
    }
}

/* Configurable appearance */
.data-table thead th,
.classification-table thead th,
.chronological-table thead th {
    background: var(--rm-table-header-bg);
    color: #fff;
}

.data-table tbody tr:nth-child(even) {
    background: var(--rm-table-row-even);
}

.management-workspace .data-table tbody tr:nth-child(even) {
    background: var(--rm-backoffice-row-even);
}

.classification-panel-stage .classification-table tbody tr:nth-child(odd),
.classification-panel-overall .classification-table tbody tr:nth-child(odd),
.classification-panel-leg .classification-table tbody tr:nth-child(odd),
.chronological-table tbody tr:nth-child(odd) {
    background: var(--rm-surface);
}

.classification-panel-stage:not(.classification-panel-leg) .classification-table tbody tr:nth-child(even) {
    background: var(--rm-stage-row-even);
}

.classification-panel-stage.classification-panel-leg .classification-table tbody tr:nth-child(even) {
    background: var(--rm-leg-row-even);
}

.classification-panel-overall .classification-table tbody tr:nth-child(even) {
    background: var(--rm-overall-row-even);
}

.chronological-table tbody tr:nth-child(even) {
    background: var(--rm-chronological-row-even);
}

.classification-primary-time.is-best,
.crono-time.is-best,
.best {
    color: var(--rm-best-time-color);
}

.classification-penalty,
.crono-penalty,
.penalty {
    color: var(--rm-penalty-color);
}

.classification-ti,
.crono-ti,
.imposed {
    color: var(--rm-imposed-time-color);
}

.appearance-settings-form {
    display: grid;
    gap: 22px;
}

.appearance-settings-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.appearance-settings-grid > section {
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--rm-border);
    border-radius: 9px;
    background: var(--rm-surface-soft);
}

.appearance-settings-grid h2,
.appearance-preview h2 {
    margin: 0 0 14px;
    font-size: 1.05rem;
}

.appearance-color-field {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 132px 28px;
    gap: 10px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--rm-border);
}

.appearance-color-field:last-child {
    border-bottom: 0;
}

.appearance-color-field label {
    display: block;
    font-weight: 700;
}

.appearance-color-field small {
    display: block;
    margin-top: 2px;
    line-height: 1.25;
}

.appearance-color-control {
    display: grid;
    grid-template-columns: 38px 1fr;
    gap: 6px;
    align-items: center;
}

.appearance-color-control input[type="color"] {
    width: 38px;
    height: 34px;
    padding: 2px;
    border: 1px solid var(--rm-border);
    border-radius: 5px;
    background: var(--rm-surface);
    cursor: pointer;
}

.appearance-color-control input[type="text"] {
    width: 100%;
    min-width: 0;
    padding: 7px 6px;
    border: 1px solid var(--rm-border);
    border-radius: 5px;
    background: var(--rm-input);
    color: var(--rm-text);
    font-family: Consolas, "Courier New", monospace;
    font-size: .78rem;
    text-transform: uppercase;
}

.appearance-color-swatch {
    width: 28px;
    height: 28px;
    border: 1px solid var(--rm-border);
    border-radius: 5px;
}

.appearance-preview {
    padding-top: 4px;
}

.appearance-preview-table {
    overflow: hidden;
    max-width: 520px;
    border: 1px solid var(--rm-border);
    border-radius: 7px;
}

.appearance-preview-header,
.appearance-preview-row {
    padding: 9px 12px;
}

.appearance-preview-header {
    background: var(--rm-table-header-bg);
    color: #fff;
    font-weight: 700;
}

.appearance-preview-row {
    background: var(--rm-surface);
}

.appearance-preview-row.is-even {
    background: var(--rm-table-row-even);
}

@media (max-width: 1100px) {
    .appearance-settings-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 620px) {
    .appearance-color-field {
        grid-template-columns: 1fr;
    }

    .appearance-color-control {
        grid-template-columns: 48px minmax(0, 150px);
    }
}

/* Automatic dark-theme counterparts for configurable light-theme colors */
html[data-theme="dark"] {
    --rm-table-header-bg: #242a34;
    --rm-table-row-even: #20252b;
    --rm-stage-row-even: #18261e;
    --rm-overall-row-even: #17232d;
    --rm-leg-row-even: #241f2d;
    --rm-chronological-row-even: #17232d;
    --rm-backoffice-row-even: #20252b;
    --rm-best-time-color: #6cb6ff;
    --rm-penalty-color: #ff7b83;
    --rm-imposed-time-color: #e5b35c;
}

/* Backup generation progress */
.backup-download-button:disabled {
    opacity: .55;
    cursor: wait;
}

.backup-progress-overlay {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(10, 12, 16, .66);
    backdrop-filter: blur(2px);
}

.backup-progress-overlay[hidden] {
    display: none;
}

.backup-progress-card {
    width: min(480px, 100%);
    padding: 26px 28px;
    border: 1px solid var(--rm-border);
    border-radius: 12px;
    background: var(--rm-surface);
    color: var(--rm-text);
    box-shadow: 0 18px 60px rgba(0,0,0,.35);
    text-align: center;
}

.backup-progress-card h2 {
    margin: 12px 0 8px;
}

.backup-progress-card p {
    margin: 0 0 16px;
}

.backup-progress-spinner {
    width: 38px;
    height: 38px;
    margin: 0 auto;
    border: 4px solid var(--rm-border);
    border-top-color: var(--rm-primary);
    border-radius: 50%;
    animation: rm-backup-spin .8s linear infinite;
}

.backup-progress-track {
    position: relative;
    overflow: hidden;
    height: 8px;
    margin: 16px 0 10px;
    border-radius: 999px;
    background: var(--rm-surface-alt);
}

.backup-progress-bar {
    position: absolute;
    inset: 0 auto 0 -35%;
    width: 35%;
    border-radius: inherit;
    background: var(--rm-primary);
    animation: rm-backup-progress 1.2s ease-in-out infinite;
}

@keyframes rm-backup-spin {
    to { transform: rotate(360deg); }
}

@keyframes rm-backup-progress {
    0% { left: -35%; }
    100% { left: 100%; }
}

/* Rally battery planning */
.battery-generator-card {
    display: grid;
    gap: 16px;
}

.battery-generator-form {
    display: grid;
    grid-template-columns: minmax(220px, 320px) auto;
    gap: 14px;
    align-items: end;
}

.battery-generator-action {
    padding-bottom: 1px;
}

.battery-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.battery-summary-grid > div {
    display: grid;
    gap: 4px;
    padding: 12px;
    border: 1px solid var(--rm-border);
    border-radius: 8px;
    background: var(--rm-surface-soft);
    text-align: center;
}

.battery-summary-grid strong {
    color: var(--rm-primary);
    font-size: 1.35rem;
}

.battery-summary-grid span {
    color: var(--rm-muted);
    font-size: .78rem;
}

.battery-warning-card {
    margin-top: 18px;
    border-left: 4px solid var(--rm-imposed-time-color, #9a5b00);
}

.battery-choice-actions {
    gap: 10px;
    flex-wrap: wrap;
}

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

.battery-card {
    overflow: hidden;
    border: 1px solid var(--rm-border);
    border-radius: 10px;
    background: var(--rm-surface);
    box-shadow: 0 2px 8px var(--rm-shadow);
}

.battery-card.is-optimal {
    border-top: 4px solid #4f8a5b;
}

.battery-card.is-warning {
    border-top: 4px solid var(--rm-imposed-time-color, #9a5b00);
}

.battery-card > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--rm-border);
    background: var(--rm-surface-soft);
}

.battery-card h2 {
    margin: 0;
    font-size: 1.05rem;
}

.battery-card header span,
.battery-recovery-count span {
    color: var(--rm-muted);
    font-size: .76rem;
}

.battery-recovery-count {
    display: grid;
    gap: 1px;
    text-align: right;
}

.battery-recovery-count strong {
    color: var(--rm-primary);
    font-size: 1.35rem;
    line-height: 1;
}

.battery-members {
    margin: 0;
    padding: 0;
    list-style: none;
}

.battery-members li {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 9px;
    align-items: center;
    padding: 9px 14px;
    border-bottom: 1px solid var(--rm-border);
}

.battery-members li:nth-child(even) {
    background: var(--rm-backoffice-row-even);
}

.battery-members li:last-child {
    border-bottom: 0;
}

.battery-members small {
    color: var(--rm-muted);
    text-align: right;
}

.battery-race-number {
    font-weight: 800;
    color: var(--rm-primary);
}


.battery-driver-name {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
}

.battery-driver-name-full,
.battery-driver-name-medium,
.battery-driver-name-short {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.battery-driver-name-medium,
.battery-driver-name-short {
    display: none;
}

.battery-driver-number {
    display: block;
    margin-top: 1px;
    color: var(--rm-muted);
    font-size: .72rem;
}

.battery-card > footer {
    padding: 10px 14px;
    border-top: 1px solid var(--rm-border);
    background: var(--rm-surface-soft);
}

.battery-note {
    margin-top: 18px;
}

.battery-note p {
    margin-bottom: 0;
}

@media (max-width: 760px) {
    .battery-generator-form,
    .battery-summary-grid {
        grid-template-columns: 1fr 1fr;
    }

    .battery-generator-action {
        align-self: end;
    }

    .battery-driver-name-full {
        display: none;
    }

    .battery-driver-name-medium {
        display: inline;
    }
}

@media (max-width: 520px) {
    .battery-generator-form,
    .battery-summary-grid {
        grid-template-columns: 1fr;
    }

    .battery-members li {
        grid-template-columns: 42px minmax(0, 1fr);
    }

    .battery-driver-name-medium {
        display: none;
    }

    .battery-driver-name-short {
        display: inline;
    }
}
