:root {
  /* Marca CEMESA */
  --verde: #15803D;        /* acción primaria (AA sobre blanco) */
  --verde-osc: #166534;
  --verde-700: #14532D;
  --verde-topbar: #1A6B2F; /* verde oficial del logo/edificio */
  --teal: #0E7490;         /* acento profundizado (AA) */
  --naranja: #B45309;
  --naranja-bg: #FDF0DC;

  /* Rampa neutral (gris verde-frío) */
  --n-0: #ffffff;
  --n-50: #f6f8f6;
  --n-100: #eef2ef;
  --n-200: #e2e8e3;
  --n-300: #cdd6cf;
  --n-500: #6b7770;
  --n-700: #3a443d;
  --n-900: #18211b;

  /* Estados (verde + teal + rojo + naranja: on-brand y distintos) */
  --st-prog: #0E7490;   --st-prog-bg: #E0F2F4;   /* Programada = teal */
  --st-done: #15803D;   --st-done-bg: #DEF3E3;   /* Realizada  = verde */
  --st-cancel: #B3261E; --st-cancel-bg: #FBEAE9; /* Cancelada  = rojo */
  --st-noshow: #B45309; --st-noshow-bg: #FDF0DC; /* No asistió = naranja */

  /* Aliases sobre la rampa */
  --bg: var(--n-50);
  --card: var(--n-0);
  --ink: var(--n-900);
  --muted: var(--n-500);
  --line: var(--n-200);
  --danger: var(--st-cancel);

  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px;

  /* Elevación */
  --shadow-sm: 0 1px 2px rgba(16, 32, 22, 0.06), 0 1px 3px rgba(16, 32, 22, 0.05);
  --shadow-md: 0 2px 8px rgba(16, 32, 22, 0.08), 0 4px 16px rgba(16, 32, 22, 0.04);
  --shadow-lg: 0 8px 24px rgba(16, 32, 22, 0.12);

  font-family: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

.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;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.4;
}

/* Foco visible global (teclado) */
:where(button, a, [tabindex], input, select, textarea):focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Topbar */
.topbar {
  background: linear-gradient(180deg, var(--verde-topbar) 0%, var(--verde-osc) 100%);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06), var(--shadow-sm);
}
.topbar__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__logo {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #fff;
  padding: 3px;
  object-fit: contain;
  flex: none;
  box-shadow: var(--shadow-sm);
}
.topbar h1 { font-size: 1.25rem; margin: 0; font-weight: 800; letter-spacing: -0.01em; }
.topbar__sub { margin: 2px 0 0; font-size: 0.78rem; opacity: 0.9; font-weight: 500; }
.chip {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  white-space: nowrap;
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: none;
}

