:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #3fd4af;          /* color oficial Ariel */
  --primary-dark: #2bbd9b;     /* hover */
  --primary-ink: #0e7c66;      /* teal legible para texto sobre blanco */
  --primary-btn-text: #08312a; /* texto oscuro sobre botón teal */
  --ok: #16a34a;
  --err: #dc2626;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: #f1f5f9;
}

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: linear-gradient(135deg, #3fd4af 0%, #0e7c66 100%);
  padding: 60px 20px 40px;
}
.login-card {
  background: #f4f0e9;
  padding: 40px 36px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 380px;
}
.login-logo { display: block; height: 88px; width: auto; margin: 0 auto 16px; }
.login-hotel { display: block; width: 215px; max-width: 70%; height: auto; margin: 0 auto 46px; }
.brand { margin: 0; font-size: 28px; color: #0f172a; text-align: center; }
.subtitle { margin: 4px 0 28px; color: var(--muted); font-size: 14px; text-align: center; }
.login-card label { display: block; margin: 14px 0 6px; font-weight: 600; font-size: 14px; }
.login-card input {
  width: 100%; padding: 14px; font-size: 16px;
  background: #fbf8f2;
  border: 1px solid #e3dccd; border-radius: 10px; outline: none;
}
.login-card input:focus { border-color: var(--primary); }
.login-card button {
  width: 100%; margin-top: 24px; padding: 14px; font-size: 16px; font-weight: 700;
  color: #fff; background: var(--primary); border: none; border-radius: 10px; cursor: pointer;
}
.login-card button:hover { background: var(--primary-dark); }
.error { color: var(--err); font-size: 14px; margin-top: 14px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: flex-start;
  background: #fff; color: var(--text); padding: 12px 22px 6px;
  border-bottom: 1px solid var(--border);
}
.topbar-left { flex: 1; display: flex; align-items: center; gap: 14px; }
.topbar-center { display: flex; align-items: center; justify-content: center; }
.topbar-logo { height: 104px; width: auto; }
.app-logo { height: 56px; width: auto; flex-shrink: 0; }
.brand-sm { font-weight: 800; font-size: 18px; color: #0f172a; }
.hotel-badge {
  background: var(--primary); color: #fff; font-size: 13px; font-weight: 700;
  padding: 4px 12px; border-radius: 999px;
}
.topbar-right { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 16px; }
.user-name { font-size: 14px; color: var(--muted); }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; text-decoration: underline; }
.link-btn:hover { color: var(--text); }
.nav-link {
  background: none; border: none; cursor: pointer; font-size: 14px; font-weight: 600;
  color: var(--muted); padding: 7px 12px; border-radius: 8px; text-decoration: none;
}
.nav-link:hover { color: var(--primary-ink); background: #effaf6; }

/* ---------- Layout ---------- */
.container { max-width: 760px; margin: 28px auto; padding: 0 18px; }
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 26px; margin-bottom: 24px;
}
.card h2 { margin: 0 0 20px; font-size: 20px; }

.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 15px; }
.field .opt { font-weight: 400; color: var(--muted); }
.field input, .field select {
  width: 100%; padding: 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 10px; outline: none; background: #fff;
}
.field input:focus, .field select:focus { border-color: var(--primary); }

