/* ==========================================================
   TAMIYA RACE CMS - STYLESHEET
   Clean, Modern, Responsive Administration Panel
   ========================================================== */

:root {
  --bg-main: #0c0f1d;
  --bg-card: #151a2d;
  --bg-input: #1d243c;
  --border-color: #2b3558;
  
  --primary: #8b5cf6;
  --primary-hover: #7c3aed;
  --accent-cyan: #06b6d4;
  --accent-gold: #f59e0b;
  --accent-silver: #94a3b8;
  --success: #10b981;
  --danger: #ef4444;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-race: 'Orbitron', monospace, sans-serif;
  --font-body: 'Rajdhani', sans-serif;
}

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

body {
  font-family: var(--font-body);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  padding-bottom: 90px;
}

/* Header */
.cms-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 16px 28px;
  background: #111526;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge-role {
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
  color: #fff;
  font-size: 0.72rem;
  font-family: var(--font-race);
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 1px;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* Realtime Server Indicator Badge */
.cms-realtime-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.4);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  color: #a7f3d0;
  letter-spacing: 0.5px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.cms-realtime-badge.status-connecting {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fde68a;
}

.cms-realtime-badge.status-offline {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
  display: inline-block;
  animation: live-pulse-glow 1.5s infinite;
}

.status-connecting .live-dot {
  background-color: #f59e0b;
  box-shadow: 0 0 8px #f59e0b;
}

.status-offline .live-dot {
  background-color: #ef4444;
  box-shadow: 0 0 8px #ef4444;
  animation: none;
}

@keyframes live-pulse-glow {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.25); opacity: 1; box-shadow: 0 0 12px currentColor; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.2s;
}

.btn-save {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
}

.btn-save:hover {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-1px);
}

.btn-view {
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  color: #ffffff;
}

.btn-view:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

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

.btn-outline:hover {
  background: rgba(6, 182, 212, 0.15);
}

/* Container */
.cms-container {
  max-width: 1240px;
  margin: 24px auto;
  padding: 0 20px 90px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ==========================================================
   TRACK NAVIGATION & MANAGEMENT BAR
   ========================================================== */
.cms-track-nav-card {
  background: #111628;
  border: 1px solid rgba(139, 92, 246, 0.4);
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.track-nav-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.track-badge-label {
  font-family: var(--font-race);
  font-size: 0.78rem;
  color: #c084fc;
  font-weight: 800;
  letter-spacing: 1px;
  display: block;
  margin-bottom: 8px;
}

.cms-track-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.cms-tab-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: var(--font-race);
  font-weight: 700;
  font-size: 0.88rem;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cms-tab-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.cms-tab-btn.active {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  border-color: #a855f7;
  color: #fff;
  box-shadow: 0 0 15px rgba(124, 58, 237, 0.4);
}

.cms-tab-btn .star-active {
  color: #fbbf24;
  font-size: 0.85rem;
}

.track-nav-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-del-track:hover {
  background: rgba(239, 68, 68, 0.25) !important;
  color: #f87171 !important;
  border-color: #ef4444 !important;
}

/* ==========================================================
   TRACK CONFIG & BACKGROUND UPLOAD
   ========================================================== */
.track-config-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
}

@media (max-width: 900px) {
  .track-config-grid {
    grid-template-columns: 1fr;
  }
}

.bg-upload-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(0, 0, 0, 0.25);
  padding: 16px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

.section-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: #38bdf8;
}

.bg-preview-container {
  position: relative;
  width: 100%;
  aspect-ratio: 576 / 1024;
  max-height: 240px;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: aspect-ratio 0.3s ease, max-height 0.3s ease;
}

.bg-preview-container.orientation-horizontal {
  aspect-ratio: 1024 / 580;
  max-height: 200px;
}

.bg-preview-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.bg-preview-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  color: #cbd5e1;
  font-size: 0.72rem;
  padding: 3px 6px;
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* CMS Orientation Selector Group */
.orientation-select-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sub-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 0.5px;
}

.orientation-btn-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.btn-orient-cms {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 8px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.btn-orient-cms:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.btn-orient-cms.active {
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  border-color: #38bdf8;
  color: #fff;
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.4);
}

