:root {
  --bg-deep: #0a0d12;
  --bg: #0f131a;
  --surface: #151a23;
  --surface-2: #1b222e;
  --surface-3: #222b3a;
  --surface-hover: #1e2634;
  --line: #252e3d;
  --line-soft: #1c2330;
  --text: #eef2f8;
  --text-dim: #b4bfd0;
  --muted: #7f8ea3;
  --accent: #4fc3f7;
  --accent-strong: #03a9f4;
  --accent-glow: rgba(79, 195, 247, 0.16);
  --ok: #66bb6a;
  --ok-bg: rgba(102, 187, 106, 0.13);
  --warn: #ffb74d;
  --warn-bg: rgba(255, 183, 77, 0.14);
  --danger: #ef5350;
  --danger-bg: rgba(239, 83, 80, 0.14);
  --purple: #ab47bc;
  --pink: #ec407a;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.36);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

body {
  background:
    radial-gradient(ellipse 900px 420px at 50% -120px, rgba(79, 195, 247, 0.09), transparent 70%),
    linear-gradient(180deg, var(--bg-deep) 0%, var(--bg) 260px);
  color: var(--text);
  font: 14px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: #8be0ff;
}

/* --- Barra superior --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(13, 17, 24, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text);
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}

.brand:hover {
  color: var(--text);
}

.brand-mark {
  display: inline-flex;
  align-items: flex-end;
  gap: 2.5px;
  height: 20px;
  padding: 3px 5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.brand-mark span {
  width: 3px;
  border-radius: 2px;
  display: block;
}

.brand-mark span:nth-child(1) { height: 7px; background: #4fc3f7; }
.brand-mark span:nth-child(2) { height: 13px; background: #f06292; }
.brand-mark span:nth-child(3) { height: 10px; background: #ffb74d; }
.brand-mark span:nth-child(4) { height: 14px; background: #81c784; }

.brand-text small {
  font-weight: 500;
  font-size: 0.74rem;
  color: var(--muted);
  margin-left: 0.3rem;
  padding: 0.12rem 0.45rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 99px;
  vertical-align: middle;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.nav-link {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.88rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-link.active {
  color: var(--accent);
  background: var(--accent-glow);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.25rem 0.65rem 0.25rem 0.3rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 0.83rem;
  color: var(--text-dim);
}

.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0288d1, #26c6da);
  color: #06131c;
  font-weight: 700;
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.avatar.lg {
  width: 34px;
  height: 34px;
  font-size: 0.82rem;
}

/* --- Contenedor principal --- */
main, .container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
  flex: 1;
}

/* --- Encabezados de página y migas de pan --- */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 0.45rem;
  flex-wrap: wrap;
}

.breadcrumb a {
  color: var(--text-dim);
}

.breadcrumb a:hover {
  color: var(--accent);
}

