/* ============================================================
   VPS Monitor — Sistema de diseño
   Dark por defecto. Auto-switch a light con prefers-color-scheme
   o override manual con data-theme en <html>.
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ─── Design tokens ─── */
:root {
  /* Paleta semántica (auto contraste para WCAG AA+) */
  --bg: #0a0f1e;
  --bg-elevated: #111827;
  --bg-subtle: #0d1424;
  --surface: #1e293b;
  --surface-2: #243047;
  --border: #1e293b;
  --border-strong: #334155;

  --text: #f1f5f9;
  --text-muted: #94a3b8;         /* subido desde #64748b: 6:1 ratio sobre bg-elevated */
  --text-dim: #64748b;

  --accent: #8b5cf6;             /* púrpura marca */
  --accent-2: #6366f1;
  --info: #3b82f6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --cyan: #06b6d4;

  --success-bg: rgba(16, 185, 129, 0.12);
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger-bg: rgba(239, 68, 68, 0.12);
  --info-bg: rgba(59, 130, 246, 0.12);
  --accent-bg: rgba(139, 92, 246, 0.14);

  /* Tipografía escalar */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --text-2xs: 0.625rem;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.25rem;
  --text-4xl: 3rem;

  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semi: 600;
  --fw-bold: 700;
  --fw-black: 800;

  /* Espaciado (escala de 4px) */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.25rem;
  --s-6: 1.5rem;
  --s-8: 2rem;
  --s-10: 2.5rem;

  /* Radios */
  --r-sm: 0.5rem;
  --r-md: 0.75rem;
  --r-lg: 1rem;
  --r-xl: 1.25rem;
  --r-full: 9999px;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 24px rgba(139, 92, 246, 0.35);

  /* Transiciones */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

  --duration-fast: 120ms;
  --duration-base: 200ms;
  --duration-slow: 360ms;

  /* Safe area para iOS */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  /* Layout */
  --max-w: 640px;
  --tabbar-h: 56px;
  --header-h: 64px;
}

/* Light mode */
:root[data-theme="light"] {
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --bg-subtle: #f1f5f9;
  --surface: #e2e8f0;
  --surface-2: #cbd5e1;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --success-bg: rgba(16, 185, 129, 0.18);
  --warning-bg: rgba(245, 158, 11, 0.18);
  --danger-bg: rgba(239, 68, 68, 0.18);
  --info-bg: rgba(59, 130, 246, 0.18);
  --accent-bg: rgba(139, 92, 246, 0.14);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
}

/* Auto dark cuando el usuario lo prefiere y no hay override */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f8fafc;
    --bg-elevated: #ffffff;
    --bg-subtle: #f1f5f9;
    --surface: #e2e8f0;
    --surface-2: #cbd5e1;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #475569;
    --text-dim: #64748b;
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.1);
  }
}

/* Respeto por reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--fw-normal);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* ─── Utilities ─── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.fade-in {
  animation: fadeIn var(--duration-slow) var(--ease-out);
}

.slide-up {
  animation: slideUp var(--duration-slow) var(--ease-out);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Focus management ─── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

button:focus:not(:focus-visible) {
  outline: none;
}

/* ─── Layout principal ─── */
.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
}

.app-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: var(--s-4);
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--s-6));
  padding-left: max(var(--s-4), var(--safe-l));
  padding-right: max(var(--s-4), var(--safe-r));
}

