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

:root {
  --accent: #eab308;
  --accent-dark: #ca8a04;
  --accent-light: #fefce8;
  --bg: #ffffff;
  --bg-card: #f9fafb;
  --bg-input: #f3f4f6;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --red: #dc2626;
  --red-light: #991b1b;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --green-border: #bbf7d0;
  --wa-green: #25d366;
  --yellow-bg: #fffbeb;
  --yellow-border: #fde68a;
  --yellow-text: #92400e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
}

html,
body {
  height: 100%;
  font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Screens */
.screen {
  display: none;
  min-height: 100vh;
  padding: 24px 16px 100px;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* Center vertically for login */
}

#screen-main.active,
#screen-admin.active {
  justify-content: flex-start;
  /* Maintain top alignment for main content */
}

/* Logo in login - replaces title */
.logo-login {
  width: 220px;
  height: auto;
  object-fit: contain;
  margin-bottom: 0px;
}

/* Logo in main screen */
.logo-main {
  width: 100%;
  max-width: 280px;
  height: auto;
  object-fit: contain;
  margin-bottom: 12px;
}

.logo-sm {
  width: 100px;
  height: auto;
  object-fit: contain;
  margin-bottom: 8px;
}

/* Login */
.login-container {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app-subtitle {
  font-size: 26px;
  color: var(--text-muted);
  margin-bottom: 36px;
}

#login-form {
  width: 100%;
}

.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.input-group input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.15);
}

.input-hint {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-gate {
  background: #0f172a;
  /* Sophisticated dark blue/black */
  color: #fff;
  padding: 28px 24px;
  font-family: 'Montserrat', sans-serif;
  font-size: 16px;
  font-weight: 800;
  border-radius: 20px;
  border: none;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.3);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-gate::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(rgba(255, 255, 255, 0.1), transparent);
  pointer-events: none;
}

.btn-gate:hover {
  background: #1e293b;
  box-shadow: 0 15px 30px rgba(15, 23, 42, 0.4);
  transform: translateY(-3px);
}

.btn-gate:active {
  transform: translateY(-1px);
}

.btn-gate:disabled {
  background: #64748b;
  opacity: 0.7;
  color: #e2e8f0;
  box-shadow: none;
  cursor: locked;
  transform: none;
}

.btn-closed {
  background: linear-gradient(135deg, #9ca3af, #6b7280) !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1) !important;
  cursor: default;
}

.btn-logout {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 14px;
  padding: 12px;
  margin-top: 24px;
}

.btn-logout:hover {
  background: var(--bg-input);
}

.btn-client-access {
  background: #fff;
  color: var(--text);
  border: 2px solid var(--accent);
  margin-top: 12px;
  text-decoration: none;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-client-access:hover {
  background: var(--accent-light);
  border-color: var(--accent-dark);
}

.btn-client-access svg {
  color: var(--accent-dark);
}

/* Error message */
.error-msg {
  margin-top: 16px;
  padding: 12px;
  border-radius: 10px;
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
  font-size: 14px;
  text-align: center;
}

/* Main screen */
.main-container {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 24px;
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}

.user-info #user-name {
  font-family: 'Montserrat', sans-serif;
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}

.user-badges {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.user-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 8px 24px;
  min-width: 120px;
  flex: 1;
}

.user-badge-ubi {
  background: var(--bg-card);
  border-color: var(--border);
}

.user-badge-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.user-badge-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

.gate-double-row {
  display: flex;
  gap: 10px;
}

.btn-gate-half {
  flex: 1;
  padding: 20px 12px;
  font-size: 16px;
}

/* Gate section */
#gate-section {
  width: 100%;
  margin-bottom: 20px;
}

.gate-status {
  text-align: center;
  padding: 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  margin-top: 8px;
}

.gate-status.opening {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}

.gate-status.error {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
}

/* Notice boxes */
.notice-box {
  width: 100%;
  padding: 16px;
  border-radius: 14px;
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 1.6;
}

.notice-horario {
  background: var(--yellow-bg);
  border: 1px solid var(--yellow-border);
  color: var(--yellow-text);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.notice-horario svg {
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--yellow-text);
}

.notice-important {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red-light);
}

.notice-important strong {
  display: block;
  margin-bottom: 8px;
  color: var(--red);
  font-size: 15px;
}

.notice-important ul {
  list-style: disc;
  padding-left: 20px;
}

.notice-important li {
  margin-bottom: 4px;
}

/* Contact section */
.contact-section {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}

.contact-section h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--accent-dark);
}

.contact-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  margin-bottom: 8px;
  transition: background 0.2s, border-color 0.2s;
}

.contact-link:hover {
  background: var(--bg-input);
  border-color: #d1d5db;
}

.contact-link svg {
  flex-shrink: 0;
}

.contact-wa svg {
  color: var(--wa-green);
  fill: var(--wa-green);
}

.contact-phone svg {
  color: var(--accent-dark);
  stroke: var(--accent-dark);
}

.contact-alt-title {
  font-size: 13px;
  color: var(--text-muted);
  margin: 14px 0 8px;
  font-weight: 500;
}

