/* =====================================================================
   UTILIA · Panel web
   Mobile-first, Comfortaa, paleta UTILIA con degradado azul.
   Diseñado para alto contraste (WCAG AA) y respeto de prefers-reduced-motion.
   ===================================================================== */

/* `[hidden]` debe forzar ocultacion sobre cualquier `display: flex/grid` definido
   por clases concretas. Sin esta regla, modales y screens se ven aunque tengan
   el atributo `hidden` en el HTML. */
[hidden] { display: none !important; }

/* Foco visible accesible (ring blanco discreto estilo Vercel) */
:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible,
.tab:focus-visible,
.chip:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

:root {
  /* Marca UTILIA (usar solo como acento puntual) */
  --brand-700: #004C99;
  --brand-600: #0066CC;
  --brand-500: #0095FF;
  --brand-400: #00B4D8;
  --brand-grad: linear-gradient(135deg, #0066CC 0%, #0095FF 55%, #00B4D8 100%);

  /* Superficies casi monocromas, estilo minimalista */
  --bg-0:   #000000;
  --bg-1:   #0a0a0a;
  --bg-2:   #111111;
  --bg-3:   #161616;
  --bg-elev:#0f0f0f;

  /* Bordes muy sutiles, 1px alto contraste sobre negro */
  --border:       #262626;
  --border-soft:  #1a1a1a;
  --border-strong:#404040;
  --border-focus: var(--brand-500);

  /* Texto neutro de alto contraste */
  --text:          #fafafa;
  --text-2:        #d4d4d4;
  --muted:         #a3a3a3;
  --muted-strong:  #d4d4d4;

  /* Semánticos */
  --ok:      #34d399;
  --warn:    #fbbf24;
  --danger:  #f87171;
  --inst:    #c4b5fd;

  /* Tipografía: Inter para cuerpo (estilo Vercel), Comfortaa solo en marca */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --font-brand: "Comfortaa", "Inter", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Geist Mono", Menlo, Consolas, monospace;

  /* Escala tipográfica */
  --fs-11: 11px; --fs-12: 12px; --fs-13: 13px; --fs-14: 14px;
  --fs-15: 15px; --fs-17: 17px; --fs-20: 20px; --fs-24: 24px;
  --fs-36: 36px; --fs-56: 56px;

  /* Espaciado escala 4 */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  /* Radii minimalistas */
  --radius-sm:   6px;
  --radius:      8px;
  --radius-lg:   12px;
  --radius-pill: 999px;

  /* Sombras casi imperceptibles (solo en elementos elevados) */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
  --shadow:    0 4px 16px rgba(0,0,0,.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.6);

  /* Transiciones */
  --t-fast: 100ms ease;
  --t:      150ms ease;
  --t-slow: 240ms ease;

  /* Layout */
  --topbar-h:    56px;
  --bottombar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);

  /* Alias retrocompatibles */
  --accent: var(--brand-500);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-14);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: contain;
  letter-spacing: -0.005em;
}
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select {
  background: var(--bg-1);
  border: 1px solid var(--border);
  color: var(--text);
}
a { color: var(--text); text-decoration: none; }
a:hover { color: var(--brand-500); }
code {
  font-family: var(--mono);
  background: var(--bg-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
  color: var(--text-2);
  border: 1px solid var(--border-soft);
}

/* =====================================================================
   Layout principal
   ===================================================================== */

.screen { min-height: 100%; }

#screen-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  height: var(--topbar-h);
  padding: 0 var(--s-4);
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}
.topbar-info { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn-active { background: var(--bg-2); border-color: var(--border); color: var(--text); }
.topbar-label {
  font-size: var(--fs-11);
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.topbar-info strong {
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--text);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  display: grid; place-items: center;
  font-size: var(--fs-17);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  color: var(--muted);
}
.icon-btn:hover, .icon-btn:active {
  background: var(--bg-2);
  border-color: var(--border-soft);
  color: var(--text);
}

#content {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-5) var(--s-4) calc(var(--bottombar-h) + var(--safe-bottom) + 96px);
}

/* =====================================================================
   Headers y chips
   ===================================================================== */

.section-head {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.section-head h2 {
  margin: 0;
  font-size: var(--fs-20);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}
.section-sub {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-13);
  line-height: 1.5;
}
.filter-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  min-height: 28px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: var(--fs-12);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip-active {
  background: var(--text);
  color: var(--bg-0);
  border-color: var(--text);
}

/* =====================================================================
   Cards
   ===================================================================== */

