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

:root {
  --bg: #f9f9f7;
  --bg-card: #ffffff;
  --bg-surface: #f3f3f0;
  --text: #1a1a19;
  --text-secondary: #5f5e5a;
  --text-muted: #9a9890;
  --border: rgba(0,0,0,0.1);
  --border-strong: rgba(0,0,0,0.18);
  --green: #16a34a;
  --green-bg: #dcfce7;
  --green-text: #15803d;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --red-text: #b91c1c;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --blue-text: #1d4ed8;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --bg-card: #1c1c1b;
    --bg-surface: #252524;
    --text: #f0efec;
    --text-secondary: #a5a49a;
    --text-muted: #6d6b67;
    --border: rgba(255,255,255,0.1);
    --border-strong: rgba(255,255,255,0.18);
    --green-bg: #14532d;
    --green-text: #86efac;
    --red-bg: #450a0a;
    --red-text: #fca5a5;
    --blue-bg: #1e3a5f;
    --blue-text: #93c5fd;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Nav ── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  height: 52px;
  background: var(--bg-card);
  border-bottom: 0.5px solid var(--border);
  gap: 1rem;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 500;
  font-size: 15px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.dot.active {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-bg);
}
.nav-links {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.nav-link {
  text-decoration: none;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.nav-link:hover { background: var(--bg-surface); }
.nav-link.active {
  color: var(--text);
  background: var(--bg-surface);
  font-weight: 500;
}

/* ── Layout ── */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

/* ── Botones principales ── */
.main-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 1.25rem;
}
.btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 1.25rem 1rem;
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover:not(:disabled) { background: var(--bg-surface); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn .icon { font-size: 20px; font-style: normal; }
.btn-entry .icon { color: var(--green); }
.btn-exit .icon { color: var(--blue); }

/* ── Visita actual ── */
.status-card {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.status-title {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.times {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.time-label { font-size: 11px; color: var(--text-muted); display: block; margin-bottom: 2px; }
.time-val { font-size: 15px; font-weight: 500; }
.time-val.muted { font-weight: 400; color: var(--text-muted); }

/* ── Section header ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.section-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.clear-btn {
  font-size: 11px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}
.clear-btn:hover { color: var(--red); }
.updated-at { font-size: 11px; color: var(--text-muted); }

/* ── Tabla historial ── */
.hist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}
.hist-table th {
  text-align: left;
  padding: 6px 8px;
  color: var(--text-muted);
  font-weight: 400;
  border-bottom: 0.5px solid var(--border);
  font-size: 12px;
}
.hist-table td {
  padding: 8px;
  border-bottom: 0.5px solid var(--border);
  vertical-align: top;
}
.hist-table tr:last-child td { border-bottom: none; }
.col-entry { width: 38%; }
.col-act   { width: 24%; }
.col-exit  { width: 38%; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  margin-top: 3px;
}
.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-red   { background: var(--red-bg);   color: var(--red-text);   }
.badge-gray  { background: var(--bg-surface); color: var(--text-secondary); }
.badge-blue  { background: var(--blue-bg);  color: var(--blue-text);  }
.dur { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-muted);
  font-size: 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: 18px 18px 14px 14px;
  width: 100%;
  max-width: 400px;
  padding: 1.5rem;
  border: 0.5px solid var(--border);
  max-height: 80vh;
  overflow-y: auto;
}
.modal-title {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 1.25rem;
}

/* ── Campos del modal ── */
.field { margin-bottom: 1.25rem; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}
.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.opt {
  padding: 0.65rem 0.75rem;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  background: var(--bg-card);
  color: var(--text);
  font-family: inherit;
  transition: all 0.1s;
  text-align: center;
}
.opt:hover { background: var(--bg-surface); }
.opt.selected-success {
  background: var(--green-bg);
  border-color: var(--green);
  color: var(--green-text);
}
.opt.selected-danger {
  background: var(--red-bg);
  border-color: var(--red);
  color: var(--red-text);
}
.opt.selected-info {
  background: var(--blue-bg);
  border-color: var(--blue);
  color: var(--blue-text);
}
.opt-full { grid-column: span 2; }
.confirm-btn {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  margin-top: 0.5rem;
  transition: opacity 0.15s;
}
.confirm-btn:hover:not(:disabled) { opacity: 0.85; }
.confirm-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.cancel-btn {
  width: 100%;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
  background: transparent;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-secondary);
  margin-top: 6px;
}
.cancel-btn:hover { background: var(--bg-surface); }

/* ── Consulta: banner readonly ── */
.readonly-banner {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
}
.refresh-inline {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  font-size: 12px;
  color: var(--text-secondary);
  background: none;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 9px;
  cursor: pointer;
  font-family: inherit;
}
.refresh-inline:hover { background: var(--bg-card); }

/* ── Consulta: activa ── */
.active-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-lg);
  background: var(--green-bg);
  border: 0.5px solid var(--green);
  margin-bottom: 1.25rem;
}
.active-card p { font-size: 13px; font-weight: 500; color: var(--green-text); }
.active-card small { font-size: 12px; color: var(--green-text); opacity: 0.8; display: block; }
.no-active-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 0.5px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}

/* ── Consulta: métricas ── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 1.25rem;
}
.metric {
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
}
.metric-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.metric-val { font-size: 22px; font-weight: 500; }
.metric-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
