/* ==================================================
   GLOBAL RESET & VARIABLES
================================================== */
:root {
  --bg: #0f1724;
  --card: #0b1220;
  --accent: #06b6d4;
  --accent-hover: #0891b2;
  --success: #22c55e;
  --danger: #ef4444;
  --text: #ffffff;
  --muted: #94a3b8;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: Arial, system-ui, sans-serif;
}

/* ==================================================
   BODY – MOBILE SAFE CENTER
================================================== */
body {
  min-height: 100svh; /* mobile keyboard safe */
  background: var(--bg);
  display: flex;
  align-items: start;
  justify-content: center;
  color: var(--text);
  padding: 16px;
}

/* ==================================================
   MAIN CARD
================================================== */
.box {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  padding: 24px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.45);
  animation: fadeIn 0.5s ease;
}

/* ==================================================
   HEADINGS
================================================== */
.box h2 {
  margin-bottom: 12px;
  font-size: 24px;
}

/* ==================================================
   INPUTS
================================================== */
.box input,
.qr-input {
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 16px;
  outline: none;
}

.box input:focus,
.qr-input:focus {
  border-color: var(--accent);
}

/* ==================================================
   BUTTONS
================================================== */
.box button {
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: bold;
  color: #0f1724;
  cursor: pointer;
  transition: 0.3s ease;
}

.box button:hover {
  background: var(--accent-hover);
}

/* ==================================================
   MESSAGE & RESULT
================================================== */
#msg,
#result {
  margin-top: 14px;
  font-size: 15px;
}

.success { color: var(--success); }
.error { color: var(--danger); }

/* ==================================================
   LOADER
================================================== */
#result::after {
  content: "";
  display: block;
  margin: 12px auto 0;
  width: 26px;
  height: 26px;
  border: 3px solid var(--muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

#result.success::after,
#result.error::after {
  display: none;
}

/* ==================================================
   QR SCANNER
================================================== */
#reader {
  width: 100%;
  margin-top: 14px;
  border-radius: 12px;
  overflow: hidden;
}

#reader video {
  width: 100% !important;
  height: auto !important;
  border-radius: 12px;
}

/* ==================================================
   QR INPUT – MOBILE FIX
================================================== */
.qr-input {
  display: block; /* 🔥 mobile-e always visible */
}

/* ==================================================
   Table
================================================== */
/* RESULT ANIMATION */
.result-valid {
  color: lime;
  animation: pulse 0.6s ease-in-out;
}

.result-used {
  color: red;
  animation: shake 0.4s;
}

.result-invalid {
  color: orange;
  animation: shake 0.4s;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-6px); }
  100% { transform: translateX(0); }
}

/* HISTORY TABLE */
#historyTable {
  width: 100%;
  margin-top: 15px;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: fixed;
  word-wrap: break-word;
}

#historyTable th,
#historyTable td {
  border: 1px solid #333;
  padding: 6px;
}

#historyTable th {
  background: #111;
}

@media screen and (max-width: 400px) {
  #historyTable, #historyTable thead, #historyTable tbody, #historyTable th, #historyTable td, #historyTable tr {
    display: block;
  }
  #historyTable thead tr { display: none; }
  #historyTable tbody tr {
    margin-bottom: 10px;
    border: 1px solid #444;
    padding: 5px;
  }
  #historyTable td {
    text-align: right;
    padding-left: 50%;
    position: relative;
  }
  #historyTable td::before {
    content: attr(data-label);
    position: absolute;
    left: 10px;
    width: 45%;
    text-align: left;
    font-weight: bold;
  }
}

/* PAGINATION BAR */
#pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 15px 0;
  flex-wrap: wrap;
}

#pagination button {
  background: #1f2933;
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  width: auto!important;
}

#pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#pagination .active {
  background: #06b6d4;
  color: #000;
  font-weight: bold;
}

/* Clear history */
#clearHistoryBtn {
  background: #7f1d1d;
}

/* Mobile optimization */
@media (max-width: 600px) {
  #pagination button {
    padding: 6px 10px;
    font-size: 13px;
  }
}


/* ==================================================
   ANIMATIONS
================================================== */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* ==================================================
   MOBILE OPTIMIZATION
================================================== */
@media screen and (max-width: 480px) {
  body {
    padding: 0;
    align-items: flex-start; /* keyboard issue fix */
  }

  .box {
    width: 100%;
    max-width: 100%;         /* 🔥 important */
    min-height: 100svh;      /* full screen height */
    border-radius: 0;        /* mobile app look */
    margin: 0;
    padding: 20px;
  }

  .box h2 {
    font-size: 22px;
  }

  .box button,
  .box input,
  .qr-input {
    font-size: 15px;
  }
}
@media screen and (max-width: 768px) {
  .box {
    max-width: 100%;
  }
}
