:root {
  --text-primary: #e6edf3;
  --bg-dark: #0d1117;
  --bg-med: #161b22;
  --bg-light: #1f2630;
  --border-color: #30363d;
  --accent-primary: #58a6ff;
  --accent-danger: #ff6b6b;
  --radius: 12px;
  --shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
}
.hidden { display: none !important; }
.wrap { max-width: none; width: 100%; padding-inline: clamp(12px, 2.2vw, 40px); margin: 0 auto; }

header { position: sticky; top: 0; z-index: 10; background: rgba(10, 14, 20, .75); border-bottom: 1px solid var(--border-color); backdrop-filter: blur(8px); }
.header-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; gap: 12px; flex-wrap: wrap; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.user-info { display: flex; align-items: center; gap: 12px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--border-color); display: none; }


.toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--border-color) var(--bg-dark); }
.toolbar::-webkit-scrollbar { height: 6px; }
.toolbar::-webkit-scrollbar-track { background: transparent; }
.toolbar::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 10px; }

.button { background: var(--bg-light); border: 1px solid var(--border-color); color: var(--text-primary); border-radius: 10px; padding: 10px 16px; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); cursor: pointer; font-size: 0.95rem; font-weight: 600; line-height: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.button:hover { background: #2c313a; border-color: #4d545d; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.button--primary { background: var(--accent-primary) !important; border-color: var(--accent-primary) !important; color: #0a0d12 !important; }
.button--danger { background: transparent !important; color: var(--accent-danger) !important; border-color: var(--accent-danger) !important; }
.button--danger:hover { background: rgba(255, 107, 107, 0.1) !important; }
.button--icon { background: transparent; border: 1px solid transparent; padding: 4px; border-radius: 6px; font-size: 1.1rem; }
.button--icon:hover { background-color: var(--bg-light); border-color: var(--border-color); }
.button--google { background: #fff; color: #333; border-color: #ddd; width: 100%; font-size: 1rem; padding: 12px; }
.button--google:hover { background: #f7f7f7; }

.ctl { background: var(--bg-dark); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: 10px; padding: 10px 12px; height: 42px; width: 100%; font-size: 1rem; }
.ctl:focus { border-color: var(--accent-primary); box-shadow: 0 0 0 4px rgba(88, 166, 255, .18); outline: none; }

.toolbar .ctl { height: 36px; padding: 6px 10px; font-size: 0.9rem; min-width: 140px; flex: 0 1 auto; width: auto; }
.toolbar .button { height: 36px; padding-top: 6px; padding-bottom: 6px; flex-shrink: 0; }

.content-wrap { padding-block: 10px; }

/* --- NUEVO DISEÑO DEL DASHBOARD --- */
.top-dashboard {
    display: grid;
    grid-template-columns: 1fr; /* Por defecto (móvil) es una sola columna */
    gap: clamp(12px, 1.5vw, 18px);
    margin-bottom: clamp(12px, 1.5vw, 18px);
}
.kpi-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(12px, 1.5vw, 18px);
}
/* A partir de 768px (tablets), cambiamos a una cuadrícula de 2 columnas */
@media(min-width: 768px) {
    .top-dashboard {
        grid-template-columns: 1fr 1fr;
    }
}
/* --- FIN DEL NUEVO DISEÑO --- */

.stat-card { background: var(--bg-med); border: 1px solid var(--border-color); border-radius: 12px; padding: 16px; }
.stat-card .title { opacity: .8; margin: 0 0 6px; font-size: 0.9rem; }
.stat-card .value { font-weight: 700; font-size: clamp(1.2rem, 1.7vw, 1.9rem); margin: 0; }

.card { background: var(--bg-med); border: 1px solid var(--border-color); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.full { grid-column: 1/-1; }
.cardHead { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border-color); flex-wrap: wrap; gap: 1rem;}
.labelPill { font-size: .9rem; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--border-color); background: var(--bg-dark); opacity: .9; }
.card-controls { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.search-box { min-width: 250px; }

.chart-box { height: clamp(240px, 30vh, 460px); padding: 12px; }
.table-wrap { max-height: clamp(360px, 50vh, 720px); overflow: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px; border-bottom: 1px solid var(--border-color); text-align: left; vertical-align: middle; }
.table th:last-child, .table td:last-child { text-align: center; }
.table thead th { border-bottom: 2px solid var(--border-color); background: #0f141b; position: sticky; top: 0; }
.table td:nth-child(3), .table td:nth-child(4) { font-weight: 600; }
.table td:nth-child(8) { font-family: monospace; white-space: nowrap; font-size: .9em; opacity: .8; }
.actions-cell { display: flex; align-items: center; justify-content: center; gap: 4px; }

.auth-view { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: var(--bg-med); border: 1px solid var(--border-color); border-radius: 12px; padding: clamp(16px, 4vw, 32px); width: min(420px, 92vw); }
.login-box h2 { text-align: center; margin-top: 0; }
.row { display: flex; gap: .8rem; align-items: center; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.login-error { color: #ff9aa2; min-height: 1.2em; text-align: center; font-size: 0.9rem; }

.modal { display: none; position: fixed; inset: 0; align-items: center; justify-content: center; background: rgba(0, 0, 0, .6); backdrop-filter: blur(5px); z-index: 1000; }
.modal.show { display: flex; }
.modal-content { background: var(--bg-med); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: var(--radius); width: min(640px, 92vw); max-width: min(920px, 92vw); animation: modal-fade-in .2s ease; }
@keyframes modal-fade-in { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border-color); }
.modal-header h3 { margin: 0; font-size: 1.2rem; }
.modal-close { background: none; border: none; color: var(--text-primary); font-size: 24px; cursor: pointer; line-height: 1; padding: 4px; }

.fieldset-card { border: 1px solid var(--border-color); padding: 12px; border-radius: 10px; }
.fieldset-card legend { font-weight: 600; padding: 0 8px; }
.danger-zone { border-color: var(--accent-danger); }
.danger-zone legend { color: var(--accent-danger); }

.file-input-wrapper { position: relative; overflow: hidden; display: inline-block; text-align: center; }
.file-input-wrapper input[type=file] { font-size: 100px; position: absolute; left: 0; top: 0; opacity: 0; cursor: pointer; }
.file-input-wrapper span { display: block; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }

#toast-container { position: fixed; bottom: 16px; right: 16px; z-index: 2000; }
.toast { background: var(--bg-med); border: 1px solid var(--border-color); border-radius: 10px; padding: 12px 16px; margin-top: 8px; color: var(--text-primary); box-shadow: var(--shadow); animation: toast-fade-in .3s ease; }
@keyframes toast-fade-in { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }

@media (max-width: 900px) {
  body.compact #filters-bar { display: none; }
  body.compact.show-filters #filters-bar { display: flex; flex-direction: column; align-items: stretch; gap: 0.8rem; }
  .toolbar.show-filters .ctl { width: 100%; }
}
@media (min-width: 901px) {
  #btn-filters { display: none; }
  #filters-bar { display: flex !important; }
}

@media (max-width: 600px) {
    .card-controls { width: 100%; justify-content: space-between; }
    .search-box { flex: 1; min-width: 150px; }
}

.button.loading { position: relative; color: transparent !important; pointer-events: none; }
.button.loading::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 1.2em; height: 1.2em;
  margin-top: -0.6em; margin-left: -0.6em;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.button--primary.loading::after { border: 3px solid rgba(13, 17, 23, 0.2); border-top-color: var(--bg-dark); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Estilos para el separador 'o' */
.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--border-color);
  margin: 1.5rem 0;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-color);
}
.divider::before { margin-right: .5em; }
.divider::after { margin-left: .5em; }

.link {
  color: var(--accent-primary);
  text-decoration: none;
  font-size: 0.9rem;
}
.link:hover {
  text-decoration: underline;
}