/* === Base (Praetorsoft Fluent palette) === */
:root {
    --rr-bg: #f3f2f1;
    --rr-surface: #fff;
    --rr-surface-alt: #faf9f8;
    --rr-text: #323130;
    --rr-text-2: #605e5c;
    --rr-muted: #a19f9d;
    --rr-border: #e1dfdd;
    --rr-border-soft: #edebe9;
    --rr-accent: #0078d4;
    --rr-accent-soft: #e7f1ff;
    --rr-danger: #a4262c;
    --rr-max: #107c10;
    --rr-max-soft: #dff6dd;
    --rr-text-value: #8a5a00;
    --rr-text-value-soft: #fff4ce;
    --rr-new: #ca5010;
}

html, body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--rr-bg);
    color: var(--rr-text);
    -webkit-text-size-adjust: 100%;
}

.text-accent {
    color: var(--rr-accent) !important;
}

.min-w-0 {
    min-width: 0;
}

/* Phone-first: one narrow column that also reads well on a desktop. */
.app-narrow {
    max-width: 720px;
    padding-left: 16px;
    padding-right: 16px;
}

.app-navbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    padding-top: calc(6px + env(safe-area-inset-top));
    padding-bottom: 6px;
}

.app-navbar .navbar-brand {
    font-size: 1.05rem;
}

.nav-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--rr-text-2);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s;
}

.nav-pill:hover {
    background: var(--rr-border);
    color: var(--rr-text);
}

.app-main {
    padding-top: 12px;
    padding-bottom: 12px;
}

.app-notice {
    padding: 10px 12px;
    font-size: 0.9rem;
}

.app-footer {
    padding-top: 8px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    font-size: 0.8rem;
    color: var(--rr-muted);
}

.app-footer a {
    color: var(--rr-text-2);
    text-decoration: none;
}

.app-footer-sep {
    margin: 0 6px;
}

.page-title {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 4px 0 2px;
}

.as-of {
    font-size: 0.8rem;
    color: var(--rr-text-2);
    margin-bottom: 12px;
}

.hint {
    font-size: 0.85rem;
    color: var(--rr-text-2);
    background: var(--rr-surface-alt);
    border: 1px dashed var(--rr-border);
    border-radius: 8px;
    padding: 8px 10px;
}

.legend {
    font-size: 0.75rem;
    color: var(--rr-text-2);
    margin: 8px 0 16px;
}

.section-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--rr-text-2);
    margin: 20px 0 8px;
}

.card-surface {
    background: var(--rr-surface);
    border: 1px solid var(--rr-border);
    border-radius: 10px;
    padding: 12px 14px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.875rem;
    color: var(--rr-accent);
    text-decoration: none;
    margin-bottom: 6px;
}

/* === Segmented control === */
.seg-switch {
    display: inline-flex;
    background: var(--rr-bg);
    border: 1px solid var(--rr-border);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}

.seg-switch-full {
    display: flex;
}

.seg-switch-full .seg-btn {
    flex: 1 1 0;
}

.seg-btn {
    padding: 7px 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--rr-text-2);
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.seg-btn.active {
    background: var(--rr-surface);
    color: var(--rr-accent);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* === Search === */
.search-box {
    position: relative;
}

.search-box .bi-search {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--rr-muted);
}

.search-box .form-control {
    padding-left: 36px;
    border-color: var(--rr-border);
    font-size: 16px; /* 16px stops iOS from zooming in on focus */
}

/* === Standings list === */
.standings-list {
    background: var(--rr-surface);
    border: 1px solid var(--rr-border);
    border-radius: 10px;
    overflow: hidden;
}

.standing-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: var(--rr-text);
    text-decoration: none;
    border-bottom: 1px solid var(--rr-border-soft);
}

.standing-row:last-child {
    border-bottom: none;
}

.standing-row:active,
.standing-row:hover {
    background: var(--rr-surface-alt);
    color: var(--rr-text);
}

.standing-row.is-me {
    background: var(--rr-accent-soft);
}

.standing-pos {
    flex: 0 0 32px;
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--rr-text-2);
}