/* Preset Template Buttons */
.preset-templates-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preset-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.btn-sm {
  padding: 6px 8px;
  font-size: 0.78rem;
  font-weight: 600;
}

.bg-upload-controls {
  display: flex;
  gap: 8px;
}

.btn-upload-file {
  cursor: pointer;
  flex: 1;
  text-align: center;
  justify-content: center;
  font-size: 0.85rem;
}

.input-bg-path {
  font-size: 0.82rem !important;
  color: #94a3b8 !important;
}

/* CMS Cards */
.cms-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.25);
}

.card-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.card-title-bar h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
}

.card-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-group-right {
  display: flex;
  gap: 8px;
}

/* Form Grid */
.form-grid {
  display: grid;
  gap: 16px;
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #cbd5e1;
}

.help-text {
  font-size: 0.78rem;
  color: var(--text-muted);
}

input[type="text"],
input[type="number"],
select {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: #ffffff;
  padding: 9px 12px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.2s;
  width: 100%;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.2);
}

.input-with-unit {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-unit .unit {
  position: absolute;
  right: 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
  pointer-events: none;
}

.input-bold {
  font-weight: 700;
  color: #38bdf8 !important;
}

.input-time {
  font-family: var(--font-race);
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* BTO Section */
.bto-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px;
}

.bto-highlight-card {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  padding: 18px;
  border: 1px solid;
}

.bto-highlight-card.bto-1 {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.04);
}

.bto-highlight-card.bto-2 {
  border-color: rgba(148, 163, 184, 0.4);
  background: rgba(148, 163, 184, 0.04);
}

.bto-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.bto-badge {
  font-family: var(--font-race);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 4px;
}

.badge-gold {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.5);
}

.badge-silver {
  background: rgba(148, 163, 184, 0.2);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.5);
}

.btn-quick-auto {
  background: rgba(255, 255, 255, 0.08);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn-quick-auto:hover {
  background: rgba(56, 189, 248, 0.2);
}

/* Table Section */
.table-container {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.cms-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.cms-table th {
  background: #111526;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 10px 8px;
  border-bottom: 2px solid var(--border-color);
  text-align: left;
}

.cms-table td {
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  vertical-align: middle;
}

.cms-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.cms-table input[type="text"],
.cms-table input[type="number"],
.cms-table select {
  padding: 6px 8px;
  font-size: 0.9rem;
}

.action-buttons {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: #fff;
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-icon.btn-delete:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #f87171;
  border-color: #ef4444;
}

/* Stopwatch Section */
.stopwatch-section {
  background: #101529;
}

.stopwatch-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 10px;
}

.stopwatch-display {
  font-family: var(--font-race);
  font-size: 3.5rem;
  font-weight: 900;
  color: #22d3ee;
  letter-spacing: 2px;
  text-shadow: 0 0 20px rgba(34, 211, 238, 0.4);
}

.stopwatch-controls {
  display: flex;
  gap: 12px;
}

.btn-sw {
  font-family: var(--font-race);
  font-size: 0.95rem;
  padding: 8px 24px;
  border-radius: 6px;
}

.btn-sw-start {
  background: #10b981;
  color: #000;
  font-weight: 800;
}

.btn-sw-start.running {
  background: #ef4444;
  color: #fff;
}

.btn-sw-lap {
  background: #0284c7;
  color: #fff;
}

.btn-sw-reset {
  background: #475569;
  color: #fff;
}

.stopwatch-laps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 600px;
  justify-content: center;
}

.lap-pill {
  background: rgba(255, 255, 255, 0.07);
  padding: 4px 10px;
  border-radius: 6px;
  font-family: var(--font-race);
  font-size: 0.85rem;
  color: #38bdf8;
}

/* Bottom Bar */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(15, 20, 36, 0.95);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border-color);
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 90;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  right: 24px;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 700;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  z-index: 1000;
  opacity: 0;
  transform: translateY(-20px);
  transition: all 0.3s ease;
  pointer-events: none;
}

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

@media (max-width: 768px) {
  .cms-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .bottom-bar {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}
