:root {
  color-scheme: light;
  --bg: #f8f5ef;
  --panel: #ffffff;
  --ink: #343b2b;
  --muted: #6b705e;
  --line: #dcd7c7;
  --accent: #4a513b;
  --accent-2: #a58e5c;
  --danger: #b3261e;
  --ok: #4a6240;
  --shadow: 0 12px 34px rgba(52, 59, 43, 0.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* evita zoom automático en iOS al enfocar */
}

button {
  border: 0;
  border-radius: 8px;
  padding: 14px 16px;
  min-height: 48px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { opacity: .55; cursor: not-allowed; }
.secondary { background: #eeeddf; color: var(--ink); }
.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.compact { min-height: 40px; padding: 9px 12px; font-size: 14px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 12px;
  background: #fff;
  color: var(--ink);
  min-height: 48px;
  appearance: none;
  -webkit-appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b705e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

textarea { resize: vertical; }
label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #454c38;
}

.hidden { display: none !important; }
.shell {
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport en móvil (oculta barra del browser) */
  display: grid;
  place-items: center;
  padding: 16px;
}

.auth-shell {
  background:
    linear-gradient(180deg, rgba(74, 81, 59, .14), rgba(165, 142, 92, .08)),
    var(--bg);
}

.auth-panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.admin-access {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, .8);
  border-radius: 999px;
  background: rgba(52, 59, 43, .82);
  color: #fff;
  box-shadow: 0 6px 18px rgba(52, 59, 43, .18);
  font-size: 12px;
  font-weight: 700;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 22px;
}

.brand-logo {
  width: 122px;
  max-width: 42%;
  height: auto;
  object-fit: contain;
}

h1, h2, p { margin: 0; }
.brand-block h1 { font-size: 20px; line-height: 1.25; }
.brand-block p, .hint, #userLabel { color: var(--muted); font-size: 14px; margin-top: 3px; }
.stack { display: grid; gap: 14px; }
.section-title { font-size: 15px; font-weight: 800; }

.notice {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f9fbfa;
  color: var(--ink);
  font-size: 14px;
}
.notice.error { border-color: #f0b8b4; background: #fff4f3; color: var(--danger); }
.notice.success { border-color: #bdcfc0; background: #f4f8f3; color: var(--ok); }

.app { min-height: 100vh; min-height: 100dvh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(255, 255, 255, .95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar h1 { font-size: 20px; line-height: 1.2; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.eyebrow {
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.icon-action {
  width: 44px;
  height: 44px;
  padding: 0;
  background: #eeeddf;
  position: relative;
}
.icon-action span,
.icon-action::before,
.icon-action::after {
  content: "";
  position: absolute;
  background: var(--ink);
}
.icon-action span { width: 17px; height: 2px; left: 13px; top: 21px; }
.icon-action::before { width: 2px; height: 18px; left: 21px; top: 9px; }
.icon-action::after {
  width: 10px;
  height: 10px;
  border-top: 2px solid var(--ink);
  border-right: 2px solid var(--ink);
  background: transparent;
  transform: rotate(45deg);
  right: 11px;
  top: 16px;
}

.content {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 12px 12px calc(28px + env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
}
.content-stack { display: grid; gap: 12px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 8px 24px rgba(52, 59, 43, .06);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.panel-head h2 { font-size: 19px; }

.form-grid {
  display: grid;
  gap: 12px;
}
.full { grid-column: 1 / -1; }

.phone-entry {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.phone-entry button { min-height: 48px; }
.phone-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
}
.phone-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 8px 7px 11px;
  background: #faf8f1;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}
.phone-chip button {
  width: 24px;
  height: 24px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: #eeeddf;
  color: var(--ink);
  line-height: 1;
}

.pin-card {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.pin-card img {
  width: 100%;
  max-width: 320px;
  height: auto;
  aspect-ratio: 7 / 4;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
}
.pin-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.speed-dial { margin-top: 16px; }
.speed-dial-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.speed-dial-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.speed-dial-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, minmax(72px, 1fr));
  gap: 8px;
}
.dial-slot {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #faf8f1;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 4px;
  overflow: hidden;
}
.dial-slot-send {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 6px 4px;
  min-height: 0;
}
.dial-slot.filled .dial-slot-send { background: var(--accent); color: #fff; }
.dial-slot.filled .dial-slot-send small { color: rgba(255,255,255,.8); font-weight: 400; }
.dial-slot.empty .dial-slot-send {
  background: transparent;
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
}
.dial-slot-send span { font-size: 13px; line-height: 1.2; word-break: break-word; max-width: 100%; }
.dial-slot-send small { font-size: 11px; color: var(--muted); }
.dial-slot-edit {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 24px;
  height: 24px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: #eeeddf;
  color: var(--ink);
  font-size: 12px;
  line-height: 1;
  z-index: 2;
}
.dial-slot.filled .dial-slot-edit { background: rgba(255,255,255,.85); }

.list-filters {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.list-filters select { width: auto; min-width: 130px; }
.search { margin-bottom: 12px; }
.invite-list {
  display: grid;
  gap: 10px;
}
.invite-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  display: grid;
  gap: 10px;
  background: #fff;
}
.invite-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.invite-main strong { display: block; font-size: 16px; }
.pin {
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}
.meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
}
.badge {
  display: inline-flex;
  width: max-content;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eeeddf;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}
.badge.activa { background: #edf4ed; color: var(--ok); }
.badge.cancelada, .badge.usada { background: #fff3f0; color: var(--danger); }
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.actions button { min-height: 44px; padding: 10px; font-size: 13px; }
.danger { background: #fff3f0; color: var(--danger); }

.auth-info-list {
  margin-top: 18px;
  display: grid;
  gap: 8px;
}

.auth-info-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid transparent;
}

.auth-info-icon {
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 1px;
}

.auth-info-item--support {
  background: #eeeddf;
  border-color: #dcd7c7;
  color: #5c624e;
}
.auth-info-item--support a {
  color: #5c624e;
  font-weight: 700;
  text-decoration: underline;
}

.auth-info-item--access {
  background: #f2f7f2;
  border-color: #bdcfc0;
  color: #456451;
}

.auth-info-item--warning {
  background: #faf5ed;
  border-color: #e4d0ad;
  color: #785f3f;
}

/* ── Modal instrucciones ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(52, 59, 43, .55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-box {
  width: min(480px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(52, 59, 43, .25);
  padding: 20px;
  display: grid;
  gap: 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-header h2 { font-size: 18px; }

.platform-selector {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: -4px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #faf8f1;
}
.platform-selector legend {
  width: 100%;
  padding: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.platform-option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.platform-option input {
  width: 18px;
  min-height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  appearance: auto;
  -webkit-appearance: radio;
}

.modal-close {
  width: 36px;
  height: 36px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: #eeeddf;
  color: var(--ink);
  font-size: 16px;
  flex-shrink: 0;
}

.instrucciones-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}
.instrucciones-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.instrucciones-list p { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; font-weight: 400; }
.instrucciones-list strong { font-size: 15px; color: var(--ink); }

.step-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  display: grid;
  place-items: center;
  margin-top: 1px;
}

.reglas-password {
  margin: 8px 0 0 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
}
.reglas-password code {
  background: #eeeddf;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  color: var(--ink);
}

.modal-note {
  margin-top: 10px;
  padding: 10px 12px;
  background: #faf5ed;
  border: 1px solid #e4d0ad;
  border-radius: 8px;
  font-size: 13px;
  color: #785f3f;
  line-height: 1.5;
  font-weight: 400;
}

.modal-btn-ok {
  width: 100%;
}

.admin-panel-intro { margin: -6px 0 14px; }
.admin-divider { height: 1px; margin: 24px 0; background: var(--line); }
.assigned-phones {
  display: grid;
  gap: 6px;
}
.assigned-phones-label {
  color: #454c38;
  font-size: 13px;
  font-weight: 700;
}

.admin-record-list {
  display: grid;
  gap: 10px;
}
.admin-search {
  display: grid;
  gap: 6px;
  margin: 0 0 12px;
  color: #454c38;
  font-size: 13px;
  font-weight: 700;
}
.admin-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}
.admin-pagination > div { display: flex; align-items: center; gap: 8px; }
.admin-pagination button { min-width: 36px; padding: 6px 10px; font-size: 20px; line-height: 1; }
.admin-record {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #faf8f1;
}
.admin-record > div:first-child {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.admin-record strong { color: var(--ink); }
.admin-record span, .admin-record small { color: var(--muted); font-size: 13px; line-height: 1.35; }
.admin-record-actions { display: flex; flex-shrink: 0; gap: 6px; }
.admin-icon-action {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 17px;
  line-height: 1;
  flex: 0 0 38px;
}
button.danger { background: #a74f47; color: #fff; }
button.danger:hover { background: #8d4039; }
button.warning-action { background: #b07a37; color: #fff; }
button.warning-action:hover { background: #94642b; }
button.success-action { background: #54775e; color: #fff; }
button.success-action:hover { background: #43624c; }

@media (max-width: 430px) {
  .admin-record { align-items: flex-start; flex-direction: column; }
  .admin-record-actions { width: 100%; }
  .admin-record-actions button:not(.admin-icon-action) { flex: 1; }
  .admin-pagination { align-items: flex-start; flex-direction: column; }
}

/* ── Tablet / Desktop ── */
@media (min-width: 600px) {
  .auth-panel { padding: 28px; }
  .brand-block h1 { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .full { grid-column: 1 / -1; }
  .pin-card {
    grid-template-columns: 160px 1fr;
    align-items: center;
  }
  .pin-card img { max-width: 160px; }
}

@media (min-width: 760px) {
  .content { max-width: 560px; }
  .panel { padding: 20px; }
  .topbar h1 { font-size: 22px; }
}

/* ── Teléfono pequeño (<380px) ── */
@media (max-width: 380px) {
  .auth-panel { padding: 14px; border-radius: 10px; }
  .brand-block { gap: 10px; margin-bottom: 14px; }
  .brand-logo { width: 104px; }
  .content { padding-left: 8px; padding-right: 8px; }
  .panel { border-radius: 10px; padding: 12px; }
  .invite-main { display: grid; }
  .actions { grid-template-columns: 1fr; }
}

/* Identidad Residencial Frondoso */
.brand-block { flex-direction: column; text-align: center; }
.brand-logo { width: 230px; max-width: 75%; }
.brand-block h1 { font-family: Georgia, "Times New Roman", serif; color: var(--accent); }
.auth-panel { border-top: 3px solid var(--accent-2); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 3px; }
@media (max-width: 480px) { .brand-logo { width: 190px; } }

.recent-access-panel { grid-column: 1 / -1; }
.access-photo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 16px; }
.access-photo-card { border: 1px solid #d9ddcf; border-radius: 14px; overflow: hidden; background: #fff; }
.access-photo-card img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.access-photo-card > div { padding: 12px; }
.access-photo-card p { margin: 6px 0 0; font-size: 0.9rem; }
.access-photo-empty { padding: 24px; background: #f0f2eb; color: #49513e; }
