/* MOTOTRAIL shared theme */
:root {
    color-scheme: dark;
    --bg: #0f172a;
    --bg-soft: #111c2f;
    --panel: rgba(15, 23, 42, 0.82);
    --panel-2: rgba(30, 41, 59, 0.9);
    --border: rgba(148, 163, 184, 0.22);
    --text: #e2e8f0;
    --muted: rgba(148, 163, 184, 0.85);
    --brand: #2563eb;
    --brand-2: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --sidebar-width: clamp(220px, 22vw, 280px);
    /* Typography scale (per spec) */
    --font: "Segoe UI", Tahoma, sans-serif;
    --fs-title: 14px;   /* headers / titles  -> bold   */
    --fs-text: 14px;    /* general text      -> normal */
    --fs-sub: 13px;     /* sub text / data   -> normal */
    font-family: var(--font);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--fs-text);
    font-weight: 400;
    line-height: 1.5;
}

/* Global typography rules ------------------------------------------------ */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font);
    font-size: var(--fs-title);
    font-weight: 700;
    margin: 0;
}
p, span, a, label, td, th, input, select, textarea, button, li, div {
    font-family: var(--font);
}

a {
    color: inherit;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* -------------------------------------------------------------- Buttons */
.btn {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.7rem 1.15rem;
    border-radius: 11px;
    border: 1px solid transparent;
    font-weight: 400;
    font-size: var(--fs-text);
    letter-spacing: 0.02em;
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn--primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #f8fafc; }
.btn--primary:hover { box-shadow: 0 10px 20px rgba(37, 99, 235, 0.35); }
.btn--danger { background: rgba(220, 38, 38, 0.18); color: #fca5a5; border-color: rgba(248, 113, 113, 0.35); }
.btn--danger:hover { background: rgba(220, 38, 38, 0.32); color: #fee2e2; }
.btn--ghost { background: rgba(15, 23, 42, 0.7); color: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: rgba(37, 99, 235, 0.25); }
.btn--sm { padding: 0.4rem 0.8rem; font-size: var(--fs-sub); border-radius: 9px; }

/* -------------------------------------------------------------- Auth / public cards */
.auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: radial-gradient(circle at top, #1e3a8a, #0b1220);
}
.auth__card {
    width: min(440px, 94vw);
    padding: 2.75rem 2.5rem;
    background: rgba(255, 255, 255, 0.96);
    border-radius: 20px;
    box-shadow: 0 25px 45px rgba(15, 23, 42, 0.45);
    color: #0f172a;
}
.auth__brand { text-align: center; margin-bottom: 2rem; }
.auth__brand h1 { margin: 0; font-size: var(--fs-title); font-weight: 700; letter-spacing: 0.1em; color: #111827; }
.auth__brand p { margin: 0.4rem 0 0; color: #6b7280; font-size: var(--fs-sub); }
.auth__alt { text-align: center; margin: 1.2rem 0 0; font-size: var(--fs-sub); }
.auth__alt a { color: #2563eb; text-decoration: none; font-weight: 400; }
.auth__alt a:hover { text-decoration: underline; }
.auth__viewer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    width: 100%;
    margin-top: 1.25rem;
    padding: 0.85rem 1.2rem;
    border-radius: 12px;
    border: 1px solid rgba(37, 99, 235, 0.35);
    background: rgba(37, 99, 235, 0.08);
    color: #1d4ed8;
    font-size: var(--fs-text);
    font-weight: 400;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.auth__viewer:hover {
    background: rgba(37, 99, 235, 0.16);
    border-color: rgba(37, 99, 235, 0.55);
    color: #1e40af;
    text-decoration: none;
}
.auth__viewer svg { flex-shrink: 0; opacity: 0.9; }

/* -------------------------------------------------------------- Forms */
.form { display: grid; gap: 1.25rem; }
.form__row { display: grid; gap: 1.25rem; }
@media (min-width: 640px) { .form__row--2 { grid-template-columns: 1fr 1fr; } }
.form__group { display: grid; gap: 0.5rem; }
.form label { font-weight: 400; font-size: var(--fs-text); }
.auth__card label { color: #1f2937; }
.form input,
.form select,
.form textarea {
    width: 100%;
    padding: 0.8rem 1rem;
    border-radius: 11px;
    border: 1px solid rgba(148, 163, 184, 0.55);
    background: rgba(15, 23, 42, 0.55);
    color: var(--text);
    font-size: var(--fs-text);
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.auth__card input,
.auth__card select,
.auth__card textarea {
    background: #ffffff;
    color: #0f172a;
}
.form textarea { min-height: 96px; resize: vertical; }
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.6rem;
}
.checkbox {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.6rem 0.85rem;
    border: 1px solid rgba(148, 163, 184, 0.55);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.55);
    cursor: pointer;
    font-weight: 400;
    font-size: var(--fs-text);
}
.checkbox input { width: auto; margin: 0; }
.auth__card .checkbox { background: #fff; color: #0f172a; border-color: rgba(148, 163, 184, 0.7); }
.form input:focus,
.form select:focus,
.form textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
    outline: none;
}

/* -------------------------------------------------------------- Flash / alerts (legacy, mostly replaced by toasts) */
.flash {
    padding: 0.9rem 1.1rem;
    border-radius: 12px;
    font-weight: 400;
    font-size: var(--fs-text);
    border: 1px solid transparent;
}
.flash--error { background: rgba(220, 38, 38, 0.14); color: #fca5a5; border-color: rgba(248, 113, 113, 0.4); }
.flash--success { background: rgba(22, 163, 74, 0.16); color: #86efac; border-color: rgba(74, 222, 128, 0.4); }
.auth__card .flash--error { color: #b91c1c; }

/* -------------------------------------------------------------- Toasts */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    z-index: 1000;
    width: min(360px, 92vw);
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    font-size: var(--fs-text);
    font-weight: 400;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    border: 1px solid transparent;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    cursor: pointer;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast--success { background: #dcfce7; color: #166534; border-color: #86efac; }
.toast--error { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }

/* -------------------------------------------------------------- Admin layout */
.layout { min-height: 100vh; }
/* Full-screen, sidebar-less layout (e.g. the viewer role). */
.bare-layout .content { margin-left: 0 !important; width: 100%; }
/* Suppress transitions during the initial load to avoid the sidebar flashing in. */
.sidebar-preload .sidebar,
.sidebar-preload .sidebar__overlay,
.sidebar-preload .content { transition: none !important; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    height: 100vh;
    transform: translateX(-110%);
    overflow-y: auto;
    background: linear-gradient(180deg, #111c2f, #0b1220);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.8rem 1.4rem;
    border-right: 1px solid var(--border);
    transition: transform 0.3s ease;
    z-index: 20;
}
body.sidebar-open .sidebar { transform: translateX(0); }
.sidebar__close {
    display: none;
    align-self: flex-end;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
}
.sidebar__brand { display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar__logo { max-height: 56px; align-self: flex-start; margin-bottom: 0.4rem; border-radius: 8px; background: #fff; padding: 4px; }
.auth__logo { display: block; max-height: 72px; margin: 0 auto 0.8rem; }
.sidebar__title { font-size: var(--fs-title); font-weight: 700; letter-spacing: 0.08em; }
.sidebar__subtitle { font-size: var(--fs-sub); color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; }
.sidebar__user { display: flex; flex-direction: column; gap: 0.2rem; }
.sidebar__user-name { font-size: var(--fs-text); font-weight: 400; }
.sidebar__user-role { font-size: var(--fs-sub); color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.sidebar__nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.sidebar__nav a {
    display: block;
    padding: 0.75rem 0.9rem;
    border-radius: 10px;
    font-size: var(--fs-text);
    font-weight: 400;
    color: rgba(226, 232, 240, 0.9);
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease;
}
.sidebar__nav li.active a,
.sidebar__nav a:hover { background: rgba(37, 99, 235, 0.3); color: #fff; }
.sidebar__footer { margin-top: auto; }
.sidebar__logout {
    display: inline-block;
    padding: 0.65rem 0.9rem;
    border-radius: 10px;
    background: rgba(220, 38, 38, 0.15);
    color: #fca5a5;
    font-size: var(--fs-text);
    font-weight: 400;
    text-decoration: none;
}
.sidebar__logout:hover { background: rgba(220, 38, 38, 0.3); color: #fee2e2; }
.sidebar__overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
    z-index: 15;
}
body.sidebar-open .sidebar__overlay { opacity: 1; visibility: visible; pointer-events: auto; }
.sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(15, 23, 42, 0.7);
    color: var(--text);
    cursor: pointer;
    font-size: 1.35rem;
}
.sidebar-toggle:focus { outline: 2px solid rgba(96, 165, 250, 0.8); outline-offset: 2px; }

.content {
    margin-left: 0;
    min-height: 100vh;
    padding: 2.2rem;
    display: flex;
    flex-direction: column;
    gap: 1.6rem;
}
.content__header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(8px);
    padding: 1.1rem 0 1rem;
    border-bottom: 1px solid var(--border);
}
.content__header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.2rem;
    flex-wrap: wrap;
}
.content__header-title { display: flex; align-items: center; gap: 1rem; }
.content__header h1 { margin: 0; font-size: var(--fs-title); font-weight: 700; letter-spacing: 0.04em; }

/* -------------------------------------------------------------- Cards / stats */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 1.5rem;
    box-shadow: 0 25px 45px rgba(15, 23, 42, 0.35);
}
.card__title { margin: 0 0 1.1rem; font-size: var(--fs-title); font-weight: 700; }
.grid { display: grid; gap: 1.2rem; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.2), rgba(15, 23, 42, 0.6));
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.4rem 1.5rem;
}
.stat__label { color: var(--muted); font-size: var(--fs-sub); text-transform: uppercase; letter-spacing: 0.08em; }
.stat__value { font-size: var(--fs-title); font-weight: 700; margin-top: 0.3rem; }

/* -------------------------------------------------------------- Pie chart */
.chart { display: flex; gap: 1.6rem; align-items: center; flex-wrap: wrap; }
.chart__pie { flex: 0 0 auto; }
.chart__legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; flex: 1 1 200px; min-width: 180px; }
.legend-item { display: flex; align-items: center; gap: 0.6rem; font-size: var(--fs-sub); }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.legend-item__count { margin-left: auto; color: var(--muted); }

/* -------------------------------------------------------------- Progress bars */
.progress-list { display: grid; gap: 1.1rem; }
.progress-item__head { display: flex; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.4rem; font-size: var(--fs-sub); }
.progress-item__meta { color: var(--muted); }
.progress {
    height: 12px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.18);
    overflow: hidden;
}
.progress__bar {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand), #22c55e);
    transition: width 0.4s ease;
}

/* -------------------------------------------------------------- Tables */
.table-wrapper {
    background: var(--panel);
    border-radius: 18px;
    border: 1px solid var(--border);
    overflow-x: auto;
    box-shadow: 0 25px 45px rgba(15, 23, 42, 0.4);
}
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 640px; }
thead th {
    background: linear-gradient(135deg, rgba(30, 64, 175, 0.6), rgba(29, 78, 216, 0.55));
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: var(--fs-sub);
    font-weight: 700;
    text-align: left;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: 0.8rem 1rem;
    font-size: var(--fs-sub);
    font-weight: 400;
    color: rgba(226, 232, 240, 0.92);
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    background: rgba(15, 23, 42, 0.58);
    vertical-align: middle;
}
tbody tr:nth-child(even) td { background: rgba(15, 23, 42, 0.72); }
tbody tr:hover td { background: rgba(30, 64, 175, 0.22); color: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
.race-date {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.32rem 0.7rem;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.18);
    border: 1px solid rgba(37, 99, 235, 0.4);
    color: #dbeafe;
    font-size: var(--fs-sub);
    font-weight: 400;
    cursor: default;
}
.race-date svg { opacity: 0.85; }
.lock-note {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    margin: 0 0 1rem;
    border-radius: 10px;
    background: rgba(234, 179, 8, 0.12);
    border: 1px solid rgba(234, 179, 8, 0.4);
    color: #fde68a;
    font-size: var(--fs-sub);
}

.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* Icon action buttons */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(148, 163, 184, 0.08);
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: rgba(37, 99, 235, 0.18); border-color: rgba(37, 99, 235, 0.5); color: #fff; }
.icon-btn:focus-visible { outline: 2px solid rgba(96, 165, 250, 0.8); outline-offset: 2px; }
.icon-btn--danger:hover { background: rgba(220, 38, 38, 0.18); border-color: rgba(220, 38, 38, 0.5); color: #fecaca; }

/* Hover tooltip rendered on <body> so it is never clipped by table overflow.
   Auto-hides whenever the trigger is not hovered/focused. */
.mt-tooltip {
    position: fixed;
    z-index: 1000;
    padding: 0.3rem 0.55rem;
    background: #0f172a;
    color: #e2e8f0;
    font-size: var(--fs-sub);
    font-weight: 400;
    line-height: 1;
    white-space: nowrap;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -100%);
    transition: opacity 0.12s ease;
}
.mt-tooltip.is-visible { opacity: 1; }
.mt-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #0f172a;
}
.table-link { color: #93c5fd; font-weight: 400; text-decoration: none; }
.table-link:hover { text-decoration: underline; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: var(--fs-sub);
    font-weight: 400;
    background: rgba(37, 99, 235, 0.2);
    color: #bfdbfe;
}
.badge--ok { background: rgba(22, 163, 74, 0.2); color: #86efac; }
.badge--muted { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }

.empty {
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--muted);
    font-size: var(--fs-sub);
}

/* -------------------------------------------------------------- Toolbar / search */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.search { display: flex; align-items: center; gap: 0.6rem; }
.search input[type="search"] {
    min-width: clamp(180px, 30vw, 320px);
    padding: 0.6rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.7);
    color: var(--text);
    font-size: var(--fs-text);
}

/* -------------------------------------------------------------- Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 0.4rem;
}
.pagination__status { color: var(--muted); font-size: var(--fs-sub); }
.pagination__actions { display: flex; gap: 0.6rem; }

/* -------------------------------------------------------------- Modal */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(2, 6, 23, 0.7);
    backdrop-filter: blur(4px);
    z-index: 50;
}
.modal.is-open { display: flex; }
.modal__box {
    width: min(640px, 96vw);
    max-height: 90vh;
    overflow-y: auto;
    background: #0b1220;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 1.8rem;
    box-shadow: 0 35px 60px rgba(0, 0, 0, 0.5);
}
.modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.2rem; }
.modal__head h2 { margin: 0; font-size: var(--fs-title); font-weight: 700; }
.modal__close { background: transparent; border: none; color: var(--text); font-size: 1.7rem; cursor: pointer; line-height: 1; }
.modal__actions { display: flex; justify-content: flex-end; gap: 0.7rem; margin-top: 0.5rem; }

/* -------------------------------------------------------------- Tabs */
.tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.tabs a {
    padding: 0.55rem 1.1rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.7);
    color: var(--text);
    text-decoration: none;
    font-weight: 400;
    font-size: var(--fs-text);
}
.tabs a.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; }

/* -------------------------------------------------------------- Responsive */
@media (min-width: 961px) {
    body.sidebar-open .content { margin-left: var(--sidebar-width); }
    body.sidebar-open { overflow: auto; }
    .sidebar__overlay { display: none; }
}
@media (max-width: 960px) {
    .sidebar { width: min(82vw, 320px); box-shadow: 0 25px 45px rgba(15, 23, 42, 0.55); }
    .sidebar__close { display: inline-flex; align-items: center; justify-content: center; }
    .content { padding: 1.6rem; }
    body.sidebar-open { overflow: hidden; }
}
@media (max-width: 600px) {
    .content { padding: 1.2rem; }
}