.card-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.card {
  background: var(--bg-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: var(--s-4);
  position: relative;
  transition: border-color var(--t-fast);
}
.card:hover { border-color: var(--border); }
.card-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-bottom: var(--s-2);
}
.card-title {
  margin: 0;
  font-size: var(--fs-14);
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  flex: 1;
  letter-spacing: -0.005em;
}
.card-meta {
  margin: var(--s-1) 0 0;
  color: var(--muted);
  font-size: var(--fs-12);
  line-height: 1.5;
}
.card-body {
  margin-top: var(--s-2);
  color: var(--text-2);
  font-size: var(--fs-13);
  line-height: 1.6;
}
.card-body strong { color: var(--text); font-weight: 600; }
.card-actions {
  margin-top: var(--s-3);
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
}
.card-empty {
  text-align: center;
  padding: var(--s-12) var(--s-4) var(--s-10);
  color: var(--muted);
  font-size: var(--fs-13);
}
.card-empty-glyph {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--bg-2);
  display: grid; place-items: center;
  font-size: 20px;
  color: var(--muted);
  margin: 0 auto var(--s-4);
  border: 1px solid var(--border-soft);
}

/* Etiquetas de scope */
.scope-label {
  margin: var(--s-5) 0 var(--s-2);
  font-size: var(--fs-11);
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  padding: 0 var(--s-1);
}
.scope-label:first-child { margin-top: 0; }

/* =====================================================================
   Tags / pills
   ===================================================================== */

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-11);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  background: var(--bg-2);
  color: var(--muted-strong);
  border: 1px solid var(--border-soft);
}
.tag-block       { background: transparent; color: var(--danger); border-color: rgba(248, 113, 113, 0.3); }
.tag-allow       { background: transparent; color: var(--ok);     border-color: rgba(52, 211, 153, 0.3); }
.tag-instruction { background: transparent; color: var(--inst);   border-color: rgba(196, 181, 253, 0.3); }
.tag-note        { background: transparent; color: var(--muted);  border-color: var(--border-soft); }
.tag-status-pending   { background: transparent; color: var(--warn);  border-color: rgba(251, 191, 36, 0.3); }
.tag-status-applied   { background: transparent; color: var(--ok);    border-color: rgba(52, 211, 153, 0.3); }
.tag-status-dismissed { background: transparent; color: var(--muted); border-color: var(--border-soft); }
.tag-success     { background: transparent; color: var(--ok);     border-color: rgba(52, 211, 153, 0.3); }
.tag-fail        { background: transparent; color: var(--danger); border-color: rgba(248, 113, 113, 0.3); }
.tag-inactive    { background: var(--bg-2); color: var(--muted); }

.match-preview {
  margin-top: var(--s-2);
  padding: 6px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: var(--fs-12);
  color: var(--text-2);
  word-break: break-word;
}

/* =====================================================================
   Botones
   ===================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 6px 14px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-13);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  text-align: center;
  letter-spacing: 0;
}
.btn:hover { background: var(--bg-2); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg-0);
  font-weight: 600;
}
.btn-primary:hover { background: var(--text-2); border-color: var(--text-2); color: var(--bg-0); }

.btn-ok      { background: var(--ok); border-color: var(--ok); color: #052e1c; font-weight: 600; }
.btn-ok:hover{ background: var(--ok); border-color: var(--ok); filter: brightness(1.1); }
.btn-danger  { background: transparent; border-color: var(--border); color: var(--danger); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.06); border-color: rgba(248, 113, 113, 0.4); }
.btn-ghost   { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }

.btn-block { width: 100%; }
.btn-sm { padding: 4px 10px; min-height: 30px; font-size: var(--fs-12); }
.btn-lg { min-height: 44px; font-size: var(--fs-14); padding: 10px 16px; }

/* =====================================================================
   Bottom navigation
   ===================================================================== */

.bottombar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-soft);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--bottombar-h) + var(--safe-bottom));
}
.tab {
  background: transparent;
  border: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-family: var(--font);
  font-size: var(--fs-11);
  font-weight: 500;
  cursor: pointer;
  padding: 0 4px;
  position: relative;
  min-height: 48px;
  transition: color var(--t-fast);
}
.tab::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 24px;
  height: 2px;
  background: var(--text);
  transition: transform var(--t-fast);
  transform-origin: center;
}
.tab-active::before { transform: translateX(-50%) scaleX(1); }
.tab-glyph {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  font-size: var(--fs-15);
  font-weight: 500;
  color: inherit;
  transition: none;
}
.tab-active { color: var(--text); }
.tab-active .tab-glyph { color: var(--text); }
.tab-label {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--danger);
  color: var(--bg-0);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