/* ─── Header sticky ─── */
.hdr {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  padding-top: calc(var(--s-3) + var(--safe-t));
  padding-left: max(var(--s-4), var(--safe-l));
  padding-right: max(var(--s-4), var(--safe-r));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.hdr-brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.hdr-brand .brand-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.hdr-brand .brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.hdr-brand .brand-title {
  font-size: var(--text-sm);
  font-weight: var(--fw-bold);
  color: var(--text);
}

.hdr-brand .brand-host {
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

.hdr-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn .icon {
  width: 18px;
  height: 18px;
}

/* ─── Tabs (bottom bar mobile) ─── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-b));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  max-width: var(--max-w);
  margin: 0 auto;
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: 0;
  color: var(--text-dim);
  cursor: pointer;
  padding: var(--s-2) 0;
  font-size: var(--text-2xs);
  font-weight: var(--fw-semi);
  transition: color var(--duration-fast) var(--ease-out);
}

.tab-btn .icon {
  width: 22px;
  height: 22px;
  transition: transform var(--duration-base) var(--ease-bounce);
}

.tab-btn[aria-current="page"] {
  color: var(--accent);
}

.tab-btn[aria-current="page"] .icon {
  transform: translateY(-2px) scale(1.1);
}

.tab-btn:focus-visible {
  outline-offset: -3px;
}

/* ─── Tab panels ─── */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn var(--duration-base) var(--ease-out);
}

/* ─── Status hero (Resumen) ─── */
.hero {
  position: relative;
  background: linear-gradient(135deg, var(--bg-elevated), var(--bg-subtle));
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s-5);
  margin-bottom: var(--s-4);
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, var(--accent-bg), transparent 70%);
  pointer-events: none;
}

.hero-content {
  position: relative;
}

.hero-status {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}

.status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.04);
  animation: pulse 2.4s var(--ease-in-out) infinite;
}

.status-dot.ok { background: var(--success); box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2), 0 0 16px rgba(16, 185, 129, 0.5); }
.status-dot.warning { background: var(--warning); box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2), 0 0 16px rgba(245, 158, 11, 0.5); }
.status-dot.critical { background: var(--danger); box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.2), 0 0 16px rgba(239, 68, 68, 0.5); }

.hero-label {
  font-size: var(--text-2xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.hero-title {
  font-size: var(--text-xl);
  font-weight: var(--fw-black);
  line-height: 1.25;
  margin: var(--s-1) 0;
}

.hero-ai {
  font-size: var(--text-sm);
  line-height: 1.55;
  color: var(--text-muted);
  min-height: 2.6em;
}

.hero-meta {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px solid var(--border);
  font-size: var(--text-xs);
  color: var(--text-dim);
  flex-wrap: wrap;
}

.hero-meta .meta-item {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
}

.hero-meta .icon {
  width: 14px;
  height: 14px;
}

/* ─── KPI cards ─── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}

.kpi {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-3);
  position: relative;
  overflow: hidden;
  transition: transform var(--duration-fast) var(--ease-out), border-color var(--duration-base);
}

.kpi:active {
  transform: scale(0.98);
}

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-2);
}

.kpi-label {
  font-size: var(--text-2xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.kpi-icon {
  width: 16px;
  height: 16px;
  color: var(--text-dim);
}

.kpi-value {
  font-size: var(--text-2xl);
  font-weight: var(--fw-black);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--text);
}

.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: var(--text-2xs);
  font-weight: var(--fw-semi);
  padding: 2px 6px;
  border-radius: var(--r-sm);
  margin-top: var(--s-1);
}

.kpi-delta.up { color: var(--danger); background: var(--danger-bg); }
.kpi-delta.down { color: var(--success); background: var(--success-bg); }
.kpi-delta.flat { color: var(--text-dim); background: var(--bg-subtle); }

.kpi-delta .icon { width: 10px; height: 10px; }

.kpi-sub {
  font-size: var(--text-2xs);
  color: var(--text-muted);
  margin-top: var(--s-1);
}

.kpi-bar {
  height: 4px;
  background: var(--bg-subtle);
  border-radius: var(--r-full);
  margin-top: var(--s-2);
  overflow: hidden;
}

.kpi-bar-fill {
  height: 100%;
  border-radius: var(--r-full);
  transition: width var(--duration-slow) var(--ease-out), background var(--duration-base);
}

.kpi.status-ok { border-color: var(--border); }
.kpi.status-ok .kpi-bar-fill { background: var(--success); }
.kpi.status-warning { border-color: color-mix(in srgb, var(--warning) 40%, var(--border)); }
.kpi.status-warning .kpi-bar-fill { background: var(--warning); }
.kpi.status-critical { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.kpi.status-critical .kpi-bar-fill { background: var(--danger); }

/* ─── Section ─── */
.section {
  margin-bottom: var(--s-4);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}

.section-title {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin: 0;
}

.section-title .icon {
  width: 14px;
  height: 14px;
}

.chip-ai {
  font-size: var(--text-2xs);
  font-weight: var(--fw-bold);
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: var(--accent-bg);
  color: var(--accent);
  letter-spacing: 0.04em;
}

/* ─── Card ─── */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
}

.card + .card {
  margin-top: var(--s-3);
}

/* ─── Chart container ─── */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 140px;
  margin-top: var(--s-2);
}

