/* ============================================
   TempoTime Shared Styles
   GitHub Dark-inspired theme for all services
   ============================================ */

/* ============================================
   THEME VARIABLES
   ============================================ */

:root {
    /* A tint is rgba(var(--x-rgb), a): add an -rgb triplet when a color
       needs one. */

    /* Backgrounds */
    --bg-dark-rgb: 13, 17, 23;
    --bg-dark: rgb(var(--bg-dark-rgb));
    --bg-card: #161b22;
    --bg-input: #21262d;

    /* Borders */
    --border: #30363d;

    /* Text */
    --text: #c9d1d9;
    --text-muted-rgb: 139, 148, 158;
    --text-muted: rgb(var(--text-muted-rgb));
    --text-bright: #fff; /* on filled buttons and badges; race clock digits */

    /* Accent colors */
    --accent-rgb: 88, 166, 255;
    --accent: rgb(var(--accent-rgb));
    --accent-hover: #79b8ff;

    /* Semantic colors */
    --success-rgb: 63, 185, 80;
    --success: rgb(var(--success-rgb));
    --warning-rgb: 210, 153, 34;
    --warning: rgb(var(--warning-rgb));
    --danger-rgb: 248, 81, 73;
    --danger: rgb(var(--danger-rgb));

    /* Filled buttons: darker than the semantic colors, so white text
       keeps 4.5:1 (WCAG AA). */
    --accent-fill: #1f6feb;
    --success-fill: #238636;
    --warning-fill: #9e6a03;
    --danger-fill: #da3633;

    /* Shadows and modal backdrops */
    --shadow-rgb: 0, 0, 0;

    /* Race-specific colors */
    --start-color: var(--success);
    --finish-color: var(--danger);

    /* Page-specific: no shared color fits. */
    --gun-time-only: #7c3aed; /* TLS race badge: must not read as a race state */
    --medal-gold-rgb: 255, 193, 7; /* podium places 1-3: RRS and the live site */
    --medal-gold: rgb(var(--medal-gold-rgb));
    --medal-silver-rgb: 160, 160, 160;
    --medal-silver: rgb(var(--medal-silver-rgb));
    --medal-bronze-rgb: 205, 127, 50;
    --medal-bronze: rgb(var(--medal-bronze-rgb));

    /* RRS high contrast (prefers-contrast: high): fixed light colors for
       outdoor glare. */
    --hc-bg: #fff;
    --hc-border: #333;
    --hc-primary: #0056b3;
    --hc-danger: #b31b2c;
    --hc-success: #1e7e34;
    --hc-warning: #ffc107;
    --hc-on-warning: #000;
    --hc-time: #006400;
    --hc-error-bg: #ffcccc;
    --hc-error-border: #990000;
    --hc-error-text: #660000;
    --hc-success-bg: #ccffcc;
    --hc-success-border: #006600;
    --hc-success-text: #004400;

    /* Typefaces. --font-ui: the TLS race page, read at a timing desk. */
    --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

    /* Type scale */
    --font-2xs: 0.6875rem;  /* 11px */
    --font-xs: 0.75rem;     /* 12px */
    --font-sm: 0.875rem;    /* 14px */
    --font-base: 1rem;      /* 16px */
    --font-md: 1.125rem;    /* 18px */
    --font-lg: 1.25rem;     /* 20px */
    --font-xl: 1.5rem;      /* 24px */
    --font-2xl: 1.75rem;    /* 28px */
    --font-3xl: 2rem;       /* 32px */
    --font-4xl: 3rem;       /* 48px */

    /* Spacing scale: padding, margin, gap */
    --space-1: 0.125rem;    /* 2px */
    --space-2: 0.25rem;     /* 4px */
    --space-3: 0.375rem;    /* 6px */
    --space-4: 0.5rem;      /* 8px */
    --space-5: 0.625rem;    /* 10px */
    --space-6: 0.75rem;     /* 12px */
    --space-7: 1rem;        /* 16px */
    --space-8: 1.25rem;     /* 20px */
    --space-9: 1.5rem;      /* 24px */
    --space-10: 2rem;       /* 32px */
    --space-11: 2.5rem;     /* 40px */
    --space-12: 3rem;       /* 48px */
    --space-13: 3.75rem;    /* 60px */

    /* Radius */
    --radius-sm: 4px;
    --radius: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-pill: 999px;
    --radius-round: 50%;
}