/* =====================================================================
   FAB (floating action button)
   ===================================================================== */

.fab {
  position: fixed;
  right: var(--s-4);
  bottom: calc(var(--bottombar-h) + var(--safe-bottom) + var(--s-3));
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--text);
  color: var(--bg-0);
  font-family: var(--font);
  font-size: 24px;
  font-weight: 400;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
  display: grid; place-items: center;
  z-index: 6;
  line-height: 1;
  transition: transform var(--t-fast), background var(--t-fast);
}
.fab:hover { background: var(--text-2); }
.fab:active { transform: scale(0.95); }

/* =====================================================================
   Sheet (modal mobile)
   ===================================================================== */

.sheet {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
}
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.75);
  animation: fadein 0.15s ease-out;
}
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg-1);
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--border);
  border-bottom: 0;
  padding: var(--s-3) var(--s-5) calc(var(--s-5) + var(--safe-bottom));
  max-height: 85vh;
  display: flex; flex-direction: column;
  animation: slideup 0.2s ease-out;
}
.sheet-panel::before {
  content: '';
  display: block;
  width: 32px;
  height: 3px;
  border-radius: var(--radius-pill);
  background: var(--border);
  margin: 0 auto var(--s-3);
}
@media (min-width: 720px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: var(--radius-lg); max-height: 80vh; margin-bottom: 0; border-bottom: 1px solid var(--border); }
  .sheet-panel::before { display: none; }
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: 0 0 var(--s-3);
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: var(--s-4);
}
.sheet-head h3 { margin: 0; font-size: var(--fs-15); font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--s-1);
}

@keyframes fadein  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* =====================================================================
   Form fields
   ===================================================================== */

.field {
  display: block;
  margin-bottom: var(--s-3);
}
.field-label {
  display: block;
  font-size: var(--fs-12);
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 6px;
}
.field-input, .field-select, .field-textarea {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-13);
  outline: 0;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field-input::placeholder, .field-textarea::placeholder { color: var(--muted); opacity: 1; }
.field-textarea { height: auto; resize: vertical; min-height: 80px; padding: 10px 12px; line-height: 1.55; }
.field-input:focus, .field-select:focus, .field-textarea:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}
/* Autofill de WebKit/Chromium */
.field-input:-webkit-autofill,
.field-input:-webkit-autofill:hover,
.field-input:-webkit-autofill:focus,
.field-input:-webkit-autofill:active {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-1) inset;
  caret-color: var(--text);
  transition: background-color 9999s ease-in-out 0s;
}
.field-hint { display: block; font-size: var(--fs-12); color: var(--muted); margin-top: 6px; line-height: 1.4; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }

.radio-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.radio-row input { position: absolute; opacity: 0; pointer-events: none; }
.radio-row label {
  display: block;
  text-align: center;
  padding: 8px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-12);
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  min-height: 32px;
  transition: all var(--t-fast);
}
.radio-row label:hover { color: var(--text); border-color: var(--border-strong); }
.radio-row input:checked + label {
  background: var(--text);
  color: var(--bg-0);
  border-color: var(--text);
  font-weight: 600;
}

/* =====================================================================
   Setup wizard (onboarding inicial)
   ===================================================================== */

#screen-setup {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(var(--s-10), var(--safe-top)) var(--s-5) var(--s-8);
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-0);
}
.setup-wrap {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
}
.setup-hero { text-align: center; }
.setup-sub  {
  margin: var(--s-3) 0 0;
  color: var(--muted);
  font-size: var(--fs-13);
}

.stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.stepper .step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  padding: 6px 0;
  border-top: 1px solid var(--border-soft);
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stepper .step span {
  width: 16px; height: 16px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 10px;
  font-weight: 600;
  background: var(--bg-2);
  color: var(--muted);
  border: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.stepper .step-active { color: var(--text); border-top-color: var(--text); }
.stepper .step-active span { background: var(--text); color: var(--bg-0); border-color: var(--text); }
.stepper .step-done { color: var(--text-2); border-top-color: var(--border); }
.stepper .step-done span { background: transparent; color: var(--text-2); border-color: var(--border); }

.setup-card {
  background: transparent;
  border: 0;
  padding: 0;
}
.setup-step { display: flex; flex-direction: column; gap: var(--s-3); }
.setup-step-title {
  margin: 0;
  font-size: var(--fs-20);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}
.setup-step-sub {
  margin: 0 0 var(--s-3);
  color: var(--muted);
  font-size: var(--fs-13);
  line-height: 1.55;
}
.setup-optional {
  font-size: var(--fs-11);
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
  margin-left: 6px;
  padding: 1px 6px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  vertical-align: 2px;
}
.setup-error {
  margin: 0;
  color: var(--danger);
  font-size: var(--fs-12);
}
.setup-actions {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  margin-top: var(--s-3);
  flex-wrap: wrap;
}
.setup-actions .btn { min-width: 120px; }

.token-box {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 10px 12px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.token-box code {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 0;
  font-family: var(--mono);
  font-size: var(--fs-12);
  color: var(--text);
  word-break: break-all;
  overflow-wrap: anywhere;
}

@media (max-width: 480px) {
  .stepper .step { font-size: 0; gap: 0; }
  .stepper .step span { font-size: 10px; }
}

/* =====================================================================
   Login (pantalla de entrada · minimalista)
   ===================================================================== */

#screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(var(--s-8), var(--safe-top)) var(--s-5) var(--s-8);
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-0);
}
.login-wrap {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.login-hero {
  text-align: center;
  margin-bottom: var(--s-8);
}
.login-title {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  color: var(--text);
}
.login-bar { display: none; }
.login-sub {
  margin: var(--s-3) 0 0;
  color: var(--muted);
  font-size: var(--fs-13);
  font-weight: 400;
}
.login-card {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  position: relative;
}
.login-card .field { margin-bottom: var(--s-4); }
.login-card .field-label {
  font-size: var(--fs-13);
  letter-spacing: 0;
  text-transform: none;
  font-weight: 500;
  color: var(--muted);
}
.login-card .field-input {
  height: 40px;
  font-size: var(--fs-14);
}
.login-error {
  margin: var(--s-3) 0 0;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--danger);
  font-size: var(--fs-13);
  font-weight: 500;
  text-align: center;
}
.login-hint {
  margin: var(--s-5) 0 0;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: var(--fs-12);
  line-height: 1.5;
  text-align: center;
}
.login-hint code {
  background: var(--bg-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: var(--fs-12);
  color: var(--text);
}

/* Viewport corto (teclado virtual abierto en móvil, ventana baja en escritorio):
   compactamos el hero para que el card de login siempre quede visible. */
@media (max-height: 640px) {
  #screen-login {
    align-items: flex-start;
    padding-top: var(--s-5);
  }
  .login-title { font-size: 40px; }
  .login-hero { margin-bottom: var(--s-4); }
  .login-card { padding: var(--s-5) var(--s-5); }
  .login-card .field { margin-bottom: var(--s-3); }
  .login-hint { display: none; }
}


/* =====================================================================
   Ajustes (key-value)
   ===================================================================== */

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px var(--s-4);
  font-size: var(--fs-13);
}
.kv dt { color: var(--muted); font-weight: 400; }
.kv dd { margin: 0; text-align: right; font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }

/* =====================================================================
   Telegram (card de Ajustes y modal de pairing)
   ===================================================================== */

.telegram-row {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
}
.telegram-row + .card-actions { margin-top: var(--s-3); }
.telegram-dot {
  flex-shrink: 0;
  width: 8px; height: 8px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--muted);
}
.telegram-on .telegram-dot   { background: var(--ok); }
.telegram-pending .telegram-dot { background: var(--brand-500); }
.telegram-warn .telegram-dot { background: var(--warn); }
.telegram-off .telegram-dot  { background: var(--muted); }
.telegram-text { min-width: 0; }
.telegram-text strong { display: block; color: var(--text); font-size: var(--fs-14); font-weight: 600; margin-bottom: 4px; letter-spacing: -0.005em; }
.telegram-text p { margin: 0; }
.code-block {
  margin: var(--s-2) 0 0;
  padding: 8px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: var(--fs-12);
  color: var(--text);
  overflow-x: auto;
  white-space: pre;
}

