/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #475569;
  --radius: 8px;
  --gold: #fbbf24;
  --silver: #94a3b8;
  --bronze: #d97706;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.screen { display: none !important; }
.screen.active { display: block !important; }

/* ── Login ── */
#login-screen {
  align-items: center; justify-content: center;
  min-height: 100vh;
}
#login-screen.active { display: flex !important; }

.login-card {
  background: var(--bg-card);
  padding: 2.5rem;
  border-radius: 16px;
  width: 100%; max-width: 400px;
  text-align: center;
  box-shadow: 0 25px 50px rgba(0,0,0,0.4);
}
.login-card h1 { font-size: 2rem; margin-bottom: 0.25rem; }
.subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
.login-card input {
  width: 100%; padding: 0.75rem 1rem; margin-bottom: 0.75rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 1rem;
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.hint { margin-top: 1rem; font-size: 0.8rem; color: var(--text-muted); }
.hint code { background: var(--bg-input); padding: 0.15rem 0.4rem; border-radius: 4px; }
.error-msg { color: var(--danger); margin-top: 0.5rem; font-size: 0.9rem; min-height: 1.2em; }

/* ── Topbar ── */
.topbar {
  background: var(--bg-card);
  padding: 1rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 1.25rem; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }

/* ── Tabs ── */
.tabs {
  display: flex; gap: 0.25rem; padding: 0.75rem 1.5rem;
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  padding: 0.5rem 1rem; border: none; background: transparent;
  color: var(--text-muted); cursor: pointer; border-radius: var(--radius);
  font-size: 0.9rem; white-space: nowrap; transition: all 0.15s;
}
.tab:hover { background: var(--bg-input); color: var(--text); }
.tab.active { background: var(--primary); color: white; }

.tab-content { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }

/* ── Buttons ── */
.btn-primary {
  width: 100%; padding: 0.75rem; background: var(--primary);
  color: white; border: none; border-radius: var(--radius);
  font-size: 1rem; cursor: pointer; transition: background 0.15s;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-sm {
  padding: 0.4rem 0.8rem; border-radius: var(--radius);
  font-size: 0.85rem; cursor: pointer; border: none;
}
.btn-outline {
  background: transparent; border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg-input); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-warning { background: var(--warning); color: #1e293b; }
.btn-warning:hover { opacity: 0.9; }

/* ── Cards ── */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.75rem;
}
.card-title { font-size: 1.1rem; font-weight: 600; }
.card-meta { font-size: 0.85rem; color: var(--text-muted); }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-size: 0.9rem; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.6rem 0.75rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.95rem;
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary);
}
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; }
td { font-size: 0.9rem; }
tr:hover td { background: rgba(99,102,241,0.05); }

/* ── Ranking ── */
.rank-1 { color: var(--gold); font-weight: 700; }
.rank-2 { color: var(--silver); font-weight: 700; }
.rank-3 { color: var(--bronze); font-weight: 700; }
.rank-medal { font-size: 1.2rem; }

/* ── Badges ── */
.badge {
  display: inline-block; padding: 0.2rem 0.5rem;
  border-radius: 12px; font-size: 0.75rem; font-weight: 600;
}
.badge-published { background: var(--success); color: white; }
.badge-scheduled { background: var(--warning); color: #1e293b; }
.badge-submitted { background: var(--primary); color: white; }

/* ── Messages ── */
.message-card { border-left: 3px solid var(--primary); }
.message-card.unread { border-left-color: var(--warning); }
.message-subject { font-weight: 600; }
.message-body { margin-top: 0.5rem; color: var(--text-muted); }
.message-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--bg-card); border-radius: 12px;
  padding: 1.5rem; width: 90%; max-width: 500px;
  max-height: 80vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* ── Timer ── */
