:root {
  --bg: #0f172a; --surface: #1e293b; --text: #e2e8f0; --primary: #10b981;
  --warn: #f59e0b; --danger: #ef4444; --border: #334155; --radius: 10px;
  --touch: 48px; --gap: 12px; --card-bg: #1e293b;
}
* { box-sizing: border-box; margin: 0; padding: 0; font-family: system-ui, -apple-system, sans-serif; }
body { background: var(--bg); color: var(--text); line-height: 1.5; }
.topbar { display: flex; align-items: center; gap: var(--gap); padding: 12px 16px; background: var(--surface); position: sticky; top: 0; z-index: 100; }
#menuBtn { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text); }
.topbar h1 { flex: 1; font-size: 1.1rem; font-weight: 600; }
.badge { padding: 4px 8px; border-radius: 20px; font-size: 0.75rem; background: #064e3b; color: #34d399; }

#sidebar { position: fixed; left: 0; top: 52px; width: 240px; height: calc(100vh - 52px); background: var(--surface); padding: 16px; transform: translateX(-100%); transition: 0.3s; z-index: 90; overflow-y: auto; }
#sidebar.open { transform: translateX(0); }
.nav-item { display: block; padding: 10px 12px; margin: 4px 0; border-radius: var(--radius); color: var(--text); text-decoration: none; background: transparent; border: none; cursor: pointer; width: 100%; text-align: left; font-size: 0.95rem; }
.nav-item.active, .nav-item:hover { background: rgba(255,255,255,0.08); }
.nav-item.warn { background:#7f1d1d; color:#fecaca; }

.container { padding: 16px; max-width: 100%; }
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--gap); margin: 16px 0; }
.card { background: var(--card-bg); padding: 14px; border-radius: var(--radius); border: 1px solid var(--border); }
.list { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.list-item { background: var(--surface); padding: 10px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
.table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 0.9rem; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 10px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: rgba(255,255,255,0.05); font-weight: 600; }
.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; align-items: center; }
.btn, .btn-event { padding: 10px 16px; border: none; border-radius: var(--radius); background: var(--primary); color: #fff; cursor: pointer; font-weight: 500; min-height: var(--touch); }
.btn-event { flex: 1; background: var(--surface); border: 1px solid var(--border); min-width: 60px; }
.btn-event.active { background: #065f46; border-color: #10b981; }
.btn-event.warn { background: #7c2d12; }
.btn-event.danger { background: #991b1b; }
.btn-sec { background: transparent; border: 1px solid var(--border); padding: 8px 14px; border-radius: var(--radius); color: var(--text); cursor: pointer; min-height: var(--touch); }
.small { padding: 6px 10px; font-size: 0.85rem; min-height: auto; }

.canvas-wrapper { position: relative; aspect-ratio: 16/9; background: #0b1a10; border-radius: var(--radius); overflow: hidden; margin: 12px 0; touch-action: none; }
#pitchCanvas { width: 100%; height: 100%; }
.pitch-footer { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
#matchClock { font-family: monospace; font-size: 1.2rem; background: var(--surface); padding: 6px 12px; border-radius: 8px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal.hidden { display: none; }
.modal-content { background: var(--surface); padding: 20px; border-radius: var(--radius); width: 92%; max-width: 500px; max-height: 85vh; overflow-y: auto; }
.modal-content form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; }
.form-row label { flex: 1; min-width: 120px; display: flex; flex-direction: column; gap: 4px; }
input, select, textarea { background: rgba(255,255,255,0.05); border: 1px solid var(--border); padding: 8px; border-radius: 6px; color: var(--text); width: 100%; }
textarea { resize: vertical; min-height: 60px; }
.hint { font-size: 0.75rem; color: #94a3b8; margin-top: 4px; }

.admin-tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.tab-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 8px 12px; border-radius: 6px; cursor: pointer; }
.tab-btn.active { background: var(--primary); border-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }
.admin-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; background: rgba(255,255,255,0.03); padding: 12px; border-radius: 8px; }

.chart-canvas { width: 100%; height: 250px; background: rgba(255,255,255,0.03); border-radius: 8px; margin: 10px 0; }
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.config-block { margin: 16px 0; padding: 12px; background: rgba(255,255,255,0.05); border-radius: 8px; }

@media (max-width: 768px) {
  #sidebar { width: 100%; }
  .charts-row, .grid, .admin-form { grid-template-columns: 1fr; }
  .controls { flex-direction: column; }
  .btn-event { width: 100%; }
}

:root {
  --bg: #0f111a;
  --panel: #161b28;
  --border: #2a3142;
  --primary: #10b981;
  --warn: #ef4444;
  --text: #e2e8f0;
  --pitch: #1a472a;
  --lines: rgba(255,255,255,0.85);
}

.match-header {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 12px; padding: 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.team-selectors { display: flex; align-items: center; gap: 8px; }
.vs-badge { font-weight: bold; color: var(--warn); }
.match-controls { display: flex; align-items: center; gap: 8px; }
.timer { font-size: 1.5rem; font-family: monospace; color: var(--primary); min-width: 60px; text-align: center; }

.pitch-wrapper {
  position: relative; width: 100%; max-width: 800px; margin: 0 auto; aspect-ratio: 1.5/1;
  background: var(--pitch); border-radius: 8px; overflow: hidden; touch-action: none;
}
#livePitch { width: 100%; height: 100%; display: block; }

.analysis-panel {
  padding: 16px; background: var(--panel); margin-top: 12px; border-radius: 8px;
}
.event-selector { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.evt-btn {
  flex: 1; min-width: 80px; padding: 8px; background: var(--border); border: none;
  color: var(--text); border-radius: 6px; cursor: pointer; transition: 0.2s;
}
.evt-btn.active { background: var(--primary); color: #000; font-weight: bold; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat-card { background: var(--bg); padding: 10px; border-radius: 6px; text-align: center; }
.stat-card h4 { margin: 0 0 4px; font-size: 0.8rem; opacity: 0.7; }
.stat-card span { font-size: 1.2rem; font-weight: bold; color: var(--primary); }
.full-width { width: 100%; margin-top: 8px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: var(--panel); padding: 24px; border-radius: 12px; max-width: 90%; width: 500px; max-height: 80vh; overflow-y: auto; }
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 600px) {
  .match-header { flex-direction: column; align-items: stretch; }
  .team-selectors, .match-controls { justify-content: center; }
  .evt-btn { min-width: 60px; font-size: 0.85rem; }
}

/* CANCHA EN VIVO PROFESIONAL */
.live-match-container {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.match-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--panel-bg, #1e293b);
  border-radius: 12px;
}

.team-selectors {
  display: flex;
  align-items: center;
  gap: 12px;
}

.form-select {
  padding: 8px 16px;
  border: 1px solid var(--border-color, #334155);
  border-radius: 8px;
  background: var(--input-bg, #0f172a);
  color: var(--text-color, #e2e8f0);
  min-width: 150px;
}

.vs-badge {
  font-weight: bold;
  color: #ef4444;
  font-size: 1.2rem;
}

.match-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.timer-display {
  font-size: 1.8rem;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  color: #10b981;
  background: #0f172a;
  padding: 8px 16px;
  border-radius: 8px;
  min-width: 100px;
  text-align: center;
}

.pitch-container {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto 20px;
  aspect-ratio: 1.5/1;
  background: #1a472a;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  touch-action: none;
}

#livePitch {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.event-controls {
  background: var(--panel-bg, #1e293b);
  padding: 20px;
  border-radius: 12px;
}

.event-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.evt-btn {
  flex: 1;
  min-width: 100px;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  background: var(--input-bg, #0f172a);
  color: var(--text-color, #e2e8f0);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.evt-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.evt-btn.active {
  background: #10b981;
  color: #000;
  font-weight: bold;
}

.live-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--input-bg, #0f172a);
  padding: 16px;
  border-radius: 8px;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 8px;
}

.stat-value {
  display: block;
  font-size: 1.8rem;
  font-weight: bold;
  color: #10b981;
}

.analysis-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.full-width {
  flex: 1;
  min-width: 200px;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-success { background: #10b981; color: #000; }
.btn-warning { background: #f59e0b; color: #000; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-primary { background: #3b82f6; color: #fff; }
.btn-secondary { background: #64748b; color: #fff; }

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

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

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: var(--panel-bg, #1e293b);
  padding: 32px;
  border-radius: 16px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content h2 {
  margin: 0 0 24px;
  color: var(--text-color, #e2e8f0);
}

/* Responsive */
@media (max-width: 768px) {
  .match-header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .team-selectors, .match-controls {
    justify-content: center;
  }
  
  .timer-display {
    font-size: 1.4rem;
    min-width: 80px;
  }
  
  .evt-btn {
    min-width: 80px;
    padding: 10px 12px;
    font-size: 0.9rem;
  }
  
  .stat-value {
    font-size: 1.4rem;
  }
  
  .pitch-container {
    aspect-ratio: 1.33/1;
  }
}

/* Cancha en Vivo - Mínimo para que se vea */
.form-select { padding:8px 12px; border:1px solid #334155; border-radius:6px; background:#0f172a; color:#fff; }
.btn-success { background:#10b981; color:#000; border:none; padding:8px 16px; border-radius:6px; cursor:pointer; }
.btn-warning { background:#f59e0b; color:#000; border:none; padding:8px 16px; border-radius:6px; cursor:pointer; }
.btn-danger { background:#ef4444; color:#fff; border:none; padding:8px 16px; border-radius:6px; cursor:pointer; }
.btn-primary { background:#3b82f6; color:#fff; border:none; padding:8px 16px; border-radius:6px; cursor:pointer; }
.btn-secondary { background:#64748b; color:#fff; border:none; padding:8px 16px; border-radius:6px; cursor:pointer; }
.btn:disabled { opacity:0.5; cursor:not-allowed; }
.evt-btn.active { background:#10b981; color:#000; font-weight:bold; }