/* ==============================
   Hotelia Pasaport — Style v2
   ============================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

:root {
  --primary: #4B2EA8;
  --primary-dark: #3a2285;
  --primary-light: #7B5CE5;
  --accent: #F59E0B;
  --success: #059669;
  --success-bg: #ECFDF5;
  --success-border: #6EE7B7;
  --danger: #DC2626;
  --danger-bg: #FEF2F2;
  --bg: #F0EEF8;
  --surface: #FFFFFF;
  --surface2: #F8F7FC;
  --border: #E4E1F5;
  --text: #1A1636;
  --text-muted: #6B6A8A;
  --text-light: #9B99B5;
  --shadow: 0 1px 3px rgba(75,46,168,0.08), 0 4px 16px rgba(75,46,168,0.06);
  --shadow-lg: 0 8px 32px rgba(75,46,168,0.15);
  --radius: 14px;
  --radius-sm: 9px;
  --font: 'DM Sans', -apple-system, sans-serif;
  --font-mono: 'DM Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

#app { max-width: 480px; margin: 0 auto; min-height: 100vh; }
.screen { min-height: 100vh; }
.screen.hidden { display: none !important; }
.hidden { display: none !important; }

/* ======================== LOGIN ======================== */
#screen-login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(160deg, #3a2285 0%, #6B3FA0 50%, #4B2EA8 100%);
}

.login-logo { margin-bottom: 28px; text-align: center; }

.login-logo-wrap {
  margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(to bottom, #4B2EA8 50%, #6B3FA0 50%);
  padding: 12px 20px;
  border-radius: 10px;
}

.login-logo-img {
  max-width: 160px; height: auto;
  object-fit: contain;
  display: block;
}

.login-logo h1 {
  font-size: 1.45rem; font-weight: 700;
  color: #fff; letter-spacing: -0.3px;
}

.login-logo p { font-size: 13px; color: rgba(255,255,255,0.6); margin-top: 4px; }

#form-login {
  background: #fff;
  border-radius: 20px;
  padding: 26px 22px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.form-group { margin-bottom: 14px; }
.form-group-checkbox label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 400; }
.form-group-checkbox input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

.form-group label {
  display: block;
  font-size: 11.5px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: 5px;
}

.form-group input {
  width: 100%; padding: 12px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 15px; color: var(--text);
  background: var(--surface2);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}

.form-group input:focus {
  outline: none; border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 3px rgba(75,46,168,0.12);
}

.form-group input::placeholder { color: var(--text-light); }

/* ======================== BUTTONS ======================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  font-family: var(--font); font-size: 15px; font-weight: 600;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.18s ease;
  -webkit-appearance: none;
  user-select: none;
}

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

.btn-primary {
  background: var(--primary); color: #fff;
  width: 100%; padding: 15px;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 14px rgba(75,46,168,0.35);
  margin-top: 6px;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
  background: rgba(75,46,168,0.12); color: var(--primary);
  border: 1px solid rgba(75,46,168,0.25);
  width: 100%; padding: 14px;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px;
  cursor: pointer; transition: all 0.2s;
}
.btn-secondary:hover { background: rgba(75,46,168,0.18); }

.btn-ghost {
  background: transparent; color: var(--text-muted);
  padding: 9px 14px; font-size: 14px; font-weight: 500; border: none;
}

.btn-ghost:hover { color: var(--text); background: rgba(0,0,0,0.05); }

.msg-login {
  font-size: 13px; color: var(--danger);
  text-align: center; margin-top: 8px;
  min-height: 18px;
}

/* ======================== RACK ======================== */
#screen-rack { padding: 0; background: var(--bg); }

.rack-header {
  background: var(--primary);
  padding: 16px 20px 20px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
}

.rack-header h1 { font-size: 1.1rem; font-weight: 700; color: #fff; }

.rack-header-actions { display: flex; align-items: center; gap: 8px; }

.btn-header-icon {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.9);
  border: none; border-radius: 8px;
  padding: 8px 12px; font-size: 15px;
  cursor: pointer; transition: background 0.15s;
  font-family: var(--font); font-weight: 600;
}

.btn-header-icon:hover { background: rgba(255,255,255,0.25); }

#screen-room-choice { padding: 0; background: var(--bg); }
.room-choice-body { padding: 24px 20px; }
.room-choice-hint { margin-bottom: 20px; color: var(--text-muted); font-size: 14px; }
.room-choice-body .btn { display: block; width: 100%; margin-bottom: 12px; }
.room-choice-body .btn:last-of-type { margin-bottom: 0; }
.room-choice-edit-list { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.room-choice-edit-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text); }
.btn-room-choice-visitor {
  display: block; width: 100%;
  padding: 14px 16px; margin-bottom: 8px;
  font-family: var(--font); font-size: 15px; font-weight: 500;
  text-align: left; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: background 0.15s;
}
.btn-room-choice-visitor:hover { background: var(--border); }