.pair-wrap { display: flex; flex-direction: column; gap: var(--s-4); }
.pair-steps {
  margin: 0;
  padding: 0 0 0 18px;
  color: var(--text-2);
  font-size: var(--fs-13);
  line-height: 1.6;
}
.pair-steps li { margin-bottom: 4px; }
.pair-steps li::marker { color: var(--muted); font-weight: 500; }
.pair-qr {
  background: #ffffff;
  padding: 14px;
  border-radius: var(--radius);
  align-self: center;
  border: 1px solid var(--border);
}
.pair-qr img { width: 220px; height: 220px; display: block; }
.pair-fallback summary {
  cursor: pointer;
  font-size: var(--fs-12);
  color: var(--muted);
  padding: 6px 0;
  list-style: none;
}
.pair-fallback summary::-webkit-details-marker { display: none; }
.pair-fallback summary::before { content: '+ '; }
.pair-fallback[open] summary::before { content: '− '; }
.pair-fallback summary:hover { color: var(--text); }
.pair-link a { color: var(--text-2); word-break: break-all; font-size: var(--fs-12); text-decoration: underline; }
.pair-code {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 3px;
  margin: 4px 0;
  color: var(--text);
}
.pair-result { font-weight: 600; }
.pair-result.pair-ok { color: var(--ok); }
.pair-result.pair-fail { color: var(--danger); }

/* =====================================================================
   Toast
   ===================================================================== */

.toast {
  position: fixed;
  bottom: calc(var(--bottombar-h) + var(--safe-bottom) + var(--s-4));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-1);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-13);
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 20;
  animation: toastin 0.18s ease-out;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast-ok::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-right: 8px; vertical-align: middle; }
.toast-err { color: var(--danger); }
.toast-err::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--danger); margin-right: 8px; vertical-align: middle; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Spinner unico para todo el sitio */
.pair-wait {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-13);
  color: var(--muted);
  padding: var(--s-2) 0;
}
.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================================
   Skeleton loaders
   ===================================================================== */

.skeleton-card { opacity: 0.55; }
.skeleton {
  display: block;
  background: linear-gradient(90deg, var(--bg-2) 0%, var(--bg-3) 50%, var(--bg-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 4px;
}
.skeleton-line { height: 12px; margin: 8px 0; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* =====================================================================
   Anim utilities
   ===================================================================== */

.fade-in { animation: fadein 0.15s ease-out; }
.view { animation: fadein 0.15s ease-out; }

/* =====================================================================
   Vista Inicio (home)
   ===================================================================== */

.home-hero {
  margin-bottom: var(--s-6);
}
.home-greeting {
  margin: 0;
  font-size: var(--fs-24);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}
.home-sub {
  margin: var(--s-2) 0 0;
  color: var(--muted);
  font-size: var(--fs-13);
  line-height: 1.5;
}

.home-block { margin-bottom: var(--s-6); }
.home-block:last-child { margin-bottom: 0; }
.home-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}
.home-block-title {
  margin: 0;
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--muted-strong);
  letter-spacing: 0;
}
.home-block-link {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--muted);
  font-family: var(--font);
  font-size: var(--fs-12);
  font-weight: 500;
  cursor: pointer;
  transition: color var(--t-fast);
}
.home-block-link:hover { color: var(--text); }

.home-msg-card { padding: var(--s-3) var(--s-4); }
.home-msg-text {
  margin: 0 0 var(--s-2);
  color: var(--text);
  font-size: var(--fs-14);
  font-weight: 500;
  line-height: 1.5;
}
.home-msg-meta {
  color: var(--muted);
  font-size: var(--fs-12);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}
.home-msg-meta .dot-sep { padding: 0 4px; opacity: 0.6; }

.home-empty-mini {
  color: var(--muted);
  font-size: var(--fs-13);
  padding: var(--s-3) var(--s-1);
  line-height: 1.5;
}
.home-inline-btn {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font: inherit;
}
.home-inline-btn:hover { color: var(--brand-500); }