.chart-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-2);
  color: var(--text);
  padding: var(--s-2);
  border-radius: var(--r-sm);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--duration-fast);
  z-index: 5;
  box-shadow: var(--shadow-md);
}

.chart-tooltip.show {
  opacity: 1;
}

.chart-legend {
  display: flex;
  gap: var(--s-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  flex-wrap: wrap;
}

.chart-legend .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* ─── Container grid cards ─── */
.ct-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-3);
}

@media (min-width: 480px) {
  .ct-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.ct-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-3);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  transition: border-color var(--duration-base);
}

.ct-card.status-ok { border-left: 3px solid var(--success); }
.ct-card.status-warning { border-left: 3px solid var(--warning); }
.ct-card.status-critical { border-left: 3px solid var(--danger); }

.ct-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}

.ct-name {
  font-size: var(--text-sm);
  font-weight: var(--fw-bold);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.badge {
  font-size: var(--text-2xs);
  font-weight: var(--fw-bold);
  padding: 2px 8px;
  border-radius: var(--r-full);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-ok { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warning-bg); color: var(--warning); }
.badge-crit { background: var(--danger-bg); color: var(--danger); animation: pulse 1.4s infinite; }

.ct-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2);
  font-size: var(--text-xs);
}

.ct-stat {
  background: var(--bg-subtle);
  padding: var(--s-2);
  border-radius: var(--r-sm);
}

.ct-stat-label {
  font-size: var(--text-2xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ct-stat-value {
  font-size: var(--text-sm);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.ct-actions {
  display: flex;
  gap: var(--s-2);
  margin-top: var(--s-1);
}

/* ─── Services list ─── */
.svc-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--s-2);
}

.svc-item {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  background: var(--bg-subtle);
  border-radius: var(--r-md);
  font-size: var(--text-xs);
  font-weight: var(--fw-semi);
}

.svc-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.svc-item.up .dot { background: var(--success); }
.svc-item.down .dot { background: var(--danger); animation: pulse 1s infinite; }
.svc-item .name { flex: 1; }
.svc-item .state {
  font-size: var(--text-2xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── Prediction list ─── */
.pred-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-2);
}

.pred {
  background: var(--bg-subtle);
  padding: var(--s-3);
  border-radius: var(--r-md);
  text-align: center;
}

.pred-label {
  font-size: var(--text-2xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--s-1);
}

.pred-value {
  font-size: var(--text-base);
  font-weight: var(--fw-bold);
}

.pred.risk-bajo .pred-value { color: var(--success); }
.pred.risk-medio .pred-value { color: var(--warning); }
.pred.risk-alto .pred-value { color: var(--danger); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 44px;
  padding: 0 var(--s-4);
  border-radius: var(--r-md);
  border: 0;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--fw-bold);
  color: var(--text);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  touch-action: manipulation;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn .icon {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-ghost {
  background: var(--bg-subtle);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-success { background: var(--success-bg); color: var(--success); }
.btn-warning { background: var(--warning-bg); color: var(--warning); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-info { background: var(--info-bg); color: var(--info); }

.btn-sm {
  min-height: 32px;
  padding: 0 var(--s-3);
  font-size: var(--text-xs);
}

/* ─── Inputs / selects ─── */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  margin-bottom: var(--s-3);
}

.field-label {
  font-size: var(--text-xs);
  font-weight: var(--fw-semi);
  color: var(--text-muted);
}

.input,
.select {
  width: 100%;
  min-height: 44px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0 var(--s-3);
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--text);
  transition: border-color var(--duration-fast);
  -webkit-appearance: none;
  appearance: none;
}

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

.select {
  padding-right: var(--s-8);
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%2394a3b8" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>');
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
}

.input-group {
  position: relative;
}

.input-group .input {
  padding-right: 44px;
}

.input-group .input-action {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
}

.input-group .input-action:hover { color: var(--text); background: var(--bg-subtle); }

/* ─── Chat ─── */
.chat-scroll {
  background: var(--bg-subtle);
  border-radius: var(--r-lg);
  padding: var(--s-3);
  max-height: 420px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
  scroll-behavior: smooth;
}

.bubble {
  max-width: 85%;
  padding: var(--s-3);
  border-radius: var(--r-lg);
  font-size: var(--text-sm);
  line-height: 1.5;
  position: relative;
  animation: slideUp var(--duration-base) var(--ease-out);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: var(--r-sm);
}

.bubble.ai {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--r-sm);
}

.bubble.ai::before {
  content: "IA";
  position: absolute;
  top: -8px;
  left: 8px;
  background: var(--accent);
  color: white;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: var(--fw-black);
  border-radius: var(--r-sm);
  letter-spacing: 0.04em;
}

.bubble.loading {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: var(--s-3) var(--s-4);
}

.bubble.loading .dots {
  display: inline-flex;
  gap: 4px;
}

.bubble.loading .dots span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: pulse 1.4s infinite;
}