/* ============================================
   RESET & BASE
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-mono);
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* ============================================
   LAYOUT
   ============================================ */

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-10);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-10);
    padding-bottom: var(--space-7);
    border-bottom: 1px solid var(--border);
}

main {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-9);
}

/* ============================================
   TYPOGRAPHY
   ============================================ */

h1 {
    font-size: var(--font-2xl);
    font-weight: 600;
}

h2 {
    font-size: var(--font-lg);
    font-weight: 500;
    margin-bottom: var(--space-7);
}

h3 {
    font-size: var(--font-md);
    font-weight: 500;
}

.gradient-text {
    background: linear-gradient(135deg, var(--start-color), var(--finish-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
   NAVIGATION
   ============================================ */

nav {
    display: flex;
    gap: var(--space-7);
}

nav a {
    color: var(--text-muted);
    text-decoration: none;
    padding: var(--space-4) var(--space-7);
    border-radius: var(--radius);
    transition: all 0.2s;
}

nav a:hover,
nav a.active {
    color: var(--text);
    background: var(--bg-input);
}

/* ============================================
   CARDS
   ============================================ */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-9);
    margin-bottom: var(--space-9);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-9);
}

.card h2 {
    font-size: var(--font-md);
    font-weight: 500;
    margin-bottom: 0;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4) var(--space-7);
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: var(--font-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    min-height: 36px;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Button variants: filled buttons use the -fill colors (white text at
   4.5:1); hover lightens the fill. */
.btn-primary {
    background: var(--accent-fill);
    color: var(--text-bright);
}

.btn-success {
    background: var(--success-fill);
    color: var(--text-bright);
}

.btn-danger {
    background: var(--danger-fill);
    color: var(--text-bright);
}

.btn-warning {
    background: var(--warning-fill);
    color: var(--text-bright);
}

.btn-primary:hover:not(:disabled),
.btn-success:hover:not(:disabled),
.btn-danger:hover:not(:disabled),
.btn-warning:hover:not(:disabled) {
    filter: brightness(1.15);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

.btn-outline-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-outline-danger:hover:not(:disabled) {
    background: var(--danger-fill);
    color: var(--text-bright);
}

.btn-sm {
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-xs);
    min-height: 28px;
}

.btn-lg {
    padding: var(--space-7) var(--space-10);
    font-size: var(--font-lg);
    font-weight: 600;
    min-height: 48px;
}

/* ============================================
   FORMS
   ============================================ */

.form-group {
    margin-bottom: var(--space-7);
}

label {
    display: block;
    font-size: var(--font-sm);
    color: var(--text-muted);
    margin-bottom: var(--space-4);
}

input,
select,
textarea {
    width: 100%;
    padding: var(--space-5) var(--space-6);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: var(--font-sm);
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    min-height: 100px;
    resize: vertical;
}

/* Form layouts */
.form-row {
    display: grid;
    grid-template-columns: 2fr 2fr 1fr;
    gap: var(--space-6);
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
}

.form-actions {
    display: flex;
    gap: var(--space-6);
    margin-top: var(--space-7);
}

.form-help {
    font-size: var(--font-xs);
    color: var(--text-muted);
    margin-top: var(--space-2);
}

/* ============================================
   TABLES
   ============================================ */

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-sm);
}

.table th,
.table td {
    padding: var(--space-6);
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    font-size: var(--font-xs);
    background: var(--bg-input);
    position: sticky;
    top: 0;
}

.table tbody tr {
    transition: background-color 0.15s;
}

.table tbody tr:hover {
    background: var(--bg-input);
}

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