/* Banner */
.banner {
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
}
.banner--error { background: #fbeae9; color: var(--danger); border: 1px solid #f3c9c6; }

/* Screen */
.screen { padding: 16px 16px 120px; max-width: 720px; margin: 0 auto; }

.daybar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.daybar__label { font-weight: 600; color: var(--muted); }
.daybar__input {
  flex: 1;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  font-size: 1rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  background: var(--card);
  color: var(--ink);
}

/* View tabs */
.viewtabs {
  display: flex;
  gap: 6px;
  background: var(--n-100);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 14px;
}
.viewtab {
  flex: 1;
  min-height: 42px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.viewtab--active { background: var(--card); color: var(--verde-osc); box-shadow: var(--shadow-sm); }
.daybar[hidden] { display: none; }

/* Resumen del día */
.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.summary__stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.summary__stat--zero { opacity: 0.55; }
.summary__num { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.summary__lbl {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 4px;
}
.summary__stat--prog   .summary__num { color: var(--st-prog); }
.summary__stat--done   .summary__num { color: var(--st-done); }
.summary__stat--cancel .summary__num { color: var(--st-cancel); }
.summary__stat--noshow .summary__num { color: var(--st-noshow); }

/* Day group headers */
.dayhead {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: capitalize;
  margin: 16px 2px 8px;
}
.dayhead:first-child { margin-top: 0; }

/* List */
.list { display: flex; flex-direction: column; gap: 10px; }
.visit {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--st-prog);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}
.visit:active { transform: scale(0.99); }
@media (hover: hover) {
  .visit:has(.visit__open:hover) { box-shadow: var(--shadow-md); }
}
.visit__open {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 14px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

/* Bloque de hora teñido por estado (fuente de verdad del color) */
.visit__time {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--st-prog-bg);
  color: var(--st-prog);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.visit__time b { font-size: 1.05rem; font-weight: 800; }
.visit__time small {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.visit__main { min-width: 0; }
.visit__name {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.visit__sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Variantes por estado */
.visit--showed    { border-left-color: var(--st-done); }
.visit--showed   .visit__time { background: var(--st-done-bg);   color: var(--st-done); }
.visit--cancelled { border-left-color: var(--st-cancel); opacity: 0.72; }
.visit--cancelled .visit__time { background: var(--st-cancel-bg); color: var(--st-cancel); }
.visit--cancelled .visit__name { text-decoration: line-through; text-decoration-color: var(--n-300); }
.visit--noshow    { border-left-color: var(--st-noshow); }
.visit--noshow   .visit__time { background: var(--st-noshow-bg); color: var(--st-noshow); }

.visit__actions {
  display: flex;
  gap: 8px;
  padding: 0 14px 12px;
}
.chipbtn {
  flex: 1;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--st-done-bg);
  color: var(--st-done);
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.chipbtn:disabled { opacity: 0.5; cursor: progress; }
.chipbtn--danger { background: var(--st-cancel-bg); color: var(--st-cancel); }

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 9px 4px 8px;
  border-radius: 999px;
  background: var(--st-prog-bg);
  color: var(--st-prog);
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}
.badge--cancelled { background: var(--st-cancel-bg); color: var(--st-cancel); }
.badge--showed { background: var(--st-done-bg); color: var(--st-done); }
.badge--noshow { background: var(--st-noshow-bg); color: var(--st-noshow); }

/* Empty / loading / error states */
.state {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
}
.state__big { font-size: 1.05rem; color: var(--ink); margin-bottom: 6px; font-weight: 600; }

/* Skeleton */
.skeleton { display: flex; flex-direction: column; gap: 10px; }
.sk-card {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--n-200);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.sk-block { height: 42px; width: 62px; border-radius: var(--radius-sm); background: var(--n-100); }
.sk-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--n-100) 25%, var(--n-200) 37%, var(--n-100) 63%);
  background-size: 400% 100%;
  animation: sk 1.4s ease infinite;
}
.sk-name { width: 60%; }
.sk-sub { width: 40%; margin-top: 8px; }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* Buttons */
.btn {
  min-height: var(--tap);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  padding: 0 18px;
  cursor: pointer;
}
.btn--primary { background: var(--verde); color: #fff; }
.btn--primary:disabled { background: #9bbfa5; cursor: progress; }
.btn--ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn--lg { width: 100%; min-height: 54px; font-size: 1.08rem; }

.fab {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  max-width: 688px;
  margin: 0 auto;
  min-height: 56px;
  background: var(--verde);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 1.1rem;
  font-weight: 800;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(20, 80, 40, 0.32);
  cursor: pointer;
  z-index: 15;
}
.fab[hidden] { display: none; }
.fab__plus { font-size: 1.5rem; line-height: 1; }

/* Sheet / dialog */
.sheet {
  border: none;
  padding: 0;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  border-radius: 18px 18px 0 0;
  margin: auto auto 0;
  background: var(--card);
  color: var(--ink);
}
.sheet[open] { animation: sheetUp 0.26s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes sheetUp {
  from { transform: translateY(16px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}
.sheet::backdrop { background: rgba(15, 30, 20, 0.45); }
.sheet__body { padding: 6px 18px calc(env(safe-area-inset-bottom) + 18px); overflow-y: auto; max-height: 92vh; }
/* Drag-handle */
.sheet__body::before {
  content: "";
  display: block;
  width: 36px; height: 4px;
  border-radius: 999px;
  background: var(--n-300);
  margin: 6px auto 14px;
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet__head h2 { margin: 0; font-size: 1.2rem; font-weight: 800; }
.sheet__head-actions { display: flex; align-items: center; gap: 6px; }
.btn--sm { min-height: 38px; padding: 0 14px; font-size: 0.9rem; }
.sheet__foot {
  position: sticky;
  bottom: 0;
  background: var(--card);
  padding-top: 12px;
  margin-top: 18px;
  box-shadow: 0 -8px 16px -8px rgba(0, 0, 0, 0.08);
}
.iconbtn {
  width: var(--tap); height: var(--tap);
  border: none; background: transparent;
  font-size: 1.2rem; cursor: pointer; color: var(--muted);
  border-radius: 50%;
}

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field[hidden] { display: none; }
.field > span, .field__label { font-weight: 600; font-size: 0.9rem; color: var(--muted); }
.field__opt { font-weight: 400; color: var(--muted); opacity: 0.8; }
.field input, .field textarea, .field select {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
.field select { appearance: none; -webkit-appearance: none; }
.field textarea { min-height: auto; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid var(--teal);
  border-color: var(--teal);
}
.field input:disabled { background: #f1f3f1; color: var(--muted); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.field [type=date], .field [type=time] { font-variant-numeric: tabular-nums; }

/* Contact search suggestions */
.field--search { position: relative; }
.suggest {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 5;
  margin-top: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  max-height: 240px;
  overflow-y: auto;
}
.suggest[hidden] { display: none; }
.suggest__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.suggest__item:last-child { border-bottom: none; }
.suggest__item:hover { background: var(--n-100); }
.suggest__name { font-weight: 600; color: var(--ink); }
.suggest__meta { font-size: 0.82rem; color: var(--muted); }

.formerror { color: var(--danger); font-size: 0.9rem; margin: 0 0 8px; }

/* Detail */
.detail-meta { background: var(--n-50); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 18px; }
.detail-meta dt { font-size: 0.78rem; color: var(--muted); font-weight: 700; }
.detail-meta dd { margin: 0 0 10px; }
.detail-meta dd:last-child { margin-bottom: 0; }

.thread__title { font-size: 1rem; margin: 0 0 10px; font-weight: 800; }
.thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.bubble { background: var(--n-100); border-radius: 12px; padding: 10px 12px; }
.bubble__head { display: flex; justify-content: space-between; gap: 8px; font-size: 0.78rem; color: var(--muted); margin-bottom: 3px; }
.bubble__author { font-weight: 700; color: var(--verde-osc); }
.bubble__body { white-space: pre-wrap; word-break: break-word; }

.comment-form { display: flex; flex-direction: column; gap: 8px; }
.comment-form textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 88px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  box-shadow: var(--shadow-lg);
  z-index: 30;
  max-width: 90vw;
  text-align: center;
  animation: toastIn 0.22s ease-out;
}
@keyframes toastIn { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.toast[hidden] { display: none; }
.toast--error { background: var(--danger); }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--verde);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 700px) {
  .sheet { border-radius: 18px; margin: auto; }
}

/* Respeto a usuarios que reducen movimiento */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