.rack-legend {
  display: flex; gap: 16px;
  padding: 10px 20px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

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

.legend-dot { width: 9px; height: 9px; border-radius: 50%; }
.legend-dot.empty { background: #10B981; }
.legend-dot.full { background: #3B82F6; }

.rack-body { padding: 14px; }

.rack-loading {
  display: flex; flex-direction: column; align-items: center;
  padding: 48px 0; color: var(--text-muted); font-size: 14px;
}

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin-bottom: 12px;
}

.rack-error {
  background: var(--danger-bg);
  border: 1px solid #FECACA;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--danger);
  margin-bottom: 12px;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: 10px;
}

.room-btn {
  aspect-ratio: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  font-family: var(--font); font-size: 1rem; font-weight: 700;
  border-radius: 12px; border: 2px solid transparent;
  cursor: pointer; transition: all 0.15s ease;
  box-shadow: var(--shadow);
}

.room-btn:active { transform: scale(0.92); }

.room-btn .room-num { font-size: 1rem; line-height: 1; }
.room-btn .room-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  flex-shrink: 0;
}
.room-btn .room-count {
  font-size: 0.7rem; font-weight: 600;
  opacity: 0.85;
}

.room-btn.room-empty {
  border-color: #A7F3D0;
  background: linear-gradient(145deg, #ECFDF5, #D1FAE5);
  color: #065F46;
}

.room-btn.room-full {
  border-color: #BFDBFE;
  background: linear-gradient(145deg, #EFF6FF, #DBEAFE);
  color: #1E40AF;
}

.room-btn.room-empty .room-status-dot { background: #10B981; }
.room-btn.room-full .room-status-dot { background: #3B82F6; }

/* ======================== SCAN ======================== */
#screen-scan {
  background: #0A0916;
  color: #fff;
  min-height: 100vh;
  display: flex; flex-direction: column;
}

.scan-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
}

.scan-room-badge {
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.85);
  padding: 6px 14px;
  border-radius: 20px; font-size: 13px; font-weight: 600;
  border: 1px solid rgba(255,255,255,0.15);
}

.btn-cancel-dark {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 8px 14px;
  font-family: var(--font); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background 0.15s;
}

.btn-cancel-dark:hover { background: rgba(255,255,255,0.18); }

.scan-tip {
  font-size: 12px; color: rgba(255,255,255,0.5);
  text-align: center; padding: 6px 20px 10px;
  line-height: 1.5;
}

.scan-tip strong { color: rgba(255,255,255,0.8); }

.video-wrap {
  position: relative;
  width: 100%; background: #000;
  overflow: hidden;
  flex-shrink: 0;
  max-height: 55vh;
}

#video { width: 100%; height: 100%; object-fit: cover; display: block; }
#canvas { display: none; }

/* Viewfinder */
.mrz-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-end;
  padding-bottom: 18px;
}

.mrz-guide-text {
  font-size: 11px; font-weight: 600;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 7px;
}

.mrz-frame {
  width: calc(100% - 28px);
  height: 72px;
  border: 2px solid rgba(123, 92, 229, 0.8);
  border-radius: 6px;
  position: relative;
  background: rgba(123, 92, 229, 0.08);
  box-shadow: 0 0 0 2000px rgba(0,0,0,0.5);
}

.mrz-frame .corner {
  position: absolute;
  width: 18px; height: 18px;
  border-color: var(--accent);
  border-style: solid;
}

.mrz-frame .corner-tl { top: -2px; left: -2px; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.mrz-frame .corner-tr { top: -2px; right: -2px; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.mrz-frame .corner-bl { bottom: -2px; left: -2px; border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.mrz-frame .corner-br { bottom: -2px; right: -2px; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

.mrz-scan-line {
  position: absolute; left: 2px; right: 2px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scanAnim 2.2s ease-in-out infinite;
  border-radius: 1px;
}

@keyframes scanAnim {
  0% { top: 4px; opacity: 0; }
  10% { opacity: 1; }
  85% { top: calc(100% - 6px); opacity: 1; }
  100% { top: calc(100% - 6px); opacity: 0; }
}

.scan-footer {
  flex: 1;
  padding: 14px 16px;
  background: #0A0916;
  display: flex; flex-direction: column; justify-content: center;
  gap: 10px;
}

.scan-actions { display: flex; gap: 10px; }

.btn-scan-primary {
  flex: 1;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: 15px;
  font-family: var(--font); font-size: 15px; font-weight: 700;
  cursor: pointer; transition: all 0.18s;
  box-shadow: 0 4px 16px rgba(75,46,168,0.45);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}

.btn-scan-primary:active { transform: scale(0.97); }
.btn-scan-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-scan-secondary {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.8);
  border: 1.5px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-sm);
  padding: 15px 18px;
  font-family: var(--font); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
  display: flex; align-items: center; gap: 6px;
}

.btn-scan-secondary:hover { background: rgba(255,255,255,0.14); }
.btn-scan-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.scan-feedback {
  text-align: center; font-size: 13px; min-height: 20px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}

.scan-feedback.idle { color: rgba(255,255,255,0.35); }
.scan-feedback.scanning { color: var(--accent); }
.scan-feedback.error { color: #F87171; }

.dot-pulse { display: inline-flex; gap: 4px; }
.dot-pulse span {
  width: 5px; height: 5px; background: var(--accent); border-radius: 50%;
  animation: dotPulse 1.2s ease-in-out infinite;
}
.dot-pulse span:nth-child(2) { animation-delay: 0.18s; }
.dot-pulse span:nth-child(3) { animation-delay: 0.36s; }

@keyframes dotPulse {
  0%,100% { transform: scale(0.6); opacity: 0.4; }
  50% { transform: scale(1.1); opacity: 1; }
}

/* ======================== CONFIRM ======================== */
#screen-confirm { background: var(--bg); }

.confirm-header {
  background: var(--primary);
  padding: 16px 20px 18px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  display: flex; align-items: center; justify-content: space-between;
}

.confirm-header-title h1 { font-size: 1.05rem; font-weight: 700; color: #fff; }
.confirm-header-title p { font-size: 12px; color: rgba(255,255,255,0.6); margin-top: 2px; }

.btn-back-white {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.9);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px; padding: 8px 14px;
  font-family: var(--font); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background 0.15s;
}

.btn-back-white:hover { background: rgba(255,255,255,0.22); }

.confirm-body { padding: 14px; }

/* OCR Summary */
.ocr-summary {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--success-border);
  padding: 12px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.ocr-summary-header {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 700;
  color: var(--success);
  text-transform: uppercase; letter-spacing: 0.7px;
  margin-bottom: 10px;
}

.ocr-ok-dot {
  width: 8px; height: 8px;
  background: var(--success); border-radius: 50%;
  flex-shrink: 0;
}

.ocr-chips { display: flex; flex-wrap: wrap; gap: 5px; }

.ocr-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 9px;
  font-size: 12.5px; color: var(--text);
}

.ocr-chip .cl { font-size: 10.5px; font-weight: 600; color: var(--text-muted); }

/* Form sections */
.form-section {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px 14px 4px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 10.5px; font-weight: 700;
  color: var(--primary);
  text-transform: uppercase; letter-spacing: 0.8px;
  margin-bottom: 12px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--border);
}

.field-row { display: flex; gap: 10px; }
.field-row .fld { flex: 1; }

.fld { margin-bottom: 12px; }

.fld label {
  display: block;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted); letter-spacing: 0.1px;
  margin-bottom: 4px;
}

.fld input, .fld select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 15px; color: var(--text);
  background: var(--surface2);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none; appearance: none;
}