.timer { font-family: 'Courier New', monospace; font-size: 1.1rem; color: var(--warning); }
.timer-urgent { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 3rem; color: var(--text-muted); }
.empty-state .icon { font-size: 3rem; margin-bottom: 0.5rem; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .form-row { flex-direction: column; }
  .tabs { padding: 0.5rem; }
  .tab { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
  .tab-content { padding: 1rem; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-stats { grid-template-columns: repeat(3, 1fr); }
}

/* ── Dashboard ── */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  transition: transform 0.15s, border-color 0.15s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-icon { font-size: 1.5rem; margin-bottom: 0.25rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.15rem; }
.stat-warning { border-color: var(--warning); }
.stat-warning .stat-value { color: var(--warning); }
.stat-success { border-color: var(--success); }
.stat-success .stat-value { color: var(--success); }

.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  align-items: start;
}
.dashboard-main, .dashboard-side { min-width: 0; }

.top-three {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.top-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-input);
  border-radius: var(--radius);
}
.top-medal { font-size: 1.5rem; }
.top-name { font-weight: 600; flex: 1; }
.top-group { font-size: 0.8rem; color: var(--text-muted); }
.top-score { font-weight: 700; color: var(--primary); }

/* ── Theme Toggle ── */
.theme-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  font-size: 1rem;
  transition: background 0.15s;
}
.theme-toggle:hover { background: var(--primary); }

/* ── Light Theme ── */
body.light {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #cbd5e1;
}
body.light .login-card { box-shadow: 0 4px 24px rgba(0,0,0,0.08); }
body.light .topbar { border-bottom-color: #e2e8f0; }
body.light .tabs { border-bottom-color: #e2e8f0; }
body.light tr:hover td { background: rgba(99,102,241,0.04); }
body.light .modal-overlay { background: rgba(0,0,0,0.3); }

/* ── File Preview ── */
.file-preview {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  max-height: 400px;
}
.file-preview img {
  width: 100%;
  height: auto;
  display: block;
}
.file-preview iframe {
  width: 100%;
  height: 400px;
  border: none;
}
.file-preview pre {
  margin: 0;
  padding: 1rem;
  background: var(--bg-input);
  overflow: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.file-preview .preview-fallback {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
}

/* ── Export & Chart ── */
.btn-sm {
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-sm:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn-sm.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn-sm.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-sm.btn-outline {
  background: transparent;
  border-color: var(--border);
}
.btn-sm.btn-outline:hover {
  background: var(--bg-input);
  border-color: var(--primary);
}

.historico-chart svg {
  display: block;
  max-width: 100%;
}
.historico-chart polyline {
  transition: opacity 0.2s;
}
.historico-chart polyline:hover {
  opacity: 1 !important;
  stroke-width: 3.5 !important;
}
.historico-chart circle:hover {
  r: 6;
}

/* ── IA Generator Styles ── */
.ia-steps {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ia-step {
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all 0.2s;
}

.ia-step.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.ia-step h3 {
  margin-bottom: 0.75rem;
  font-size: 1.1rem;
}

#ia-prompt-input,
#ia-generated-prompt,
#ia-json-response {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
}

#ia-generated-prompt {
  background: var(--bg);
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
}

#ia-verification-result {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Success state for verification */
#ia-verification-result .form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

#ia-verification-result input,
#ia-verification-result textarea {
  margin-top: 0.25rem;
  padding: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.85rem;
}

#ia-verification-result textarea:focus,
#ia-verification-result input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Responsive */
@media (max-width: 640px) {
  .ia-step h3 {
    font-size: 1rem;
  }
  
  #ia-generated-prompt {
    font-size: 0.7rem;
  }
}

/* ── Badges / Medallas ── */
.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}
.badge-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.badge-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  border-color: var(--primary);
}
.badge-card.badge-category {
  border-color: var(--primary);
  background: linear-gradient(135deg, var(--bg-card), rgba(99,102,241,0.12));
}
.badge-card.badge-locked {
  opacity: 0.4;
  filter: grayscale(0.7);
}
.badge-card.badge-locked:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--border);
}
.badge-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}
.badge-name {
  font-weight: 600;
  font-size: 0.95rem;
}
.badge-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.3;
}
.badge-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-style: italic;
}

/* ── Chat IA ── */
.chat-ia-container {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
.chat-ia-container textarea {
  resize: vertical;
  min-height: 60px !important;
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  line-height: 1.4;
}
.chat-ia-container textarea:focus {
  outline: none;
  border-color: var(--primary);
}