button.primary {
  width: 100%; padding: 16px; font-size: 17px; font-weight: 700;
  color: #fff; background: var(--primary); border: none; border-radius: 10px; cursor: pointer;
}
button.primary:hover { background: var(--primary-dark); }
button.primary:disabled { background: #bdeee0; cursor: default; }

button.secondary {
  padding: 12px 18px; font-size: 15px; font-weight: 600;
  color: var(--primary-ink); background: #e9faf4; border: 1px solid #bcebdd;
  border-radius: 10px; cursor: pointer;
}
button.secondary:hover { background: #d5f5ec; }

button.ghost-btn {
  padding: 12px 18px; font-size: 15px; font-weight: 600;
  color: var(--text); background: #fff; border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer;
}
button.ghost-btn:hover { background: #f1f5f9; }

.msg { margin-top: 16px; font-size: 15px; }
.msg.error { color: var(--err); }
.msg.ok { color: var(--ok); }

/* ---------- Resultados ---------- */
.result-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.summary { font-size: 14px; color: var(--muted); }
.summary .ok { color: var(--ok); font-weight: 700; }
.summary .err { color: var(--err); font-weight: 700; }

.connection-info {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin: 16px 0; font-size: 14px; color: var(--muted);
}
.connection-info strong { color: var(--text); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }

.codes-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.code-item {
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: #fff;
}
.code-value { font-family: "SFMono-Regular", Consolas, monospace; font-size: 20px; font-weight: 700; letter-spacing: 1px; }
.copy-btn {
  border: none; background: #f1f5f9; border-radius: 8px; padding: 7px 10px;
  cursor: pointer; font-size: 13px; color: var(--muted);
}
.copy-btn:hover { background: #e2e8f0; }
.copy-btn.copied { background: #dcfce7; color: var(--ok); }

.failures { margin-top: 18px; padding: 12px 16px; border-radius: 10px; background: #fef2f2; color: var(--err); font-size: 14px; }

/* ---------- Administración de usuarios ---------- */
.link-btn-dark { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.link-btn-dark:hover { color: var(--primary-ink); background: #effaf6; }

/* ---------- Modal y toast ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 400px; padding: 26px; }
.modal h3 { margin: 0 0 18px; font-size: 19px; }
.modal-field { margin-bottom: 14px; }
.modal-field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.modal-field input { width: 100%; padding: 13px; font-size: 15px; border: 1px solid var(--border); border-radius: 10px; }
.modal-field input:focus { border-color: var(--primary); outline: none; }
.modal-field p { margin: 0; font-size: 15px; color: var(--text); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-actions button { width: auto; padding: 11px 22px; }
.toast { position: fixed; bottom: 26px; right: 26px; background: #0f172a; color: #fff; padding: 13px 22px; border-radius: 10px; font-size: 14px; font-weight: 600; z-index: 1100; box-shadow: var(--shadow); max-width: 90%; text-align: left; }
.toast.ok { background: var(--ok); }
.toast.del { background: #d97706; }
.toast.error { background: var(--err); }
.user-form { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }
.user-form .uf-row { display: flex; gap: 14px; }
.user-form .uf-field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.user-form .uf-field label { font-size: 13px; font-weight: 600; color: var(--text); }
.user-form input:not([type="checkbox"]) { width: 100%; box-sizing: border-box; padding: 9px 12px; font-size: 14px; border: 1px solid var(--border); border-radius: 10px; }
.user-form input:not([type="checkbox"]):focus { border-color: var(--primary); outline: none; }
.user-form .uf-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-top: 2px; }
.user-form .chk { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }

/* Toggle estilo switch (sustituye a los checkbox) */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--muted); user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { position: relative; width: 38px; height: 22px; background: #cbd5e1; border-radius: 999px; transition: background .15s; flex: 0 0 auto; }
.switch .slider::before { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary); outline-offset: 2px; }
.users-list { list-style: none; margin: 0; padding: 0; }
.user-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--border); font-size: 15px; }
.user-item .u-user { color: var(--muted); font-size: 13px; }
.user-item .u-badge { background: var(--primary); color: #fff; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 700; }
.user-item .u-off { color: var(--err); font-size: 12px; }
.user-acts { display: flex; gap: 8px; }
.mini-btn { border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; color: var(--text); }
.mini-btn:hover { background: #f1f5f9; }
.mini-btn.danger { color: var(--err); border-color: #fecaca; }
.mini-btn.danger:hover { background: #fef2f2; }

/* ---------- Historial ---------- */
.hist-sub { color: var(--muted); font-size: 14px; margin: -8px 0 18px; }
.hist-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.hist-table th, .hist-table td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--border); }
.hist-table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.hist-table tbody tr:hover { background: #f8fafc; }
.hist-empty { color: var(--muted); text-align: center; padding: 22px; }

/* Filtros y paginación del historial */
.hist-filters {
  display: flex; flex-wrap: nowrap; gap: 12px; align-items: flex-end;
  margin-bottom: 18px; padding: 16px;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 12px;
}
.hist-filters label {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.hist-filters select,
.hist-filters input[type="date"] {
  width: 100%; height: 40px; box-sizing: border-box; padding: 0 12px;
  font-size: 14px; font-family: inherit; color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
}
.hist-filters select:focus,
.hist-filters input[type="date"]:focus { border-color: var(--primary); outline: none; }
.hist-filters .ghost-btn { flex: 0 0 auto; height: 40px; padding: 0 18px; }

.hist-pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; }
.hist-pginfo { font-size: 14px; color: var(--muted); }
.hist-pager button:disabled { opacity: .45; cursor: default; }

/* ---------- Responsive (móvil / tablet) ---------- */
@media (max-width: 680px) {
  .topbar { flex-wrap: wrap; row-gap: 10px; padding: 10px 14px; }
  .topbar-center { order: -1; flex: 1 1 100%; }
  .topbar-left { flex: 1 1 auto; gap: 8px; }
  .topbar-right { flex: 1 1 auto; flex-wrap: wrap; justify-content: flex-end; gap: 2px; }
  .topbar-logo { height: 62px; }
  .app-logo { height: 40px; }
  .brand-sm { font-size: 16px; }
  .nav-link { padding: 6px 9px; font-size: 13px; }
  .user-name { display: none; }

  .container { margin: 18px auto; padding: 0 12px; }
  .card { padding: 18px; }
  .card h2 { font-size: 18px; }

  .login-card { padding: 30px 22px; }

  .actions { gap: 8px; }
  .actions button { flex: 1 1 auto; }
  .result-head { flex-direction: column; align-items: flex-start; gap: 6px; }

  .codes-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

  .user-form .uf-row { flex-direction: column; }
  .user-form .uf-footer { flex-direction: column; align-items: stretch; }
  .user-form .uf-footer button { width: 100%; }
  .user-item { flex-direction: column; align-items: flex-start; gap: 8px; }
  .user-acts { width: 100%; }

  .hist-table { font-size: 13px; }
  .hist-table th, .hist-table td { padding: 9px 5px; }
  .hist-filters { flex-wrap: wrap; }
  .hist-filters label { flex: 1 1 140px; }

  .modal { padding: 22px; }
}

/* ---------- Tarjetas (impresión) ---------- */
.print-area { display: none; }

@media print {
  @page { size: A4 portrait; margin: 0; }
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  /* Geometría idéntica al PDF (app/pdf.py): margen 12mm, gap 8mm, 2 columnas,
     tarjeta 89x50mm, esquinas 4mm. */
  .print-area {
    display: grid; position: absolute; top: 0; left: 0;
    grid-template-columns: repeat(2, 89mm); gap: 8mm; padding: 12mm;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .ticket-card {
    position: relative; width: 89mm; height: 50mm;
    background: #ececec; border-radius: 4mm; overflow: hidden;
    page-break-inside: avoid; color: #0f172a;
    font-family: Helvetica, Arial, sans-serif;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .tc-body { position: absolute; inset: 0; }
  .tc-logo { position: absolute; left: 6mm; top: 6mm; height: 13mm; width: auto; }
  .tc-hotel { position: absolute; right: 7mm; top: 8mm; text-align: right; }
  .tc-hotel-name { font-weight: bold; font-size: 12pt; color: #0f172a; }
  .tc-ticket-label { position: absolute; left: 6mm; top: 24mm; font-size: 10pt; color: #5a646e; }
  .tc-ticket-code { position: absolute; left: 6mm; top: 29mm; font-size: 22pt; font-weight: bold; color: #0f172a; }
  .tc-footer {
    position: absolute; left: 0; right: 0; bottom: 0; height: 9mm; background: #3fd4af;
    display: flex; align-items: center; justify-content: center;
    color: #ffffff; font-size: 8pt; letter-spacing: 0.3pt;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
