/* ==========================================================================
   CloudApiTiming · tema Conersys (negro y rojo)
   ========================================================================== */
:root {
    --red: #ca0323;
    --red-hi: #e3122f;
    --red-lo: #8f0218;
    --red-soft: rgba(202, 3, 35, 0.12);
    --red-line: rgba(202, 3, 35, 0.45);

    --bg: #070708;
    --bg-2: #0d0d0f;
    --surface: #121215;
    --surface-2: #18181c;
    --surface-3: #202026;
    --border: #26262c;
    --border-2: #34343c;

    --text: #f4f4f6;
    --text-2: #a5a5ae;
    --text-3: #6c6c76;

    --ok: #2fbf71;
    --warn: #e5a50a;
    --danger: #ff4d5e;
    --gold: #d4af37;
    --silver: #c0c4cc;
    --bronze: #b8763e;

    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 12px 32px -18px rgba(0,0,0,0.9);
    --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;

    /* Alias usados por las páginas */
    --accent: var(--red);
    --accent-2: var(--red-hi);
    --accent-3: var(--red-lo);
    --glass: var(--surface-2);
    --glass-strong: var(--surface-3);
    --glass-border: var(--border);
    --glass-hi: var(--border-2);
}

* { box-sizing: border-box; }

html { background: var(--bg); }
html, body {
    margin: 0;
    min-height: 100%;
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}
body {
    background:
        radial-gradient(1200px 500px at 100% -10%, rgba(202, 3, 35, 0.10), transparent 60%),
        linear-gradient(180deg, var(--bg-2), var(--bg) 40%);
    background-attachment: fixed;
}

