/* Rally TC Results — motorsport dark-first design */

/* ============================================================
   Custom properties — dark theme (default)
   ============================================================ */
.rtr-widget {
	--rtr-bg:           #0b0c10;
	--rtr-surface:      #14151e;
	--rtr-surface-2:    #1c1d28;
	--rtr-border:       #2c2d3e;
	--rtr-text:         #dde0ef;
	--rtr-text-muted:   #7a7d94;
	--rtr-text-dim:     #4a4d60;
	--rtr-accent:       #e8b800;
	--rtr-accent-dim:   rgba(232, 184, 0, 0.12);
	--rtr-leader-left:  #e8b800;
	--rtr-row-hover:    rgba(255, 255, 255, 0.03);
	--rtr-notime-bg:    rgba(0, 0, 0, 0.25);
	--rtr-notime-text:  #4a4d60;
	--rtr-pos1-bg:      #e8b800;
	--rtr-pos1-fg:      #000;
	--rtr-pos2-bg:      #b0b4c8;
	--rtr-pos2-fg:      #000;
	--rtr-pos3-bg:      #c07840;
	--rtr-pos3-fg:      #fff;
	--rtr-pos-other-bg: #2c2d3e;
	--rtr-pos-other-fg: #7a7d94;

	font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
	background: var(--rtr-bg);
	color: var(--rtr-text);
	border-radius: 10px;
	overflow: hidden;
	box-shadow: 0 6px 32px rgba(0, 0, 0, 0.5);
	margin: 1.5em 0;
}

/* ============================================================
   Light theme overrides
   ============================================================ */
.rtr-widget.rtr-theme-light {
	--rtr-bg:           #f2f3f8;
	--rtr-surface:      #ffffff;
	--rtr-surface-2:    #ecedf5;
	--rtr-border:       #d4d6e6;
	--rtr-text:         #1a1b28;
	--rtr-text-muted:   #646880;
	--rtr-text-dim:     #9294a8;
	--rtr-accent-dim:   rgba(200, 155, 0, 0.14);
	--rtr-row-hover:    rgba(0, 0, 0, 0.025);
	--rtr-notime-bg:    rgba(0, 0, 0, 0.035);
	--rtr-notime-text:  #9294a8;
	--rtr-pos-other-bg: #d4d6e6;
	--rtr-pos-other-fg: #646880;
	box-shadow: 0 2px 14px rgba(0, 0, 0, 0.12);
}

/* ============================================================
   Header — always dark regardless of theme
   ============================================================ */