.bubble.loading .dots span:nth-child(2) { animation-delay: 0.2s; }
.bubble.loading .dots span:nth-child(3) { animation-delay: 0.4s; }

.chat-form {
  display: flex;
  gap: var(--s-2);
}

.chat-form .input {
  flex: 1;
}

/* ─── Logs ─── */
.logs-code {
  background: #000;
  color: #a7f3d0;
  border-radius: var(--r-md);
  padding: var(--s-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.55;
  max-height: 280px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre;
  overflow-x: auto;
}

.logs-code .line-err { color: #fca5a5; }
.logs-code .line-warn { color: #fcd34d; }

.ia-box {
  background: linear-gradient(135deg, var(--bg-elevated), color-mix(in srgb, var(--accent) 8%, var(--bg-subtle)));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  border-radius: var(--r-lg);
  padding: var(--s-4);
  margin-bottom: var(--s-3);
  position: relative;
}

.ia-box-title {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  margin-bottom: var(--s-2);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ia-box-title .icon { width: 14px; height: 14px; }

.ia-box-body {
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ─── Terminal-style code block ─── */
.terminal {
  background: #000;
  border-radius: var(--r-lg);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  border: 1px solid var(--border-strong);
}

.terminal-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  background: #0f172a;
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border-strong);
}

.terminal-dots {
  display: inline-flex;
  gap: 6px;
}

.terminal-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.terminal-dots span:nth-child(1) { background: #ef4444; }
.terminal-dots span:nth-child(2) { background: #f59e0b; }
.terminal-dots span:nth-child(3) { background: #10b981; }

.terminal-title {
  font-size: var(--text-2xs);
  color: var(--text-muted);
  font-weight: var(--fw-semi);
  flex: 1;
  text-align: center;
}

.terminal-body {
  padding: var(--s-3);
  max-height: 320px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  color: #67e8f9;
  word-break: break-all;
  white-space: pre-wrap;
  user-select: all;
  -webkit-user-select: all;
}

.terminal-body .tok-cmd { color: #10b981; font-weight: var(--fw-bold); }
.terminal-body .tok-flag { color: #f59e0b; }
.terminal-body .tok-str { color: #e0e7ff; }

/* ─── Skeleton loaders ─── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-subtle) 0%, var(--surface) 50%, var(--bg-subtle) 100%);
  background-size: 800px 100%;
  border-radius: var(--r-sm);
  animation: shimmer 1.6s infinite linear;
  color: transparent;
  user-select: none;
}

.skeleton-line {
  height: 12px;
  margin: 4px 0;
}

.skeleton-line.short { width: 40%; }
.skeleton-line.med { width: 70%; }
.skeleton-line.long { width: 100%; }

/* ─── Empty states ─── */
.empty {
  text-align: center;
  padding: var(--s-6) var(--s-4);
  color: var(--text-muted);
}

.empty .icon {
  width: 36px;
  height: 36px;
  margin: 0 auto var(--s-2);
  color: var(--text-dim);
}

.empty-title {
  font-size: var(--text-base);
  font-weight: var(--fw-semi);
  color: var(--text);
  margin-bottom: var(--s-1);
}

.empty-text {
  font-size: var(--text-sm);
  margin-bottom: var(--s-3);
}

/* ─── Alert banner ─── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3);
  border-radius: var(--r-md);
  margin-bottom: var(--s-3);
  font-size: var(--text-sm);
}

.alert.alert-danger { background: var(--danger-bg); color: #fca5a5; border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.alert.alert-warning { background: var(--warning-bg); color: #fcd34d; border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent); }
.alert.alert-info { background: var(--info-bg); color: #93c5fd; border: 1px solid color-mix(in srgb, var(--info) 30%, transparent); }

.alert .icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 2px; }
.alert-body { flex: 1; }
.alert-title { font-weight: var(--fw-bold); margin-bottom: 2px; }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--s-4));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  max-width: calc(100vw - 32px);
  background: var(--surface-2);
  color: var(--text);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  font-weight: var(--fw-semi);
  z-index: 100;
  transition: transform var(--duration-base) var(--ease-out);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast .icon { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success { color: var(--success); }
.toast.warning { color: var(--warning); }
.toast.danger { color: var(--danger); }

/* ─── Offline banner ─── */
.offline-banner {
  position: fixed;
  top: calc(var(--safe-t) + var(--s-2));
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  background: var(--danger);
  color: white;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  z-index: 50;
  transition: transform var(--duration-base) var(--ease-out);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  box-shadow: var(--shadow-md);
}

.offline-banner.show { transform: translateX(-50%) translateY(0); }

/* ─── Footer ─── */
.footer {
  margin-top: var(--s-6);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: var(--text-2xs);
  color: var(--text-dim);
}

/* ─── Login ─── */
.login-shell {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: var(--s-6);
  padding-top: calc(var(--s-6) + var(--safe-t));
  padding-bottom: calc(var(--s-6) + var(--safe-b));
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s-6);
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin: 0 auto var(--s-3);
  background: var(--accent-bg);
  border-radius: var(--r-xl);
  color: var(--accent);
}

.login-logo .icon { width: 36px; height: 36px; }

.login-title {
  font-size: var(--text-xl);
  font-weight: var(--fw-black);
  text-align: center;
  margin-bottom: 4px;
}

.login-sub {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
  margin-bottom: var(--s-5);
}

.login-err {
  color: var(--danger);
  font-size: var(--text-xs);
  text-align: center;
  min-height: 1.5em;
  margin-top: var(--s-2);
}

/* ─── Theme override buttons ─── */
.theme-toggle .icon.moon { display: none; }
:root[data-theme="light"] .theme-toggle .icon.sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon.moon { display: block; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .theme-toggle .icon.sun { display: none; }
  :root:not([data-theme="dark"]) .theme-toggle .icon.moon { display: block; }
}

/* ─── Breakpoints extra ─── */
@media (max-width: 360px) {
  :root {
    --text-2xl: 1.5rem;
    --text-xl: 1.2rem;
  }
  .kpi-value { font-size: var(--text-xl); }
  .tab-btn { font-size: 9px; }
}

@media (min-width: 640px) {
  .app-scroll {
    padding: var(--s-6);
    padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--s-6));
  }
}

/* ─── Pull-to-refresh hint ─── */
.ptr-hint {
  text-align: center;
  padding: var(--s-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
  transform: translateY(-100%);
  transition: transform var(--duration-base);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
}

.ptr-hint.show { transform: translateY(0); }
.ptr-hint .icon { width: 14px; height: 14px; animation: spin 1s linear infinite; }

/* ─── Scrollbar styling ─── */
.app-scroll::-webkit-scrollbar,
.chat-scroll::-webkit-scrollbar,
.logs-code::-webkit-scrollbar,
.terminal-body::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.app-scroll::-webkit-scrollbar-thumb,
.chat-scroll::-webkit-scrollbar-thumb,
.logs-code::-webkit-scrollbar-thumb,
.terminal-body::-webkit-scrollbar-thumb {
  background: var(--surface-2);
  border-radius: var(--r-full);
}
