:root {
  --teal-900: #134E4A;
  --teal-800: #115E59;
  --teal-700: #0F766E;
  --teal-100: #CCFBF1;
  --teal-50: #F0FDFA;
  --coral-600: #EA580C;
  --coral-500: #F97316;
  --coral-50: #FFF7ED;
  --amber-600: #D97706;
  --amber-50: #FFFBEB;
  --danger-700: #B91C1C;
  --danger-600: #DC2626;
  --danger-50: #FEF2F2;
  --success-700: #15803D;
  --success-50: #F0FDF4;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-alt: #F1F5F9;
  --ink: #0F172A;
  --muted: #475569;
  --border: #E2E8F0;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 4px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, 0.1);
}

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

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 {
  font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  margin: 0;
  line-height: 1.25;
}

p {
  margin: 0;
}

code, pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.row-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.row-between {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  min-height: 38px;
  padding: 0.4rem 0.78rem;
  font-size: 0.84rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--teal-700);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--teal-800);
}

.btn-accent {
  background: var(--coral-500);
  color: #fff;
}

.btn-accent:hover:not(:disabled) {
  background: var(--coral-600);
}

.btn-danger {
  background: var(--danger-600);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-700);
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
}

.btn-outline:hover:not(:disabled) {
  background: var(--surface-alt);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.15rem;
  cursor: pointer;
}

/* Formularios */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.58rem 0.78rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.94rem;
}

.field textarea {
  min-height: 90px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.25);
  border-color: var(--teal-700);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
}

.switch-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--teal-700);
  flex-shrink: 0;
}

/* Pills y alertas */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.62rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.pill-teal { background: var(--teal-50); color: var(--teal-800); border: 1px solid #99F6E4; }
.pill-success { background: var(--success-50); color: var(--success-700); border: 1px solid #BBF7D0; }
.pill-warn { background: var(--amber-50); color: var(--amber-600); border: 1px solid #FDE68A; }
.pill-danger { background: var(--danger-50); color: var(--danger-700); border: 1px solid #FECACA; }
.pill-coral { background: var(--coral-50); color: var(--coral-600); border: 1px solid #FED7AA; }
.pill-muted { background: var(--surface-alt); color: var(--muted); border: 1px solid var(--border); }

.alert {
  padding: 0.78rem 0.95rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  border: 1px solid transparent;
}

.alert-danger { background: var(--danger-50); color: var(--danger-700); border-color: #FECACA; }
.alert-warn { background: var(--amber-50); color: #92400E; border-color: #FDE68A; }
.alert-info { background: var(--teal-50); color: var(--teal-900); border-color: #99F6E4; }

/* Login */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: radial-gradient(circle at top right, #CCFBF1 0%, #F8FAFC 52%, #FFF7ED 100%);
}

.login-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.login-brand img {
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.login-notice {
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--teal-700);
}

.login-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
}

/* Shell Admin */
.admin-shell {
  min-height: 100dvh;
  display: flex;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 268px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}

.sidebar.open {
  transform: translateX(0);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 35;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.sidebar-brand img {
  border-radius: 9px;
}

.sidebar-brand strong {
  display: block;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 1.05rem;
}

.sidebar-brand span {
  display: block;
  font-size: 0.76rem;
  color: var(--teal-700);
  font-weight: 700;
}

.sidebar-nav {
  flex: 1;
  padding: 0.85rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.85rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--surface-alt);
}

.nav-item.active {
  background: var(--teal-50);
  color: var(--teal-800);
  border-color: #99F6E4;
}

.sidebar-footer {
  padding: 0.95rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.admin-badge {
  background: var(--surface-alt);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
}

.admin-badge strong {
  display: block;
  font-size: 0.84rem;
  word-break: break-word;
}

.admin-badge span {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--teal-700);
  text-transform: uppercase;
}

.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.15rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.topbar-left h2 {
  font-size: 1.15rem;
}

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

.view-container {
  padding: 1.15rem;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

@media (min-width: 1024px) {
  .mobile-only {
    display: none !important;
  }

  .sidebar {
    position: sticky;
    top: 0;
    height: 100dvh;
    transform: none;
    flex-shrink: 0;
  }

  .view-container {
    padding: 1.5rem 1.75rem;
  }
}

/* Grids y tarjetas */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 1.15rem;
}

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

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.9rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--ink);
}

.kpi-sub {
  font-size: 0.82rem;
  color: var(--muted);
}

.cards-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 820px) {
  .cards-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

/* Barras de cuota Ably */
.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-ok { background: var(--teal-700); }
.progress-warn { background: var(--amber-600); }
.progress-danger { background: var(--danger-600); }

/* Tablas adaptables a móvil */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th {
  text-align: left;
  padding: 0.7rem 0.65rem;
  border-bottom: 2px solid var(--border);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  white-space: nowrap;
}

.data-table td {
  padding: 0.75rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

@media (max-width: 767px) {
  .responsive-table thead {
    display: none;
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.7rem;
    margin-bottom: 0.75rem;
    background: var(--surface);
  }

  .responsive-table td {
    border-bottom: 1px dashed var(--border);
    padding: 0.45rem 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.65rem;
    text-align: right;
  }

  .responsive-table td:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }

  .responsive-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted);
    font-size: 0.78rem;
    text-align: left;
    flex-shrink: 0;
  }
}

/* Sub-pestañas */
.tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.3rem;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.tab-btn {
  min-height: 38px;
  padding: 0.4rem 0.85rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* Modales y Toasts */
.modal-root {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  width: 100%;
  max-width: 580px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.toast-root {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  left: 1rem;
  max-width: 400px;
  margin-left: auto;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  background: var(--ink);
}

.toast-success { background: var(--teal-700); }
.toast-error { background: var(--danger-600); }

.code-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem;
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.loading-box {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

.card-subtle {
  background: var(--surface-alt);
}

.switch-chip {
  flex: 1 1 130px;
}

.field-end {
  justify-content: flex-end;
}

.mt-xs {
  margin-top: 4px;
}

.row-wrap-start {
  margin-top: 4px;
  justify-content: flex-start;
}

.row-wrap-end {
  justify-content: flex-end;
}

.telemetry-status-select {
  min-height: 38px;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
}

.quota-progress {
  display: block;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
}

.quota-progress::-webkit-progress-bar {
  background: var(--surface-alt);
  border-radius: 999px;
}

.quota-progress.progress-ok::-webkit-progress-value {
  background: var(--teal-700);
  border-radius: 999px;
}

.quota-progress.progress-warn::-webkit-progress-value {
  background: var(--amber-600);
  border-radius: 999px;
}

.quota-progress.progress-danger::-webkit-progress-value {
  background: var(--danger-600);
  border-radius: 999px;
}

.quota-progress.progress-ok::-moz-progress-bar {
  background: var(--teal-700);
  border-radius: 999px;
}

.quota-progress.progress-warn::-moz-progress-bar {
  background: var(--amber-600);
  border-radius: 999px;
}

.quota-progress.progress-danger::-moz-progress-bar {
  background: var(--danger-600);
  border-radius: 999px;
}