.rtr-header {
	background: linear-gradient(135deg, #0a1520 0%, #12243a 55%, #0a1520 100%);
	padding: 20px 24px 18px;
	position: relative;
	overflow: hidden;
}

/* Gold accent stripe at top */
.rtr-header::before {
	content: '';
	position: absolute;
	top: 0; left: 0; right: 0;
	height: 3px;
	background: linear-gradient(90deg, transparent 0%, #e8b800 40%, #e8b800 60%, transparent 100%);
}

/* Subtle chequered flag watermark */
.rtr-header::after {
	content: '';
	position: absolute;
	top: 0; right: 0; bottom: 0;
	width: 140px;
	background-image: repeating-conic-gradient(rgba(255,255,255,0.03) 0% 25%, transparent 0% 50%);
	background-size: 16px 16px;
	pointer-events: none;
}

.rtr-rally-name {
	font-size: 1.5rem;
	font-weight: 800;
	color: #fff;
	letter-spacing: 0.5px;
	line-height: 1.2;
	text-transform: uppercase;
	position: relative;
}

.rtr-rally-meta {
	margin-top: 6px;
	display: flex;
	flex-wrap: wrap;
	gap: 14px;
	position: relative;
}

.rtr-meta-item {
	font-size: 0.82rem;
	color: #94a8c0;
	font-weight: 500;
}

/* ============================================================
   Toolbar (TC count + refresh info)
   ============================================================ */
.rtr-toolbar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 8px 16px;
	background: var(--rtr-surface-2);
	border-bottom: 1px solid var(--rtr-border);
	font-size: 0.78rem;
	flex-wrap: wrap;
	gap: 6px;
}

.rtr-tc-count {
	font-weight: 600;
	color: var(--rtr-text-muted);
	text-transform: uppercase;
	letter-spacing: 0.6px;
	font-size: 0.72rem;
}

.rtr-refresh-info {
	display: flex;
	align-items: center;
	gap: 10px;
	color: var(--rtr-text-muted);
}

.rtr-updating {
	display: flex;
	align-items: center;
	gap: 4px;
	color: var(--rtr-accent);
	font-weight: 600;
	font-size: 0.75rem;
	animation: rtr-pulse 1s ease-in-out infinite;
}

.rtr-last-updated {
	font-size: 0.72rem;
	color: var(--rtr-text-muted);
}

.rtr-hidden {
	display: none !important;
}

@keyframes rtr-pulse {
	0%, 100% { opacity: 1; }
	50%       { opacity: 0.4; }
}

/* ============================================================
   Tab navigation
   ============================================================ */
.rtr-tab-nav {
	display: flex;
	gap: 0;
	background: var(--rtr-surface);
	border-bottom: 2px solid var(--rtr-border);
	overflow-x: auto;
	scrollbar-width: none;
	-ms-overflow-style: none;
}

.rtr-tab-nav::-webkit-scrollbar { display: none; }

.rtr-tab-btn {
	flex-shrink: 0;
	padding: 11px 20px;
	background: none;
	border: none;
	border-bottom: 3px solid transparent;
	margin-bottom: -2px;
	color: var(--rtr-text-muted);
	font-size: 0.8rem;
	font-weight: 700;
	letter-spacing: 0.8px;
	text-transform: uppercase;
	cursor: pointer;
	transition: color 0.18s, border-color 0.18s;
	white-space: nowrap;
}

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

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

.rtr-tab-btn.rtr-tab-accum {
	color: var(--rtr-accent);
	font-weight: 800;
	letter-spacing: 1px;
}

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

.rtr-badge-accum {
	background: linear-gradient(135deg, #e8b800 0%, #ff7800 100%) !important;
	color: #000 !important;
}

.rtr-no-data {
	padding: 28px 20px;
	text-align: center;
	color: var(--rtr-text-muted);
	font-size: 0.88rem;
	font-style: italic;
}

/* ============================================================
   TC panels
   ============================================================ */
.rtr-tc-panel {
	display: none;
	background: var(--rtr-surface);
}

.rtr-tc-panel.rtr-panel-active {
	display: block;
}

/* TC info chips bar */
.rtr-tc-info {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	padding: 10px 16px;
	background: var(--rtr-surface-2);
	border-bottom: 1px solid var(--rtr-border);
}

.rtr-tc-info span {
	font-size: 0.76rem;
	font-weight: 600;
	color: var(--rtr-text-muted);
	white-space: nowrap;
}

.rtr-tc-badge {
	background: var(--rtr-accent);
	color: #000 !important;
	padding: 2px 9px;
	border-radius: 4px;
	font-size: 0.72rem !important;
	font-weight: 800 !important;
	letter-spacing: 0.5px;
	text-transform: uppercase;
}

.rtr-tc-code {
	background: var(--rtr-surface);
	border: 1px solid var(--rtr-border);
	padding: 2px 9px;
	border-radius: 4px;
	font-family: 'Courier New', monospace;
	font-size: 0.76rem !important;
	letter-spacing: 1px;
}

/* ============================================================
   Results table
   ============================================================ */
.rtr-table-wrap {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.rtr-results-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.82rem;
}

.rtr-results-table thead th {
	background: var(--rtr-surface-2);
	color: var(--rtr-text-muted);
	font-size: 0.68rem;
	font-weight: 700;
	letter-spacing: 1.2px;
	text-transform: uppercase;
	padding: 9px 12px;
	text-align: left;
	border-bottom: 2px solid var(--rtr-border);
	white-space: nowrap;
	position: sticky;
	top: 0;
	z-index: 1;
}

.rtr-results-table thead th.rtr-col-pos,
.rtr-results-table thead th.rtr-col-car {
	text-align: center;
}


.rtr-results-table tbody tr {
	border-bottom: 1px solid var(--rtr-border);
	transition: background 0.12s;
}

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

.rtr-results-table tbody tr:hover {
	background: var(--rtr-row-hover);
}

.rtr-results-table tbody td {
	padding: 9px 12px;
	vertical-align: middle;
}

.rtr-results-table tbody td.rtr-col-pos,
.rtr-results-table tbody td.rtr-col-car {
	text-align: center;
}

/* ============================================================
   Leader row
   ============================================================ */
.rtr-row-leader {
	background: var(--rtr-accent-dim) !important;
	border-left: 3px solid var(--rtr-leader-left) !important;
}

/* ============================================================
   No-time row
   ============================================================ */
.rtr-row-notime {
	background: var(--rtr-notime-bg) !important;
}

.rtr-row-notime td {
	color: var(--rtr-notime-text) !important;
}

.rtr-no-time {
	font-style: italic;
	font-size: 0.75rem;
	color: var(--rtr-text-dim);
}

/* ============================================================
   Position badges
   ============================================================ */
.rtr-pos {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	font-weight: 800;
	font-size: 0.78rem;
	line-height: 1;
}

.rtr-pos-1    { background: var(--rtr-pos1-bg); color: var(--rtr-pos1-fg); }
.rtr-pos-2    { background: var(--rtr-pos2-bg); color: var(--rtr-pos2-fg); }
.rtr-pos-3    { background: var(--rtr-pos3-bg); color: var(--rtr-pos3-fg); }
.rtr-pos-other { background: var(--rtr-pos-other-bg); color: var(--rtr-pos-other-fg); }
.rtr-pos-none  { color: var(--rtr-text-dim); width: auto; height: auto; }

/* ============================================================
   Car number
   ============================================================ */
.rtr-col-car {
	font-weight: 700;
	color: var(--rtr-text-muted);
	font-size: 0.9rem;
}

/* ============================================================
   Crew names
   ============================================================ */
.rtr-pilot {
	font-weight: 700;
	font-size: 0.84rem;
	color: var(--rtr-text);
	line-height: 1.3;
}

.rtr-copilot {
	font-size: 0.74rem;
	color: var(--rtr-text-muted);
	line-height: 1.3;
}

/* ============================================================
   Category chip
   ============================================================ */
.rtr-category {
	display: inline-block;
	padding: 1px 7px;
	border-radius: 3px;
	border: 1px solid var(--rtr-border);
	font-size: 0.7rem;
	font-weight: 700;
	letter-spacing: 0.5px;
	color: var(--rtr-text-muted);
	white-space: nowrap;
}

/* ============================================================
   Brand logo / badge
   ============================================================ */

/* Wrapper pill — fondo blanco sólido para que CUALQUIER logo
   sea legible independientemente del color del tema.
   Es el estándar en pantallas de cronometraje (WRC, F1, etc.) */
.rtr-brand-logo-wrap {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 52px;
	height: 30px;
	flex-shrink: 0;
	vertical-align: middle;
	border-radius: 6px;
	background: #ffffff;
	border: 1px solid rgba(0, 0, 0, 0.12);
	box-shadow:
		0 2px 8px rgba(0, 0, 0, 0.55),
		inset 0 1px 0 rgba(255, 255, 255, 1);
	transition: box-shadow 0.18s, transform 0.18s;
	overflow: hidden;
}

.rtr-brand-logo-wrap:hover {
	box-shadow:
		0 4px 14px rgba(0, 0, 0, 0.65),
		inset 0 1px 0 rgba(255, 255, 255, 1);
	transform: translateY(-1px);
}

.rtr-brand-logo {
	display: block;
	width: 40px;
	height: 22px;
	object-fit: contain;
	object-position: center;
}

/* Light theme: misma tarjeta blanca, sombra más suave */
.rtr-theme-light .rtr-brand-logo-wrap {
	box-shadow:
		0 1px 5px rgba(0, 0, 0, 0.18),
		inset 0 1px 0 rgba(255, 255, 255, 1);
	border-color: rgba(0, 0, 0, 0.10);
}

.rtr-theme-light .rtr-brand-logo-wrap:hover {
	box-shadow:
		0 3px 10px rgba(0, 0, 0, 0.22),
		inset 0 1px 0 rgba(255, 255, 255, 1);
}

/* Fallback text badge for unknown brands */
.rtr-brand-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 36px;
	height: 22px;
	padding: 0 6px;
	border-radius: 5px;
	font-size: 0.58rem;
	font-weight: 900;
	letter-spacing: 0.06em;
	white-space: nowrap;
	vertical-align: middle;
	flex-shrink: 0;
	box-shadow:
		0 2px 6px rgba(0, 0, 0, 0.30),
		inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.rtr-brand-badge--generic {
	background: rgba(255, 255, 255, 0.10);
	border: 1px solid rgba(255, 255, 255, 0.14);
	color: var(--rtr-text-muted);
}

.rtr-theme-light .rtr-brand-badge--generic {
	background: rgba(0, 0, 0, 0.07);
	border-color: rgba(0, 0, 0, 0.12);
	color: var(--rtr-text-muted);
}

/* Vehicle cell — flex row: logo pill + stacked brand/model text */
.rtr-veh-cell {
	display: flex;
	align-items: center;
	gap: 9px;
	min-width: 0;
}

.rtr-veh-info {
	display: flex;
	flex-direction: column;
	justify-content: center;
	min-width: 0;
	gap: 1px;
}

.rtr-veh-brand {
	font-size: 0.62rem;
	font-weight: 800;
	letter-spacing: 0.8px;
	text-transform: uppercase;
	color: var(--rtr-text-muted);
	line-height: 1.2;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.rtr-veh-model {
	font-size: 0.80rem;
	font-weight: 600;
	color: var(--rtr-text);
	line-height: 1.3;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* ============================================================
   Time column
   ============================================================ */
.rtr-col-time strong {
	font-size: 0.88rem;
	font-variant-numeric: tabular-nums;
	letter-spacing: 0.3px;
}

.rtr-penalty {
	font-size: 0.7rem;
	color: #ef9a00;
	background: rgba(239, 154, 0, 0.12);
	padding: 1px 5px;
	border-radius: 3px;
	margin-left: 4px;
}

/* ============================================================
   Gap column
   ============================================================ */
.rtr-gap-leader {
	font-weight: 800;
	font-size: 0.72rem;
	letter-spacing: 1px;
	color: var(--rtr-accent);
	text-transform: uppercase;
}

.rtr-gap {
	font-variant-numeric: tabular-nums;
	font-size: 0.82rem;
	color: var(--rtr-text-muted);
}

.rtr-gap-none {
	color: var(--rtr-text-dim);
}

/* ============================================================
   Status badges
   ============================================================ */
.rtr-badge {
	display: inline-block;
	padding: 2px 7px;
	border-radius: 4px;
	font-size: 0.66rem;
	font-weight: 700;
	letter-spacing: 0.6px;
	text-transform: uppercase;
	white-space: nowrap;
}

.rtr-status-finished     { background: rgba(34, 197, 94, 0.14);  color: #4ade80; }
.rtr-status-started      { background: rgba(250, 204, 21, 0.14); color: #facc15; }
.rtr-status-registered   { background: rgba(96, 165, 250, 0.14); color: #60a5fa; }
.rtr-status-retired      { background: rgba(156, 163, 175, 0.14);color: #9ca3af; }
.rtr-status-disqualified { background: rgba(248, 113, 113, 0.14);color: #f87171; }

/* ============================================================
   Accumulated — category sections
   ============================================================ */
.rtr-category-sections {
	border-top: 2px solid var(--rtr-border);
}

.rtr-category-section {
	border-top: 1px solid var(--rtr-border);
}

.rtr-category-section:first-child {
	border-top: none;
}

.rtr-category-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 16px;
	background: var(--rtr-surface-2);
	border-bottom: 1px solid var(--rtr-border);
}

.rtr-category-title {
	font-size: 0.8rem;
	font-weight: 800;
	color: var(--rtr-accent);
	letter-spacing: 1.2px;
	text-transform: uppercase;
}

.rtr-category-crew-count {
	font-size: 0.74rem;
	font-weight: 600;
	color: var(--rtr-text-muted);
}

/* ============================================================
   Error box
   ============================================================ */
.rtr-error-box {
	padding: 12px 16px;
	background: rgba(239, 68, 68, 0.12);
	border-left: 3px solid #ef4444;
	color: #f87171;
	border-radius: 4px;
	font-size: 0.85rem;
	margin: 1em 0;
}

/* Light theme — adjust badge colors to be more legible */
.rtr-theme-light .rtr-status-finished     { background: rgba(22, 163, 74, 0.12);  color: #15803d; }
.rtr-theme-light .rtr-status-started      { background: rgba(202, 138, 4, 0.12);  color: #92400e; }
.rtr-theme-light .rtr-status-registered   { background: rgba(37, 99, 235, 0.12);  color: #1d4ed8; }
.rtr-theme-light .rtr-status-retired      { background: rgba(107, 114, 128, 0.12);color: #4b5563; }
.rtr-theme-light .rtr-status-disqualified { background: rgba(220, 38, 38, 0.1);   color: #b91c1c; }
.rtr-theme-light .rtr-gap-leader          { color: #b59000; }

/* ============================================================
   Responsive — tablet
   ============================================================ */
@media (max-width: 900px) {
	.rtr-veh-model {
		display: none;
	}
}

@media (max-width: 600px) {
	.rtr-veh-info {
		display: none;
	}
}

/* ============================================================
   Responsive — mobile
   ============================================================ */
@media (max-width: 600px) {
	.rtr-rally-name { font-size: 1.15rem; }

	.rtr-results-table tbody td,
	.rtr-results-table thead th {
		padding: 7px 8px;
	}

	.rtr-tc-info {
		gap: 6px;
		padding: 8px 12px;
	}

	.rtr-tab-btn {
		padding: 10px 14px;
		font-size: 0.74rem;
	}
}

@media (max-width: 420px) {
	.rtr-col-cat,
	.rtr-results-table thead th.rtr-col-cat,
	.rtr-results-table tbody td.rtr-col-cat {
		display: none;
	}
}
