/* Design system del dashboard del agente */

:root {
  --bg: #0f172a;
  --bg-2: #0b1220;
  --panel: #1e293b;
  --panel-2: #111827;
  --border: #334155;
  --border-2: #475569;
  --text: #e2e8f0;
  --text-dim: #cbd5e1;
  --muted: #94a3b8;

  --primary: #10b981;
  --primary-dark: #059669;
  --primary-light: #34d399;
  --info: #3b82f6;
  --warn: #f59e0b;
  --danger: #ef4444;
  --success: #22c55e;

  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-light); }

/* === SHELL === */
.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand {
  padding: 1.1rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.sidebar-brand .logo { font-size: 1.6rem; }
.sidebar-brand h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}
.sidebar-brand .tag {
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.88rem;
  cursor: pointer;
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active {
  background: var(--primary);
  color: white;
}
.nav-icon { width: 1.2em; text-align: center; }

/* Separador visual antes de las páginas SaaS (solo superadmin) */
.nav a.nav-saas:first-of-type,
.nav a.nav-saas + .nav a:not(.nav-saas) { }
.nav a.nav-saas {
  position: relative;
}
.nav a.nav-saas::before {
  content: "";
  position: absolute;
  left: 0.5rem;
  right: 0.5rem;
  top: -0.15rem;
  height: 1px;
  background: var(--border);
  opacity: 0;
}
/* Aplicamos el separador solo al primer item SaaS, no a todos */
.nav a:not(.nav-saas) + .nav a.nav-saas::before {
  opacity: 1;
}

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.sidebar-footer .footer-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.sidebar-footer .footer-logout {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.55rem;
  font-size: 0.7rem;
  cursor: pointer;
  font-family: inherit;
}
.sidebar-footer .footer-logout:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

/* === TIPOGRAFÍA === */
.page-title {
  margin: 0 0 0.2rem;
  font-size: 1.35rem;
  font-weight: 600;
}
.page-subtitle {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.muted { color: var(--muted); }
.text-right { text-align: right; }
.text-mono { font-family: "JetBrains Mono", "Courier New", monospace; font-size: 0.85em; }

/* === LAYOUT HELPERS === */
.row { display: flex; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* === TOOLBAR === */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

/* === CARD === */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.card-header {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.9rem;
}
.card-body { padding: 1rem; }

/* === FORMS === */
.input, .select, .textarea {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.65rem;
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  min-width: 0;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
}
.textarea { resize: vertical; min-height: 60px; }

/* === BUTTONS === */
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  font-weight: 600;
}
.btn--primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: white; }

.btn--ghost {
  background: transparent;
}

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
.btn--danger:hover { background: #dc2626; border-color: #dc2626; color: white; }

.btn--small {
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
}

/* === BADGES === */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--panel-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.badge--success { background: rgba(34, 197, 94, 0.15); color: #4ade80; border-color: rgba(34, 197, 94, 0.4); }
.badge--info { background: rgba(59, 130, 246, 0.15); color: #60a5fa; border-color: rgba(59, 130, 246, 0.4); }
.badge--warn { background: rgba(245, 158, 11, 0.18); color: #fbbf24; border-color: rgba(245, 158, 11, 0.4); }
.badge--danger { background: rgba(239, 68, 68, 0.15); color: #f87171; border-color: rgba(239, 68, 68, 0.4); }
.badge--muted { background: var(--panel-2); color: var(--muted); border-color: var(--border); }

/* === TABLES === */
.scroll-x { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.table th, .table td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 1;
}
.table tbody tr {
  cursor: default;
  transition: background 0.1s;
}
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--panel-2); }

/* === EMPTY / SPINNER === */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}
.empty-state .icon { font-size: 2.2rem; margin-bottom: 0.4rem; }

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.spinner-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2.5rem;
}

/* === METRICS === */
.metric {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
  margin: 0.2rem 0;
}
.metric-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.metric-card.success { border-left: 3px solid var(--success); }
.metric-card.info { border-left: 3px solid var(--info); }
.metric-card.warn { border-left: 3px solid var(--warn); }
.metric-card.danger { border-left: 3px solid var(--danger); }

/* === MODAL === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 1rem;
}
.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal-header {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body { padding: 1rem; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.85rem;
  box-shadow: 0 12px 28px rgba(0,0,0,0.45);
  z-index: 200;
  animation: toast-in 0.18s ease-out;
  max-width: 360px;
}
.toast--success { border-color: rgba(34,197,94,0.5); }
.toast--danger { border-color: rgba(239,68,68,0.5); color: #fecaca; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === LINKS de teléfono === */
.tel-link {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85em;
  color: var(--primary-light);
  text-decoration: none;
}
.tel-link:hover { text-decoration: underline; }

/* === Responsive sidebar === */
@media (max-width: 800px) {
  .shell { grid-template-columns: 60px 1fr; }
  .sidebar-brand h1, .sidebar-brand .tag, .nav a span.label, .sidebar-footer { display: none; }
  .nav a { justify-content: center; padding: 0.7rem; }
}
