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

body {
  background-color: #0f172a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #f1f5f9;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Page router ── */
.page { display: none; flex-direction: column; min-height: 100dvh; }
.page.active { display: flex; }
.hidden { display: none !important; }

/* ═══════════════════════════════════════
   SPLASH
═══════════════════════════════════════ */
#page-splash {
  background: #0f172a;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
}
#splash-logo {
  width: 180px;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
#splash-logo.show     { opacity: 1; transform: scale(1); }
#splash-logo.fade-out { opacity: 0; transform: scale(1.08); }
#splash-tagline {
  color: #93c5fd;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  opacity: 0;
  transition: opacity 0.5s ease 0.3s;
  text-transform: uppercase;
}
#splash-tagline.show { opacity: 1; }
.splash-spinner {
  width: 28px; height: 28px;
  border: 3px solid #1e3a5f;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  opacity: 0;
  transition: opacity 0.4s ease 0.8s;
}
.splash-spinner.show { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════
   LOGIN
═══════════════════════════════════════ */
#page-login {
  background: linear-gradient(160deg, #0f172a 0%, #1e3a5f 100%);
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: rgba(30,41,59,0.9);
  border: 1px solid #334155;
  border-radius: 24px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  backdrop-filter: blur(12px);
  animation: slideUp 0.4s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}
.login-logo  { width: 100px; }
.login-title { font-size: 1.3rem; font-weight: 700; color: #fff; text-align: center; line-height: 1.3; }
.login-sub   { font-size: 0.8rem; color: #64748b; text-align: center; }
.login-form  { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.login-hint  { font-size: 0.72rem; color: #475569; text-align: center; }

/* ── Form inputs ── */
.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label { font-size: 0.78rem; color: #94a3b8; font-weight: 500; }
.input-group input {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px 14px;
  color: #f1f5f9;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}
.input-group input:focus { border-color: #3b82f6; }
.input-group input[readonly] { color: #475569; cursor: default; user-select: all; }

/* ── Buttons ── */
button {
  cursor: pointer; font-size: 0.9rem; font-weight: 600;
  border: none; border-radius: 14px; padding: 13px 18px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: filter 0.15s, transform 0.1s;
}
button:active { transform: scale(0.97); }
button:hover  { filter: brightness(1.12); }

.btn-primary {
  width: 100%; background: #1d4ed8; color: #fff;
  border: none; border-radius: 14px; padding: 14px;
  font-size: 0.95rem; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: filter 0.15s, transform 0.1s;
  margin-top: 4px;
}
.btn-primary:hover  { filter: brightness(1.15); }
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  flex: 1; background: #334155; color: #94a3b8;
  border: none; border-radius: 14px; padding: 13px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: filter 0.15s;
}
.btn-secondary:hover { filter: brightness(1.2); }

/* ═══════════════════════════════════════
   USER DATA MODAL
═══════════════════════════════════════ */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  width: 100%; max-width: 480px;
  background: #1e293b;
  border-radius: 24px 24px 0 0;
  padding: 28px 24px 40px;
  display: flex; flex-direction: column;
  gap: 16px;
  animation: sheetUp 0.35s ease;
  max-height: 92dvh;
  overflow-y: auto;
}
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.modal-handle {
  width: 40px; height: 4px;
  background: #475569;
  border-radius: 4px;
  margin: 0 auto -4px;
}
.modal-title { font-size: 1.1rem; font-weight: 700; color: #fff; }
.modal-sub   { font-size: 0.78rem; color: #64748b; margin-top: -8px; }
.modal-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-grid .full { grid-column: 1 / -1; }
.modal-sheet .input-group input { background: #0f172a; }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }

/* ═══════════════════════════════════════
   SCANNER PAGE
═══════════════════════════════════════ */
#page-scanner {
  background-color: #0f172a;
  flex-direction: column;
}

/* ── Header ── */
.header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #1e3a5f;
  background: #0f172a;
  position: sticky; top: 0; z-index: 10;
}
.header-burger {
  width: 38px; height: 38px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background 0.15s;
}
.header-burger:hover { background: #334155; }
.header-burger svg { width: 18px; height: 18px; color: #94a3b8; }
.header-info { flex: 1; }
.header-info h1 { font-size: 1rem; font-weight: 700; color: #fff; line-height: 1.2; }
.header-info p  { font-size: 0.7rem; color: #64748b; }
.header-avatar {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #1d4ed8, #7c3aed);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; color: #fff;
  flex-shrink: 0; cursor: pointer;
}

/* ── Sidebar ── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); z-index: 150;
  backdrop-filter: blur(3px);
}
.sidebar-overlay.open { display: block; }
.sidebar {
  position: fixed; top: 0; left: -320px; bottom: 0;
  width: 300px; background: #1e293b;
  border-right: 1px solid #334155;
  z-index: 151; transition: left 0.3s ease;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar.open { left: 0; }
.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid #334155;
  display: flex; align-items: center; gap: 12px;
}
.sidebar-avatar {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, #1d4ed8, #7c3aed);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.sidebar-user-name { font-size: 0.95rem; font-weight: 700; color: #fff; }
.sidebar-user-id   { font-size: 0.72rem; color: #64748b; font-family: monospace; }
.sidebar-section   { padding: 16px 20px 8px; font-size: 0.7rem; font-weight: 700; color: #475569; text-transform: uppercase; letter-spacing: 0.08em; }
.sidebar-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; cursor: pointer;
  transition: background 0.15s; color: #94a3b8;
  font-size: 0.9rem;
}
.sidebar-item:hover         { background: #334155; color: #fff; }
.sidebar-item svg           { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-item.danger        { color: #f87171; }
.sidebar-item.danger:hover  { background: #2d0a0a; color: #fca5a5; }
.sidebar-divider { height: 1px; background: #334155; margin: 8px 0; }
.sidebar-user-info {
  padding: 8px 20px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.sui-row   { display: flex; justify-content: space-between; }
.sui-label { font-size: 0.72rem; color: #475569; }
.sui-val   { font-size: 0.72rem; color: #94a3b8; font-weight: 600; }

/* ── Main ── */
main {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center;
  padding: 20px 16px 32px;
  gap: 20px;
}

/* ── Install banner ── */
#install-banner {
  display: none; width: 100%; max-width: 360px;
  background: #1e40af; border-radius: 14px;
  padding: 12px 16px; align-items: center; gap: 12px;
}
#install-banner span { flex: 1; font-size: 0.82rem; color: #bfdbfe; }
#btn-install {
  background: #fff; color: #1d4ed8;
  font-size: 0.8rem; padding: 8px 14px;
  border-radius: 10px; flex-shrink: 0;
  border: none; cursor: pointer; font-weight: 600;
}
#btn-install-dismiss {
  background: transparent; color: #93c5fd;
  font-size: 0.85rem; padding: 8px;
  border-radius: 10px; flex-shrink: 0;
  border: none; cursor: pointer;
}

/* ── Scanner box ── */
.scanner-wrap {
  width: 100%; max-width: 360px; position: relative;
  border-radius: 18px; overflow: hidden;
  border: 2px solid #3b82f6;
  box-shadow: 0 0 32px rgba(59,130,246,0.35);
  background: #000;
}
#qr-reader                             { width: 100%; }
#qr-reader video                       { width: 100% !important; display: block !important; }
#qr-reader img                         { display: none !important; }
#qr-reader__dashboard_section_swaplink,
#qr-reader__status_span,
#qr-reader__header_message,
#qr-reader__filescan_input,
#qr-reader__dashboard                  { display: none !important; }

/* corner decorations */
.corner { position: absolute; width: 22px; height: 22px; z-index: 5; pointer-events: none; }
.corner.tl { top: 10px; left: 10px;  border-top:    2px solid #60a5fa; border-left:  2px solid #60a5fa; border-radius: 4px 0 0 0; }
.corner.tr { top: 10px; right: 10px; border-top:    2px solid #60a5fa; border-right: 2px solid #60a5fa; border-radius: 0 4px 0 0; }
.corner.bl { bottom: 10px; left: 10px;  border-bottom: 2px solid #60a5fa; border-left:  2px solid #60a5fa; border-radius: 0 0 0 4px; }
.corner.br { bottom: 10px; right: 10px; border-bottom: 2px solid #60a5fa; border-right: 2px solid #60a5fa; border-radius: 0 0 4px 0; }

/* scan line */
.scan-line {
  position: absolute; left: 10%; right: 10%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #3b82f6, transparent);
  animation: scanline 2s linear infinite;
  z-index: 4; border-radius: 2px; pointer-events: none;
  display: none;
}
@keyframes scanline {
  0%  { top: 15%; }
  50% { top: 80%; }
  100%{ top: 15%; }
}

/* ── Scanner controls ── */
.btn-row { display: flex; gap: 10px; width: 100%; max-width: 360px; }
#btn-start  { flex: 1; background: #16a34a; color: #fff; }
#btn-stop   { flex: 1; background: #dc2626; color: #fff; }
#btn-switch { background: #1e40af; color: #fff; }

/* ── Result card ── */
#result-section { width: 100%; max-width: 360px; display: none; flex-direction: column; gap: 12px; }
.result-card { border-radius: 16px; padding: 16px; background: #1e293b; border: 1px solid #334155; }
.result-card.success { border-color: #16a34a; background: #052e16; }
.result-card.error   { border-color: #dc2626; background: #2d0a0a; }
.result-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.result-icon { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.result-icon.success { background: #14532d; }
.result-icon.error   { background: #450a0a; }
.result-icon svg { width: 22px; height: 22px; }
.result-title { font-weight: 700; font-size: 1rem; }
.result-card.success .result-title { color: #4ade80; }
.result-card.error   .result-title { color: #f87171; }
.result-body { font-size: 0.82rem; color: #94a3b8; line-height: 1.7; }
.result-body strong { color: #e2e8f0; font-weight: 600; }
.result-raw {
  margin-top: 8px; padding: 10px 12px;
  background: #0f172a; border-radius: 10px;
  font-size: 0.78rem; color: #7dd3fc;
  word-break: break-all; font-family: monospace;
}
#btn-scan-again { width: 100%; background: #1d4ed8; color: #fff; padding: 14px; font-size: 0.95rem; }

/* ── History ── */
#history-section { width: 100%; max-width: 360px; }
.history-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.history-header span { font-size: 0.85rem; font-weight: 600; color: #94a3b8; }
#btn-clear-history {
  background: transparent; color: #64748b;
  font-size: 0.75rem; padding: 4px 10px;
  border: 1px solid #334155; border-radius: 8px;
}
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex; align-items: center; gap: 10px;
  background: #1e293b; border-radius: 12px;
  padding: 10px 12px; border: 1px solid #334155;
}
.hi-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.hi-dot.success { background: #4ade80; }
.hi-dot.error   { background: #f87171; }
.hi-text { flex: 1; font-size: 0.8rem; overflow: hidden; }
.hi-text .hi-name { font-weight: 600; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hi-text .hi-time { color: #64748b; font-size: 0.72rem; }
.hi-badge { font-size: 0.68rem; padding: 2px 8px; border-radius: 20px; font-weight: 700; }
.hi-badge.success { background: #14532d; color: #4ade80; }
.hi-badge.error   { background: #450a0a; color: #f87171; }

/* ── Toast ── */
#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1e293b; color: #f1f5f9;
  padding: 12px 22px; border-radius: 12px;
  font-size: 0.85rem; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  border: 1px solid #334155;
  transition: transform 0.3s ease;
  z-index: 300; white-space: nowrap;
}
#toast.show { transform: translateX(-50%) translateY(0); }