.fld 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 fill='%236B6A8A' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 10px;
  padding-right: 32px;
  cursor: pointer;
}

.fld input:focus, .fld select:focus {
  outline: none; border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 3px rgba(75,46,168,0.1);
}

.fld input::placeholder { color: var(--text-light); }

.fld-hint {
  display: block; font-size: 10.5px; color: var(--text-light); margin-top: 3px;
}

.confirm-actions { padding: 0 0 28px; }

.btn-save {
  width: 100%;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: 16px;
  font-family: var(--font); font-size: 16px; font-weight: 700;
  cursor: pointer; transition: all 0.18s;
  box-shadow: 0 4px 16px rgba(75,46,168,0.35);
  display: flex; align-items: center; justify-content: center; gap: 10px;
}

.btn-save:hover { background: var(--primary-dark); }
.btn-save:active { transform: scale(0.98); }
.btn-save:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

.save-error {
  background: var(--danger-bg);
  border: 1px solid #FECACA;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px; color: var(--danger);
  margin-top: 10px;
}

/* ======================== RESULT ======================== */
#screen-result {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 28px 20px;
  background: var(--bg);
}

.result-actions-wrap {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 20px;
}

.result-card {
  background: #fff;
  border-radius: 20px;
  padding: 36px 24px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  width: 100%;
  animation: fadeIn 0.35s ease;
}

.result-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px;
  font-size: 32px;
}

.result-icon.ok { background: var(--success-bg); border: 2px solid var(--success-border); }
.result-icon.err { background: var(--danger-bg); border: 2px solid #FECACA; }

.result-title { font-size: 1.25rem; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.result-detail { font-size: 14px; color: var(--text-muted); line-height: 1.6; margin-bottom: 28px; }

/* ======================== UTILS ======================== */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.input-file-hidden { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

@media (max-width: 380px) {
  .room-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
  .field-row { flex-direction: column; gap: 0; }
}