/* ============================================
   STATUS BADGES
   ============================================ */

.status-badge {
    display: inline-block;
    padding: var(--space-1) var(--space-4);
    border-radius: var(--radius-sm);
    font-size: var(--font-xs);
    font-weight: 500;
    text-transform: uppercase;
}

/* Runner status badges (TLS race page): not yet seen, on course, done.
   Amber stays for flags that need attention. */
.status-badge.registered {
    background: rgba(var(--text-muted-rgb), 0.2);
    color: var(--text-muted);
}

.status-badge.started {
    background: rgba(var(--accent-rgb), 0.2);
    color: var(--accent);
}

.status-badge.finished {
    background: rgba(var(--success-rgb), 0.2);
    color: var(--success);
}

/* Race status badges */
.status.created {
    background: rgba(var(--accent-rgb), 0.2);
    color: var(--accent);
}

.status.active {
    background: rgba(var(--success-rgb), 0.2);
    color: var(--success);
}

.status.ended {
    background: rgba(var(--text-muted-rgb), 0.2);
    color: var(--text-muted);
}

/* ============================================
   CONNECTION STATUS
   ============================================ */

.status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    font-size: var(--font-sm);
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-round);
    background: var(--danger);
}

.status-dot.connected {
    background: var(--success);
    animation: pulse 2s infinite;
}

.status-connected {
    background: rgba(var(--success-rgb), 0.2);
    color: var(--success);
    padding: var(--space-4) var(--space-7);
    border-radius: var(--radius);
    font-size: var(--font-sm);
    font-weight: 500;
}

.status-disconnected {
    background: rgba(var(--danger-rgb), 0.2);
    color: var(--danger);
    padding: var(--space-4) var(--space-7);
    border-radius: var(--radius);
    font-size: var(--font-sm);
    font-weight: 500;
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
}

.toast {
    padding: var(--space-7) var(--space-9);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: var(--space-6);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    margin-top: var(--space-4);
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--danger);
}

.toast.info {
    border-color: var(--accent);
}

.toast.warning {
    border-color: var(--warning);
}

/* ============================================
   EMPTY STATES
   ============================================ */

.empty-state {
    text-align: center;
    padding: var(--space-10);
    color: var(--text-muted);
}

.empty-state h2 {
    color: var(--text-muted);
    margin-bottom: var(--space-4);
}

.empty-state p {
    font-size: var(--font-sm);
}

/* ============================================
   STAT CARDS
   ============================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-7);
    margin-bottom: var(--space-7);
}

.stat-card {
    background: var(--bg-input);
    padding: var(--space-7);
    border-radius: var(--radius-md);
    text-align: center;
}

.stat-card .value {
    font-size: var(--font-3xl);
    font-weight: 700;
    color: var(--accent);
}

.stat-card .label {
    font-size: var(--font-xs);
    color: var(--text-muted);
    text-transform: uppercase;
}

/* ============================================
   MODALS
   ============================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--shadow-rgb), 0.7);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-9);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-9);
}

.modal-title {
    font-size: var(--font-lg);
    font-weight: 500;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: var(--font-xl);
    cursor: pointer;
    padding: var(--space-2);
    line-height: 1;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    margin-bottom: var(--space-9);
}

.modal-actions {
    display: flex;
    gap: var(--space-6);
    justify-content: flex-end;
}

/* ============================================
   PAGINATION
   ============================================ */

.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-4);
    margin-top: var(--space-9);
    flex-wrap: wrap;
}

.page-btn {
    min-width: 36px;
    min-height: 36px;
    padding: var(--space-4);
    font-size: var(--font-sm);
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
    border-color: var(--accent);
    background: var(--bg-card);
}

.page-btn.active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--text-bright);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    padding: 0 var(--space-7);
    color: var(--text-muted);
    font-size: var(--font-sm);
}

/* ============================================
   TABS
   ============================================ */

.tab-nav {
    display: flex;
    gap: var(--space-2);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-9);
}

