:root {
  --sm-primary: #1B84FF;
  --sm-primary-soft: #e8f2ff;
  --sm-ink: #1f2937;
  --sm-muted: #6b7280;
  --sm-line: #e5e7eb;
  --sm-success: #17C653;
  --sm-danger: #f1416c;
  --bg-0: #f8fafc;
  --bg-1: #eef2ff;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --radius: 14px;
  --radius-sm: 10px;
  --player-w: 704px;
  --player-h: 488px;
  --font: "Inter", system-ui, sans-serif;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(135deg, var(--bg-0) 0%, var(--bg-1) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
}

h1, h2, h3 {
  font-family: var(--font);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

a { color: var(--sm-primary); text-decoration: none; }
.muted { color: var(--muted); margin: 0.35rem 0 0; }

/* Typography wordmark (isotipo) */
.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0.55rem;
  text-decoration: none;
  color: inherit;
}
.brand-mark {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--sm-primary);
  font-size: 1.25rem;
  line-height: 1;
}
.brand-mark .accent {
  color: var(--sm-ink);
}
.brand-lg .brand-mark {
  font-size: 2rem;
}
.brand-product {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sm-muted);
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  background: var(--sm-primary-soft);
  color: var(--sm-primary);
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 0.65rem;
  padding: 0.55rem 1rem;
  font: 600 0.9rem var(--font);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--sm-primary);
  border-color: var(--sm-primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.05);
  box-shadow: 0 6px 16px rgba(27, 132, 255, 0.28);
}
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent;
}
.btn-ghost:hover:not(:disabled) {
  border-color: #c7d7fe;
  background: var(--sm-primary-soft);
  color: var(--sm-primary);
}
.btn-ghost.active {
  border-color: var(--sm-primary);
  background: var(--sm-primary-soft);
  color: var(--sm-primary);
}
.btn-danger {
  background: #fff1f3;
  border-color: #f9c5d1;
  color: var(--sm-danger);
}

.alert {
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.alert-error { background: #fff1f3; color: #b42318; border: 1px solid #f9c5d1; }
.alert-ok { background: #e8fff3; color: #0f7a3a; border: 1px solid #b6f0cd; }

/* Login */
.page-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.auth-wrap {
  width: min(480px, 100%);
}
.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-subtitle {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
}
.login-card {
  background: var(--panel);
  border: 1px solid rgba(229, 231, 235, 0.9);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}
.login-form, .admin-form {
  display: grid;
  gap: 1rem;
}
.login-form label, .admin-form label, .inline-form label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--sm-ink);
}
input, select {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: #f1f3f8;
  color: var(--text);
  padding: 0.8rem 0.9rem;
  font: 1rem var(--font);
}
input::placeholder { color: #9ca3af; }
input:focus, select:focus {
  outline: none;
  border-color: #b6d4fe;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(27, 132, 255, 0.15);
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid rgba(229, 231, 235, 0.9);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.topbar-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--sm-ink);
}
.topbar-divider {
  width: 1px;
  height: 1.1rem;
  background: var(--line);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.user-chip {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  margin-right: 0.25rem;
}

/* Home */
.home-layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 1.25rem;
  padding: 1.25rem;
  min-height: calc(100vh - 74px);
}
.channel-panel, .player-panel, .admin-card {
  background: var(--panel);
  border: 1px solid rgba(229, 231, 235, 0.95);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.channel-list {
  list-style: none;
  margin: 1.25rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}
.channel-btn {
  width: 100%;
  text-align: left;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.85rem 1rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font: 600 0.95rem var(--font);
}
.channel-btn:hover {
  border-color: #b6d4fe;
  background: var(--sm-primary-soft);
}
.channel-btn.active {
  border-color: var(--sm-primary);
  background: var(--sm-primary-soft);
  box-shadow: inset 0 0 0 1px rgba(27, 132, 255, 0.2);
}
.badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
}
.badge-live {
  background: rgba(23, 198, 83, 0.12);
  color: #0f7a3a;
}
.badge-off {
  background: #f3f4f6;
  color: var(--muted);
}

.player-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.player-stage {
  display: grid;
  place-items: center;
  min-height: 320px;
}
.player-shell {
  width: var(--player-w);
  height: var(--player-h);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #0b1220;
  border: 1px solid var(--line);
  position: relative;
  box-shadow: var(--shadow);
}
.player-shell.is-empty #player { display: none; }
.player-shell:not(.is-empty) #player-placeholder { display: none; }
#player, .op-wrapper, .op-ratio, video {
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
}
.player-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #94a3b8;
  letter-spacing: 0.08em;
  font-size: 0.85rem;
}

.admin-layout {
  padding: 1.25rem;
  display: grid;
  gap: 1.25rem;
  max-width: 980px;
}
.admin-form {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: end;
}
.users-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}
.users-table th, .users-table td {
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 0.4rem;
  text-align: left;
  vertical-align: top;
  font-size: 0.92rem;
}
.actions-cell {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.inline-form {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}
.inline-form input {
  width: auto;
  min-width: 140px;
}

@media (max-width: 860px) {
  .home-layout {
    grid-template-columns: 1fr;
  }
}

/* Monitor (admin) */
.monitor-layout {
  padding: 1.25rem;
}
.monitor-hint {
  margin: 0 0 1rem;
}
.monitor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}
.monitor-card {
  background: var(--panel);
  border: 1px solid rgba(229, 231, 235, 0.95);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.monitor-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.monitor-player-shell {
  position: relative;
  aspect-ratio: 16 / 11;
  background: #0b1220;
}
.monitor-player-shell .op-wrapper,
.monitor-player-shell .op-ratio,
.monitor-player-shell video,
.monitor-player-shell > div:first-child {
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
}
.monitor-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #94a3b8;
  letter-spacing: 0.06em;
  font-size: 0.85rem;
  background: #0b1220;
}

.login-links {
  display: grid;
  gap: 0.4rem;
  margin-top: 1.15rem;
  text-align: center;
}
.login-links a {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
}
.login-links a:hover {
  color: #1B84FF;
  text-decoration: underline;
}