/* WhatsApp FAB */
.whatsapp-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--wa-green);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(37, 211, 102, 0.35);
  z-index: 1000;
  transition: transform 0.2s, box-shadow 0.2s, width 0.3s, border-radius 0.3s, padding 0.3s;
  text-decoration: none;
}

.whatsapp-fab.has-label {
  width: auto;
  padding: 0 20px;
  border-radius: 30px;
}

.whatsapp-fab-label {
  display: none;
  font-family: 'Open Sans', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  margin-right: 12px;
  white-space: nowrap;
}

.whatsapp-fab.has-label .whatsapp-fab-label {
  display: block;
}

.whatsapp-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(37, 211, 102, 0.45);
}

.whatsapp-fab:active {
  transform: scale(0.95);
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

@keyframes pulse {

  0%,
  100% {
    box-shadow: 0 4px 20px rgba(22, 163, 74, 0.2);
  }

  50% {
    box-shadow: 0 4px 32px rgba(22, 163, 74, 0.4);
  }
}

.gate-status.opening {
  animation: pulse 1.5s ease-in-out 3;
}

/* ── Admin Panel ── */
.admin-container {
  width: 100%;
  max-width: 600px;
  padding-top: 16px;
}

.admin-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}

.admin-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.admin-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
}

.admin-section h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-dark);
  margin-bottom: 12px;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.admin-section-header h3 {
  margin-bottom: 0;
}

.admin-gates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-gate-sm {
  padding: 16px 12px;
  font-size: 14px;
}

.admin-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .admin-form-grid {
    grid-template-columns: 1fr;
  }
}

.admin-section select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.admin-section select:focus {
  border-color: var(--accent);
}

.admin-msg {
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
}

.admin-msg.success {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}

.admin-msg.error {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
}

.admin-clients-list {
  max-height: 500px;
  overflow-y: auto;
}

/* Admin search */
.admin-search {
  margin-bottom: 12px;
}

.admin-search input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.admin-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.15);
}

/* Admin filter bar */
.admin-filter-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.admin-filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.admin-filter-btn:hover {
  background: var(--bg-input);
}

.admin-filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.admin-clients-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.client-card {
  display: flex;
  flex-direction: column;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  margin-bottom: 10px;
  gap: 10px;
}

.client-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.client-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.client-card-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.client-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text);
}

.client-badge-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.client-badge-tel {
  background: #eff6ff;
  color: #1d4ed8;
}

.client-badge-box {
  background: var(--accent-light);
  color: var(--accent-dark);
}

.client-badge-ubi {
  background: var(--green-bg);
  color: var(--green);
}

.client-card-bottom {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.client-info {
  flex: 1;
  min-width: 0;
}

.client-info strong {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-info small {
  color: var(--text-muted);
  font-size: 12px;
}

.client-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 24px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked+.toggle-slider {
  background: var(--green);
}

.toggle input:checked+.toggle-slider::before {
  transform: translateX(20px);
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.2s;
}

.btn-icon:hover {
  background: var(--bg-input);
}

.btn-delete {
  background: none;
  border: 1px solid var(--red-border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--red);
  transition: background 0.2s;
}

.btn-delete:hover {
  background: var(--red-bg);
}

.text-muted {
  color: var(--text-muted);
  font-size: 14px;
}

.ubicacion-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--accent-light);
  color: var(--accent-dark);
}

/* Truck gate button */
.btn-gate-truck {
  background: #1e3a5f;
  box-shadow: 0 10px 25px rgba(30, 58, 95, 0.3);
  margin-top: 10px;
}

.btn-gate-truck:hover {
  background: #2d527a;
  box-shadow: 0 15px 30px rgba(30, 58, 95, 0.4);
}

/* Admin gate grid with 5 buttons */
.admin-gates {
  grid-template-columns: 1fr 1fr 1fr;
}

@media (max-width: 480px) {
  .admin-gates {
    grid-template-columns: 1fr 1fr;
  }
}

/* Logs section */
.admin-logs-list {
  max-height: 480px;
  overflow-y: auto;
}

.log-item {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  background: #fff;
  margin-bottom: 8px;
}

.log-item.log-success {
  border-left-color: var(--green);
}

.log-item.log-error {
  border-left-color: var(--red);
}

.log-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.log-status-icon {
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.log-status-icon.log-ok {
  background: var(--green-bg);
  color: var(--green);
}

.log-status-icon.log-fail {
  background: var(--red-bg);
  color: var(--red);
}

.log-who {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.log-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding-left: 28px;
}

.log-loc {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent-light);
  color: var(--accent-dark);
}

.log-error-msg {
  font-size: 11px;
  color: var(--red);
  font-style: italic;
}

/* ── Device Status Bar ── */
#device-status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 9px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d1d5db;
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
  animation: pulse-dot 2.5s ease-in-out infinite;
}

.status-dot.offline {
  background: var(--red);
}

@keyframes pulse-dot {

  0%,
  100% {
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
  }

  50% {
    box-shadow: 0 0 0 6px rgba(22, 163, 74, 0.08);
  }
}

.status-checking {
  font-size: 12px;
  color: var(--text-muted);
}