.tab-btn {
    padding: var(--space-6) var(--space-8);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: var(--font-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ============================================
   SEARCH
   ============================================ */

.search-form {
    display: flex;
    gap: var(--space-6);
    margin-bottom: var(--space-9);
}

.search-input-group {
    flex: 1;
    display: flex;
    gap: var(--space-6);
}

.search-input {
    flex: 1;
    padding: var(--space-6) var(--space-7);
    font-size: var(--font-base);
}

.search-help {
    font-size: var(--font-xs);
    color: var(--text-muted);
    margin-top: var(--space-4);
}

/* ============================================
   RESULT CARDS
   ============================================ */

.result-card {
    display: block;
    padding: var(--space-7) var(--space-8);
    margin-bottom: var(--space-6);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.result-card:hover,
.result-card:focus {
    border-color: var(--accent);
    outline: none;
}

.result-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

.result-bib {
    font-size: var(--font-lg);
    font-weight: 700;
    color: var(--accent);
}

.result-name {
    font-size: var(--font-base);
    font-weight: 500;
}

.result-category {
    font-size: var(--font-sm);
    color: var(--text-muted);
}

.result-times {
    display: flex;
    gap: var(--space-7);
    font-size: var(--font-sm);
    margin-top: var(--space-4);
}

.time-label {
    color: var(--text-muted);
}

.time-value {
    font-weight: 600;
    color: var(--success);
}

.result-ranks {
    display: flex;
    gap: var(--space-7);
    margin-top: var(--space-4);
}

.rank {
    font-size: var(--font-sm);
    color: var(--text-muted);
}

.rank.overall-rank {
    color: var(--accent);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px; /* visually-hidden pattern: 1px box, not a spacing step */
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

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

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.text-warning {
    color: var(--warning);
}

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

.monospace {
    font-family: var(--font-mono);
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .container {
        padding: var(--space-7);
    }
    
    header {
        flex-direction: column;
        gap: var(--space-7);
        text-align: center;
    }
    
    .form-row,
    .form-row-2 {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .modal-content {
        width: 95%;
        margin: var(--space-7);
    }
    
    .search-form,
    .search-input-group {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    nav {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* An award winner's line under the name in a ranked list (placing.js,
   awardLineHTML): RRS's kiosk and the live site. */
.award-line { margin-top: var(--space-1); font-size: var(--font-xs); font-weight: 600; color: var(--text); }
.award-line b { font-weight: 800; }
.award-line .award-gold { color: var(--medal-gold); }
.award-line .award-silver { color: var(--medal-silver); }
.award-line .award-bronze { color: var(--medal-bronze); }

/* The category settings form (categories-form.js): TLS's Categories page
   and RMS's Categories step. */
.cat-form .fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-6) var(--space-7); }
.cat-form .fields.two { grid-template-columns: repeat(2, 1fr); }
.cat-form .check { display: flex; gap: var(--space-4); align-items: flex-start; color: var(--text); font-size: var(--font-sm); }
.cat-form .check input { width: auto; margin-top: var(--space-1); }
.cat-form .race-bands { display: flex; gap: var(--space-4); align-items: center; flex-wrap: wrap; }
.cat-form .race-bands select, .cat-form .race-bands input[type=number] { width: auto; }
.cat-form .race-bands input[type=number] { width: 5.5rem; }
.cat-form .race-bands input[type=text] { width: 18rem; }
.cat-form .race-bands .check { white-space: nowrap; }
.cat-form .group-tag { font-size: var(--font-xs); color: var(--accent); }
.cat-form .weight-ranges textarea { width: 100%; min-height: 6rem; resize: vertical; font: inherit; }
.cat-form .custom-row { display: flex; gap: var(--space-6); align-items: center; margin-bottom: var(--space-4); flex-wrap: wrap; }
.cat-form .custom-row input[type=text] { width: 18rem; }
.cat-form .custom-row .check { white-space: nowrap; }

@media (max-width: 700px) {
    .cat-form .fields, .cat-form .fields.two { grid-template-columns: 1fr; }
}