.standing-who {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.standing-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.standing-club {
    font-size: 0.75rem;
    color: var(--rr-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.standing-laps {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-variant-numeric: tabular-nums;
}

.standing-total {
    font-weight: 600;
}

.standing-meta {
    display: flex;
    gap: 6px;
    font-size: 0.72rem;
}

.standing-plus {
    color: var(--rr-max);
    font-weight: 600;
}

.standing-change {
    color: var(--rr-muted);
}

.standing-change.is-up {
    color: var(--rr-max);
    font-weight: 600;
}

/* === "Me" card on the standings === */
.me-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #fff;
    background: var(--rr-accent);
    border-radius: 4px;
    padding: 2px 6px;
    vertical-align: middle;
}

.me-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    margin-bottom: 12px;
    background: var(--rr-surface);
    border: 1px solid var(--rr-accent);
    border-radius: 10px;
    color: var(--rr-text);
    text-decoration: none;
    box-shadow: 0 1px 4px rgba(0, 120, 212, 0.12);
}

.me-card:hover {
    color: var(--rr-text);
}

.me-card-name {
    flex: 1 1 auto;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.me-card-pos,
.me-card-total {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.me-card .bi-chevron-right {
    color: var(--rr-muted);
}

/* === Driver card === */
.driver-card {
    background: var(--rr-surface);
    border: 1px solid var(--rr-border);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 8px;
}

.driver-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.driver-name {
    font-size: 1.35rem;
    font-weight: 600;
    margin: 0;
}

.driver-club {
    font-size: 0.8rem;
    color: var(--rr-muted);
}

.driver-total {
    font-size: 1.1rem;
    font-weight: 700;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.driver-positions {
    margin-top: 6px;
    font-size: 0.9rem;
    color: var(--rr-text-2);
}

.driver-since {
    font-size: 0.85rem;
    color: var(--rr-max);
    font-weight: 600;
}

.driver-actions {
    margin-top: 10px;
}

/* === Summary chips === */
.summary-chips {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.chip {
    flex: 1 1 0;
    text-align: center;
    background: var(--rr-surface);
    border: 1px solid var(--rr-border);
    border-radius: 8px;
    padding: 6px 4px;
    font-size: 0.8rem;
    color: var(--rr-text-2);
}

.chip strong {
    display: block;
    font-size: 1.2rem;
    color: var(--rr-text);
}

.chip-left strong {
    color: var(--rr-accent);
}

.chip-max strong {
    color: var(--rr-max);
}

/* === Box grid: one row per car class, lanes 1-4 plus the clean "0" box === */
.box-grid {
    background: var(--rr-surface);
    border: 1px solid var(--rr-border);
    border-radius: 10px;
    padding: 6px;
}

.box-grid-head,
.box-grid-row {
    display: grid;
    grid-template-columns: minmax(58px, 1.1fr) repeat(5, minmax(0, 1fr));
    gap: 4px;
    align-items: stretch;
}

.box-grid-row {
    margin-top: 4px;
}

.box-grid-head span {
    text-align: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--rr-muted);
}

.box-grid-label {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    padding-left: 4px;
}

.box-grid-code {
    font-weight: 700;
    font-size: 0.85rem;
    line-height: 1.1;
}

.box-grid-class {
    font-size: 0.62rem;
    color: var(--rr-muted);
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.box-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 2px;
    border: 1px solid var(--rr-border);
    border-radius: 6px;
    background: var(--rr-surface-alt);
    color: var(--rr-text);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    transition: opacity 0.15s, transform 0.1s;
}

.box-cell:active {
    transform: scale(0.96);
}

.box-cell-value {
    font-size: 0.85rem;
    font-weight: 600;
}

.box-cell-gap {
    font-size: 0.62rem;
    color: var(--rr-muted);
}

.box-cell-check {
    font-size: 0.7rem;
    line-height: 1;
}

.box-cell.is-void {
    border: none;
    background: transparent;
}

.box-cell.is-empty {
    border: 1.5px dashed var(--rr-accent);
    background: var(--rr-surface);
    color: var(--rr-accent);
}

.box-cell.is-empty .box-cell-value {
    font-size: 0.72rem;
    font-weight: 500;
}

.box-cell.is-max {
    border-color: #9fd89f;
    background: var(--rr-max-soft);
    color: var(--rr-max);
}

.box-cell.is-text {
    border-color: #f2d27a;
    background: var(--rr-text-value-soft);
    color: var(--rr-text-value);
}

.box-cell.is-dim,
.other-row.is-dim {
    opacity: 0.28;
}

.new-dot {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--rr-new);
}

.new-dot-inline {
    position: static;
    display: inline-block;
    vertical-align: middle;
}

/* === Other boxes === */
.other-list {
    background: var(--rr-surface);
    border: 1px solid var(--rr-border);
    border-radius: 10px;
    overflow: hidden;
}

.other-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    border-bottom: 1px solid var(--rr-border-soft);
    background: transparent;
    color: var(--rr-text);
    text-align: left;
    transition: opacity 0.15s;
}

.other-row:last-child {
    border-bottom: none;
}

.other-nr {
    flex: 0 0 24px;
    font-size: 0.75rem;
    color: var(--rr-muted);
    text-align: right;
}

.other-who {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.other-code {
    font-weight: 600;
}

.other-note {
    font-size: 0.72rem;
    color: var(--rr-muted);
}

.other-value {
    flex: 0 0 auto;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.other-max {
    color: var(--rr-muted);
    font-weight: 400;
}

.other-row.is-empty .other-value {
    color: var(--rr-accent);
}

.other-row.is-max .other-value {
    color: var(--rr-max);
}

.other-row.is-text .other-value {
    color: var(--rr-text-value);
}

.other-row.is-none .other-value {
    color: var(--rr-muted);
}

.other-row .new-dot {
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
}

/* === Box details: a bottom sheet on phones, a dialog on wider screens === */
.sheet-kicker {
    font-size: 0.75rem;
    color: var(--rr-muted);
}

.sheet-subtitle {
    font-size: 0.85rem;
    color: var(--rr-text-2);
}

.sheet-stats {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.sheet-stat {
    flex: 1 1 0;
    background: var(--rr-surface-alt);
    border: 1px solid var(--rr-border-soft);
    border-radius: 8px;
    padding: 8px 10px;
}

.sheet-stat.is-max {
    background: var(--rr-max-soft);
}

.sheet-stat.is-text {
    background: var(--rr-text-value-soft);
}

.sheet-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--rr-muted);
    margin-bottom: 2px;
}

.sheet-value {
    font-size: 1.3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.sheet-note {
    font-size: 0.75rem;
    color: var(--rr-text-2);
}

.sheet-kind {
    font-size: 0.85rem;
    color: var(--rr-text-2);
}

.sheet-best {
    margin-bottom: 12px;
}

.sheet-rules {
    margin-bottom: 12px;
}

.sheet-rules p {
    font-size: 0.85rem;
    color: var(--rr-text-2);
    white-space: pre-line;
}

@media (max-width: 575.98px) {
    .modal-dialog.modal-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        max-width: none;
    }

    .modal-sheet .modal-content {
        border: none;
        border-radius: 14px 14px 0 0;
        max-height: 85vh;
        overflow-y: auto;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .modal.fade .modal-dialog.modal-sheet {
        transform: translateY(100%);
        transition: transform 0.25s ease-out;
    }

    .modal.show .modal-dialog.modal-sheet {
        transform: none;
    }
}

/* === Status page === */
.status-line {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.status-dot {
    flex: 0 0 10px;
    width: 10px;
    height: 10px;
    margin-top: 6px;
    border-radius: 50%;
    background: var(--rr-muted);
}

.status-dot.status-changed,
.status-dot.status-unchanged {
    background: var(--rr-max);
}

.status-dot.status-failed {
    background: var(--rr-danger);
}

.snapshot-row {
    padding: 8px 0;
    border-top: 1px solid var(--rr-border-soft);
}