.breadcrumb-sep {
  color: var(--muted);
  opacity: 0.6;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.page-subtitle {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 1rem;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.02rem;
  font-weight: 600;
  margin: 0 0 0.85rem;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

h3 {
  font-size: 0.92rem;
  font-weight: 600;
  margin: 1rem 0 0.5rem;
  color: var(--text-dim);
}

/* --- Tarjetas y grillas --- */
.card, section.card {
  background: linear-gradient(180deg, rgba(27, 34, 46, 0.65) 0%, var(--surface) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.2rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.95rem;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.2rem;
  margin-bottom: 1.2rem;
}

.grid-2 > .card {
  margin-bottom: 0;
}

/* --- Tarjetas de métricas (KPIs) --- */
.stats, .stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.stat {
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
  border: 1px solid var(--line);
  border-top: 2px solid rgba(79, 195, 247, 0.45);
  border-radius: var(--radius);
  padding: 0.95rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat.accent-green { border-top-color: var(--ok); }
.stat.accent-amber { border-top-color: var(--warn); }
.stat.accent-purple { border-top-color: var(--purple); }
.stat.accent-pink { border-top-color: var(--pink); }

.stat span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat b {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat small {
  font-size: 0.78rem;
  color: var(--muted);
}

/* --- Tablas --- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th, td {
  text-align: left;
  padding: 0.68rem 0.75rem;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(15, 19, 26, 0.45);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody tr {
  transition: background 0.12s ease;
}

tbody tr:hover {
  background: var(--surface-hover);
}

tbody tr:last-child td {
  border-bottom: none;
}

.num, th.num, td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row-title {
  font-weight: 600;
  color: var(--text);
  display: inline-block;
}

a.row-title {
  color: var(--text);
}

a.row-title:hover {
  color: var(--accent);
}

.row-sub {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

/* --- Formularios, botones y barra de búsqueda --- */
form {
  margin: 0;
}

form.inline, .inline-actions {
  display: inline-flex;
  gap: 0.45rem;
  align-items: center;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem;
  align-items: end;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.toolbar-form {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  flex: 1;
}

.toolbar-form input[type="search"],
.toolbar-form input[type="text"] {
  min-width: 240px;
  flex: 1;
  max-width: 380px;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
}

label > input:not([type="checkbox"]),
label > select {
  display: block;
  width: 100%;
  margin-top: 0.32rem;
}

label.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  color: var(--text);
  font-size: 0.86rem;
  user-select: none;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
select {
  background: var(--bg-deep);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--accent);
  color: #05131d;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

button:hover,
.btn:hover {
  filter: brightness(1.08);
  color: #05131d;
}

button.secondary,
.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--line);
}

button.secondary:hover,
.btn.secondary:hover {
  background: var(--surface-3);
  color: var(--text);
}

button.danger,
.btn.danger {
  background: var(--danger-bg);
  color: #ff8a80;
  border-color: rgba(239, 83, 80, 0.35);
}

button.danger:hover,
.btn.danger:hover {
  background: var(--danger);
  color: #fff;
}

button.sm,
.btn.sm {
  padding: 0.32rem 0.65rem;
  font-size: 0.78rem;
}

/* --- Insignias (Badges), Tonalidades y Stems --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.16rem 0.55rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.badge.ok {
  background: var(--ok-bg);
  color: #81c784;
  border-color: rgba(102, 187, 106, 0.3);
}

.badge.warn {
  background: var(--warn-bg);
  color: #ffb74d;
  border-color: rgba(255, 183, 77, 0.3);
}

.badge.danger {
  background: var(--danger-bg);
  color: #ff8a80;
  border-color: rgba(239, 83, 80, 0.3);
}

.badge.accent {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: rgba(79, 195, 247, 0.35);
}

.key-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.1rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(79, 195, 247, 0.12);
  border: 1px solid rgba(79, 195, 247, 0.28);
  color: #8be0ff;
  font-weight: 700;
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

.bpm-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.14rem 0.48rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.stem-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.2rem 0.58rem;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text);
}

.stem-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.pos-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

/* --- Reproductor de vista previa de audio --- */
.track-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
}

audio.audio-preview {
  height: 28px;
  width: 180px;
  vertical-align: middle;
  border-radius: 6px;
}

/* --- Alertas y mensajes flash --- */
.flash {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1.2rem;
  border: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  font-size: 0.9rem;
}

.flash.ok {
  border-color: rgba(102, 187, 106, 0.45);
  background: rgba(102, 187, 106, 0.11);
  color: #b9f6ca;
}

.flash.error {
  border-color: rgba(239, 83, 80, 0.5);
  background: rgba(239, 83, 80, 0.12);
  color: #ffcdd2;
}

.flash.password-once {
  border-color: rgba(255, 183, 77, 0.55);
  background: rgba(255, 183, 77, 0.12);
  color: #ffe0b2;
  flex-direction: column;
  gap: 0.35rem;
}

code {
  font-family: var(--font-mono);
  background: var(--bg-deep);
  padding: 0.18rem 0.45rem;
  border-radius: 5px;
  border: 1px solid var(--line);
  font-size: 0.84em;
  color: #8be0ff;
}

.muted {
  color: var(--muted);
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

.empty-state p {
  margin: 0.3rem 0;
}

/* --- Pantalla de inicio de sesión --- */
.login-shell {
  min-height: calc(100vh - 110px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}

.login-card {
  width: 100%;
  max-width: 410px;
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 2rem 1.85rem;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.login-brand .brand-mark {
  height: 28px;
  padding: 5px 7px;
  gap: 3px;
}

.login-brand .brand-mark span {
  width: 4px;
}

.login-brand .brand-mark span:nth-child(1) { height: 9px; }
.login-brand .brand-mark span:nth-child(2) { height: 17px; }
.login-brand .brand-mark span:nth-child(3) { height: 13px; }
.login-brand .brand-mark span:nth-child(4) { height: 19px; }

.login-brand-title {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.login-brand-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.login-card h1 {
  font-size: 1.25rem;
  margin: 0 0 0.35rem;
}

.login-card .login-lead {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0 0 1.25rem;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.login-card button[type="submit"] {
  width: 100%;
  padding: 0.62rem 1rem;
  font-size: 0.92rem;
  margin-top: 0.25rem;
}

.security-note {
  margin-top: 1.25rem;
  padding-top: 0.95rem;
  border-top: 1px solid var(--line-soft);
  font-size: 0.76rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

/* --- Pie de página --- */
.footer {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.5rem 1.75rem;
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
}

.error-page {
  max-width: 520px;
  margin: 3rem auto;
  text-align: center;
  padding: 2.2rem 1.8rem;
}

.error-page h1 {
  margin: 0.65rem 0 0.4rem;
}

.error-page .actions {
  margin-top: 1.25rem;
}

@media (max-width: 720px) {
  .topbar-inner {
    padding: 0.65rem 1rem;
  }
  main, .container {
    padding: 1.15rem 1rem 2rem;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  audio.audio-preview {
    width: 140px;
  }
}

/* Enlace secundario debajo de los formularios de acceso (¿Olvidaste tu contraseña?). */
.login-alt { margin: 1rem 0 0; text-align: center; font-size: 0.9rem; }
.login-alt a { color: var(--accent, #4fc3f7); text-decoration: none; font-weight: 600; }
.login-alt a:hover { text-decoration: underline; }