.home-runs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.home-run-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--s-3);
  padding: 10px 12px;
  background: var(--bg-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: var(--fs-13);
}
.home-run-bullet {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  background: rgba(52, 211, 153, 0.12);
  color: var(--ok);
}
.home-run-fail .home-run-bullet {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
}
.home-run-text {
  color: var(--text-2);
  line-height: 1.4;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.home-run-time {
  color: var(--muted);
  font-size: var(--fs-12);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.home-rules-summary {
  background: var(--bg-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: var(--s-3) var(--s-4);
}
.home-rules-line {
  margin: 0;
  color: var(--text-2);
  font-size: var(--fs-13);
  line-height: 1.5;
}
.home-rules-line strong { color: var(--text); font-weight: 600; }

/* =====================================================================
   Selector de plantillas (sheet "+")
   ===================================================================== */

.template-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.template-card {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  text-align: left;
  background: var(--bg-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-4);
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.template-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-2);
}
.template-card-adv {
  border-style: dashed;
  opacity: 0.85;
}
.template-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
}
.template-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.template-title {
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}
.template-sub {
  font-size: var(--fs-12);
  color: var(--muted);
  line-height: 1.4;
}

.sheet-intro {
  margin: 0 0 var(--s-4);
  color: var(--muted);
  font-size: var(--fs-13);
  line-height: 1.5;
}

.adv-cond {
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: var(--s-3);
  margin: var(--s-3) 0;
}

/* Select dropdown (mismo aspecto que field-input) */
.field-select {
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
  cursor: pointer;
}

/* Tarjetas de regla: estilo discreto para inactivas */
.rule-inactive { opacity: 0.6; }

/* =====================================================================
   Bottom navigation: 5 columnas
   ===================================================================== */

.bottombar-5 {
  grid-template-columns: repeat(5, 1fr);
}
.bottombar-5 .tab {
  padding: 0 2px;
}
.bottombar-5 .tab-label {
  font-size: 10px;
  letter-spacing: -0.005em;
}
.bottombar-5 .tab-glyph {
  font-size: var(--fs-13);
}

/* =====================================================================
   Vista Asistente (chat)
   ===================================================================== */

.chat-shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--topbar-h) - var(--bottombar-h) - 96px);
}
.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.chat-head-info { min-width: 0; flex: 1; }
.chat-title {
  margin: 0;
  font-size: var(--fs-20);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}
.chat-sub {
  margin: var(--s-1) 0 0;
  color: var(--muted);
  font-size: var(--fs-13);
  line-height: 1.5;
}
.chat-thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding-bottom: var(--s-4);
  min-height: 240px;
}
.chat-empty {
  margin: var(--s-8) auto;
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-13);
  max-width: 360px;
  line-height: 1.6;
}
.chat-empty p { margin: 0 0 var(--s-2); }
.chat-empty-hint { color: var(--muted); font-size: var(--fs-12); }

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 85%;
}
.chat-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-msg-agent {
  align-self: flex-start;
  align-items: flex-start;
}
.chat-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: var(--fs-14);
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.chat-msg-user .chat-bubble {
  background: var(--text);
  color: var(--bg-0);
  border-bottom-right-radius: 4px;
}
.chat-msg-agent .chat-bubble {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 4px;
}
.chat-bubble-loading {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 48px;
  padding: 12px 14px;
}
.chat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
  animation: chatbounce 1.2s infinite ease-in-out;
}
.chat-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatbounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}
.chat-time {
  font-size: var(--fs-11);
  color: var(--muted);
}
.chat-actions {
  font-size: var(--fs-12);
  color: var(--muted);
  line-height: 1.4;
}
.chat-model-tag {
  font-size: var(--fs-11);
  color: var(--muted);
  font-style: italic;
}
.chat-model-bar {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
  font-size: var(--fs-12);
  color: var(--muted);
  flex-wrap: wrap;
}
.chat-model-label {
  font-weight: 500;
  color: var(--muted);
}
.chat-model-select {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: var(--fs-12);
  font-family: inherit;
  cursor: pointer;
}
.chat-model-select:focus {
  outline: none;
  border-color: var(--text);
}
.chat-model-hint {
  font-size: var(--fs-11);
  color: var(--muted);
}
.chat-cutoff {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-11);
  font-weight: 600;
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.08);
  align-self: flex-start;
}

.chat-composer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
  padding: var(--s-3) 0 var(--s-2);
  background: linear-gradient(180deg, transparent 0%, var(--bg-0) 30%);
}
.chat-input {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 140px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-1);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-14);
  line-height: 1.5;
  outline: 0;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.chat-input:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}
.chat-send {
  flex-shrink: 0;
  min-height: 40px;
}

/* =====================================================================
   Vista Programadas / Memoria / Skills
   ===================================================================== */

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: var(--s-3) 0;
  font-size: var(--fs-13);
  color: var(--text-2);
  cursor: pointer;
}
.field-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--text);
  cursor: pointer;
}

.memory-list,
.skills-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin-top: var(--s-3);
}
.memory-item,
.skill-item {
  padding: var(--s-3);
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.memory-item-head,
.skill-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  margin-bottom: var(--s-2);
}
.memory-item-title,
.skill-item-title {
  margin: 0;
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}
.memory-item-body {
  margin: 0;
  font-size: var(--fs-13);
  color: var(--text-2);
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.skill-actions {
  margin-top: 0;
}

/* =====================================================================
   Reduced motion
   ===================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