a { color: var(--red-hi); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
h1:focus { outline: none; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.spacer { height: 16px; }

/* ---------- Superficies ---------- */
.glass {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card { padding: 18px 20px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-title h3 {
    font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--text-2);
    display: flex; align-items: center; gap: 10px;
}
.card-title h3::before { content: ""; width: 3px; height: 14px; background: var(--red); border-radius: 2px; }
.subcard { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }

/* ---------- Estructura ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
    position: sticky; top: 0; height: 100vh;
    background: #000; border-right: 1px solid var(--border);
    padding: 22px 14px; display: flex; flex-direction: column; gap: 2px;
}
.brand { display: flex; flex-direction: column; gap: 8px; padding: 2px 8px 22px; border-bottom: 1px solid var(--border); margin-bottom: 14px; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-img { width: 168px; height: auto; display: block; }
.brand-sub { font-size: 10.5px; color: var(--text-3); letter-spacing: 0.16em; text-transform: uppercase; font-weight: 600; }
.nav-label { font-size: 10.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.14em; padding: 10px 10px 6px; font-weight: 600; }
.nav-link {
    position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text-2); font-weight: 500; transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--surface-2); color: #fff; }
.nav-link.active::before {
    content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; background: var(--red); border-radius: 0 3px 3px 0;
}
.nav-link.active svg { color: var(--red-hi); }
.nav-link svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); padding-top: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 10px; color: var(--text-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; text-transform: uppercase; }

.main { padding: 28px 34px 48px; min-width: 0; }
.page-head {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap;
    padding-bottom: 18px; border-bottom: 1px solid var(--border);
}
.page-head h1 { font-size: 24px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.eyebrow { font-size: 11px; color: var(--red-hi); text-transform: uppercase; letter-spacing: .16em; font-weight: 600; margin-bottom: 6px; }

/* ---------- Rejillas ---------- */
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }

/* ---------- Indicadores ---------- */
.stat { padding: 18px 20px; position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; right: 0; height: 2px; background: var(--stat-color, var(--border-2)); }
.stat-label { color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }
.stat-value { font-size: 32px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-foot { color: var(--text-2); font-size: 12px; margin-top: 2px; }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-2);
    background: var(--surface-2); color: var(--text); font: inherit; font-weight: 500; font-size: 13px;
    cursor: pointer; transition: background .15s, border-color .15s, color .15s; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-3); border-color: #44444d; text-decoration: none; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--red-hi); outline-offset: 2px; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--red-hi); border-color: var(--red-hi); }
.btn-danger { color: #ff8a95; border-color: rgba(255,77,94,0.35); background: rgba(255,77,94,0.08); }
.btn-danger:hover { background: rgba(255,77,94,0.16); border-color: rgba(255,77,94,0.5); }
.btn-live { background: #fff; color: #000; border-color: #fff; font-weight: 600; }
.btn-live:hover { background: #e9e9ee; border-color: #e9e9ee; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px 8px; }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .label { font-size: 11.5px; color: var(--text-2); font-weight: 500; letter-spacing: .02em; }
.input, select.input, textarea.input {
    width: 100%; padding: 9px 11px; border-radius: var(--radius-sm);
    background: var(--bg-2); border: 1px solid var(--border-2); color: var(--text);
    font: inherit; font-size: 13.5px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:hover { border-color: #44444d; }
.input:focus { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
select.input option { background: var(--surface); color: var(--text); }
.input-sm { padding: 6px 8px; font-size: 12.5px; }
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; }
.col-12 { grid-column: span 12; } .col-8 { grid-column: span 8; } .col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; } .col-2 { grid-column: span 2; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; color: var(--text-2); font-size: 13px; position: relative; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 34px; height: 20px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-2); position: relative; transition: background .2s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #8a8a94; transition: transform .2s, background .2s; }
.switch input:checked + .track { background: var(--red); border-color: var(--red); }
.switch input:checked + .track::after { transform: translateX(14px); background: #fff; }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--red-soft); }
.switch input:disabled + .track { opacity: .4; }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 16px; color: var(--text-2); cursor: pointer; font-weight: 500; border: none; background: none; font: inherit; font-size: 13.5px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: #fff; border-bottom-color: var(--red); }

/* ---------- Tablas ---------- */
.table-wrap { overflow: auto; border-radius: var(--radius-sm); }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
    text-align: left; font-weight: 600; color: var(--text-3); font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em;
    padding: 10px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
    background: var(--surface); z-index: 1; white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid #1b1b20; vertical-align: middle; }
.table tbody tr:hover { background: #16161a; }
.table .actions { text-align: right; white-space: nowrap; }
.table-compact td { padding: 6px 9px; }
.table-compact th { padding: 8px 9px; }

/* ---------- Etiquetas ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 600; letter-spacing: .04em; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text-2);
}
.badge-ok { color: #7ee2a8; background: rgba(47,191,113,0.1); border-color: rgba(47,191,113,0.35); }
.badge-warn { color: #f3c55a; background: rgba(229,165,10,0.1); border-color: rgba(229,165,10,0.35); }
.badge-danger { color: #ff8a95; background: rgba(255,77,94,0.1); border-color: rgba(255,77,94,0.35); }
.badge-info { color: #fff; background: var(--red); border-color: var(--red); }
.badge-type { font-family: var(--mono); font-size: 10.5px; padding: 1px 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #3a3a42; display: inline-block; flex: none; }
.dot-live { background: var(--red-hi); animation: pulse 1.6s infinite; }
.dot-err { background: var(--warn); }
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(227,18,47,0.6); }
    70% { box-shadow: 0 0 0 8px rgba(227,18,47,0); }
    100% { box-shadow: 0 0 0 0 rgba(227,18,47,0); }
}

/* ---------- Modales ---------- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 24px;
    animation: fade .15s ease;
}
.modal { min-width: 0; max-width: 100%; width: min(1180px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; background: var(--surface); border-top: 2px solid var(--red); }
.modal-sm { width: min(520px, 100%); }
.modal-full { width: min(1700px, 100%); height: calc(100vh - 48px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--border); gap: 12px; flex-wrap: wrap; }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 20px 22px; overflow: auto; flex: 1; min-width: 0; }
.modal-body > *, .stack > * { min-width: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); flex-wrap: wrap; background: var(--bg-2); border-radius: 0 0 var(--radius) var(--radius); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Avisos ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; border: 1px solid var(--border-2); background: var(--surface-2); border-left-width: 3px; }
.alert-ok { border-color: rgba(47,191,113,0.35); border-left-color: var(--ok); color: #bde8cf; }
.alert-danger { border-color: rgba(255,77,94,0.35); border-left-color: var(--danger); color: #ffc2c8; }
.alert-info { border-left-color: var(--red); color: var(--text-2); }

/* ---------- Tarjeta en vivo ---------- */
.live-card { padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.live-card > * { padding-left: 18px; padding-right: 18px; }
.live-card.running { border-color: var(--red-line); }
.live-card.running .live-head { background: linear-gradient(90deg, rgba(202,3,35,0.16), transparent 70%); }
.live-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding-top: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.live-title { font-size: 16px; font-weight: 600; }
.live-sub { color: var(--text-3); font-size: 12px; margin-top: 3px; }
.live-card .live-metrics { display: grid; grid-template-columns: repeat(3, 1fr); padding: 0; border-bottom: 1px solid var(--border); }
.metric { padding: 12px 18px; border-right: 1px solid var(--border); }
.metric:last-child { border-right: 0; }
.metric-v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-l { font-size: 10.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; }
.podium { display: flex; flex-direction: column; padding-top: 6px; padding-bottom: 6px; }
.podium-row { display: grid; grid-template-columns: 26px 40px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid #1b1b20; }
.podium-row:last-child { border-bottom: 0; }
.medal { width: 24px; height: 24px; border-radius: 4px; display: grid; place-items: center; font-weight: 800; font-size: 12px; color: #000; }
.medal-1 { background: var(--gold); }
.medal-2 { background: var(--silver); }
.medal-3 { background: var(--bronze); }
.changes { font-size: 12px; color: var(--text-2); min-height: 18px; padding-top: 10px; padding-bottom: 4px; border-top: 1px solid var(--border); }
.log { font-family: var(--mono); font-size: 11px; color: var(--text-3); max-height: 84px; overflow: auto; padding-bottom: 10px; }
.live-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; border-top: 1px solid var(--border); background: var(--bg-2); }

.status-DNF { color: var(--warn); font-weight: 600; }
.status-DQ { color: var(--danger); font-weight: 600; }
.status-DNS { color: var(--text-3); font-weight: 600; }
.split-pos { color: var(--text-3); font-size: 10.5px; margin-left: 4px; }
.split-cell { white-space: nowrap; }
.split-empty { color: #3a3a42; }

.empty { padding: 40px; text-align: center; color: var(--text-2); }
.empty h3 { margin-bottom: 6px; color: var(--text); }

/* ---------- Acceso ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(400px, 100%); padding: 34px 30px; display: flex; flex-direction: column; gap: 18px; border-top: 2px solid var(--red); }
.login .brand-img { width: 220px; margin: 0 auto; }
.login .brand-sub { text-align: center; }

/* ---------- Adaptable ---------- */
@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: sticky; top: 0; z-index: 50; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; gap: 2px; border-right: 0; border-bottom: 1px solid var(--border); }
    .sidebar .nav-label, .sidebar .brand-sub, .user-chip { display: none; }
    .sidebar .brand { padding: 0; border: 0; margin: 0 auto 0 0; }
    .sidebar .brand-img { width: 116px; }
    .nav-link { padding: 8px 10px; font-size: 13px; }
    .nav-link.active::before { display: none; }
    .sidebar-foot { margin-top: 0; border: 0; padding: 0; }
    .main { padding: 18px 14px 32px; }
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .grid-cards { grid-template-columns: 1fr; }
    .form-grid > * { grid-column: span 12; }
}
@media (max-width: 600px) {
    .nav-link .nav-text { display: none; }
}

/* ---------- Blazor ---------- */
#blazor-error-ui {
    background: var(--red-lo); color: #fff; bottom: 0; box-sizing: border-box; display: none; left: 0;
    padding: 0.6rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
#blazor-error-ui a { color: #fff; text-decoration: underline; }
.blazor-error-boundary { background: var(--red-lo); padding: 1rem; color: white; border-radius: 8px; }
.blazor-error-boundary::after { content: "Se ha producido un error."; }
.validation-message { color: var(--danger); font-size: 12px; }

/* ---------- Destello de cambios (visor interno) ---------- */
@keyframes rowFlash {
    0%   { background: rgba(47, 191, 113, 0.55); box-shadow: inset 4px 0 0 #2fbf71; }
    25%  { background: rgba(47, 191, 113, 0.30); box-shadow: inset 4px 0 0 #2fbf71; }
    100% { background: rgba(47, 191, 113, 0.08); box-shadow: inset 4px 0 0 #2fbf71; }
}
/* Dos nombres iguales para que la animación se reinicie si el atleta vuelve a cambiar. */
@keyframes rowFlash2 {
    0%   { background: rgba(47, 191, 113, 0.55); box-shadow: inset 4px 0 0 #2fbf71; }
    25%  { background: rgba(47, 191, 113, 0.30); box-shadow: inset 4px 0 0 #2fbf71; }
    100% { background: rgba(47, 191, 113, 0.08); box-shadow: inset 4px 0 0 #2fbf71; }
}
.table tbody tr.row-flash.f0 { animation: rowFlash 3s ease-out forwards; }
.table tbody tr.row-flash.f1 { animation: rowFlash2 3s ease-out forwards; }
.table tbody tr.row-flash td { color: #eafff2; }
.changed-at { color: #7ee2a8; font-weight: 600; }

.btn-copied { color: #7ee2a8; border-color: rgba(47,191,113,0.4); background: rgba(47,191,113,0.12); }
