/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --blue:        #1e40af;
  --blue-light:  #3b82f6;
  --blue-pale:   #eff6ff;
  --red:         #dc2626;
  --green:       #16a34a;
  --orange:      #d97706;
  --gray-50:     #f9fafb;
  --gray-100:    #f3f4f6;
  --gray-200:    #e5e7eb;
  --gray-400:    #9ca3af;
  --gray-600:    #4b5563;
  --gray-800:    #1f2937;
  --gray-900:    #111827;
  --white:       #ffffff;
  --shadow-sm:   0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 16px rgba(0,0,0,.10);
  --radius:      10px;
  --header-h:    62px;
}

/* ── Reset / Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* -text-size-adjust: stop iOS Safari from auto-inflating text in landscape. */
html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  line-height: 1.55;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* ── Header ────────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
}

.site-header__inner {
  max-width: 1280px;
  margin: 0 auto;
  height: 100%;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.site-header__left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.site-header__title {
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-header__right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.site-header__user {
  font-size: 14px;
  color: var(--gray-600);
}

.site-header__logout {
  font-size: 14px;
  color: var(--gray-600);
  border: 1px solid var(--gray-200);
  padding: 5px 14px;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.site-header__logout:hover {
  background: var(--gray-100);
  color: var(--gray-800);
  text-decoration: none;
}

.site-header__logo {
  height: 38px;
  width: auto;
}

.site-header__logo--compact {
  display: none;
  height: 32px;
  width: auto;
}

/* ── Main content ──────────────────────────────────────────────────────────── */
.site-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 36px 24px 60px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 28px;
}

/* ── Tile grid ─────────────────────────────────────────────────────────────── */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.tile {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 2px solid transparent;
  transition: box-shadow .18s, border-color .18s, transform .18s;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.tile:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--blue-light);
  transform: translateY(-2px);
  text-decoration: none;
}

.tile--disabled {
  opacity: .46;
  cursor: not-allowed;
  filter: grayscale(.6);
}

.tile--disabled:hover {
  box-shadow: var(--shadow-sm);
  border-color: transparent;
  transform: none;
}

/* Drag-and-drop states */
.tile-grid .tile { cursor: grab; }
.tile-grid .tile:active { cursor: grabbing; }

.tile--ghost {
  opacity: .35;
  border: 2px dashed var(--blue-light) !important;
  background: var(--gray-50) !important;
  box-shadow: none !important;
  transform: none !important;
}

.tile--drag {
  opacity: .9;
  box-shadow: var(--shadow-md);
  transform: rotate(1.5deg) scale(1.02);
  cursor: grabbing;
}

.tile__icon {
  font-size: 32px;
  line-height: 1;
}

.tile__name {
  font-size: 17px;
  font-weight: 700;
  color: var(--gray-900);
}

.tile__meta {
  font-size: 13px;
  color: var(--gray-600);
  flex: 1;
}

.tile__badge {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 12px;
  background: var(--gray-100);
  color: var(--gray-600);
  letter-spacing: .03em;
  text-transform: uppercase;
}

.tile__badge--ok     { background: #dcfce7; color: #15803d; }
.tile__badge--warn   { background: #fef3c7; color: #b45309; }
.tile__badge--error  { background: #fee2e2; color: #b91c1c; }
.tile__badge--soon   { background: var(--gray-200); color: var(--gray-600); }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 28px;
}

.card + .card { margin-top: 20px; }

.card__title {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
}

/* ── Stats row ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-box {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}

.stat-box__value {
  font-size: 28px;
  font-weight: 800;
  color: var(--blue);
  line-height: 1.1;
}

.stat-box--error {
  border-color: #fecaca;
  background: #fef2f2;
}

.stat-box__label {
  font-size: 12px;
  color: var(--gray-600);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.form-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700, var(--gray-800));
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: 7px;
  font-size: 15px;
  color: var(--gray-900);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.18);
}

.form-hint {
  font-size: 12px;
  color: var(--gray-400);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 22px;
  border-radius: 7px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s, transform .1s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn:hover { text-decoration: none; opacity: .88; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--blue); color: var(--white); }
.btn-secondary { background: var(--gray-200); color: var(--gray-800); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-success { background: var(--green); color: var(--white); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 13px 30px; font-size: 16px; width: 100%; }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 18px;
  border: 1.5px solid transparent;
}
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-info    { background: var(--blue-pale); border-color: #bfdbfe; color: #1e40af; }
.alert-warn    { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* ── Login page ────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 44px 40px;
}

.login-card__logo {
  margin: 0 auto 28px;
  display: block;
  max-height: 52px;
  max-width: 180px;
}

.login-card__title {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 24px;
  text-align: center;
}

.login-card__footer {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--gray-600);
}

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--gray-600);
  cursor: pointer;
}

/* ── Admin table ───────────────────────────────────────────────────────────── */
.admin-table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  font-size: 14px;
}

.admin-table th,
.admin-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

.admin-table th {
  background: var(--gray-50);
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: .06em;
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--gray-50); }

.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.status-badge--active  { background: #dcfce7; color: #15803d; }
.status-badge--blocked { background: #fee2e2; color: #b91c1c; }

.feature-toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}
.feature-toggle input { opacity: 0; width: 0; height: 0; }
.feature-toggle__slider {
  position: absolute;
  inset: 0;
  background: var(--gray-200);
  border-radius: 20px;
  cursor: pointer;
  transition: background .2s;
}
.feature-toggle__slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  bottom: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.feature-toggle input:checked + .feature-toggle__slider { background: var(--blue); }
.feature-toggle input:checked + .feature-toggle__slider::before { transform: translateX(16px); }

/* ── Log viewer ────────────────────────────────────────────────────────────── */
.log-viewer {
  background: #0f172a;
  color: #94a3b8;
  border-radius: 8px;
  padding: 20px;
  font-family: 'Fira Mono', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.7;
  overflow-y: auto;
  max-height: 480px;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-viewer .log-info  { color: #7dd3fc; }
.log-viewer .log-debug { color: #94a3b8; }
.log-viewer .log-warn  { color: #fcd34d; }
.log-viewer .log-error { color: #f87171; }

/* ── Spinner ───────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner--dark {
  border-color: rgba(30,64,175,.2);
  border-top-color: var(--blue);
}

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

/* ── QR page ───────────────────────────────────────────────────────────────── */
.qr-master {
  text-align: center;
}

.qr-master__code {
  display: inline-block;
  padding: 16px;
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  margin: 20px 0;
}

.qr-master__code img,
.qr-master__code canvas,
.qr-master__code svg {
  display: block;
  width: 220px;
  height: 220px;
}

.qr-master__status {
  font-size: 14px;
  color: var(--gray-600);
  margin-top: 8px;
}

/* Mobile scanner area */
.scanner-wrap {
  position: relative;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
}

#html5-qrcode-button-camera-start,
#html5-qrcode-button-camera-stop {
  background: var(--blue) !important;
  color: var(--white) !important;
  border: none !important;
  padding: 10px 20px !important;
  border-radius: 7px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
}

/* ── Progress bar ──────────────────────────────────────────────────────────── */
.progress-bar-wrap {
  background: var(--gray-200);
  border-radius: 20px;
  height: 8px;
  overflow: hidden;
  margin: 12px 0;
}
.progress-bar {
  height: 100%;
  background: var(--blue);
  border-radius: 20px;
  transition: width .4s ease;
}

/* ── Breadcrumb ────────────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--gray-400);
  margin-bottom: 24px;
}
.breadcrumb a { color: var(--blue); }
.breadcrumb__sep { color: var(--gray-300); }

/* ── Inline action row ─────────────────────────────────────────────────────── */
.actions-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

/* ── Autocomplete dropdown ─────────────────────────────────────────────────── */
.autocomplete-wrap { position: relative; }

.autocomplete-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--white);
  border: 1.5px solid var(--blue-light);
  border-radius: 7px;
  z-index: 200;
  box-shadow: var(--shadow-md);
  max-height: 200px;
  overflow-y: auto;
  font-size: 14px;
}

.autocomplete-item {
  padding: 9px 14px;
  cursor: pointer;
}
.autocomplete-item:hover,
.autocomplete-item.active { background: var(--blue-pale); }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .site-header__logo         { display: none; }
  .site-header__logo--compact { display: block; }
  .site-header__title        { font-size: 15px; }
  .site-header__inner        { gap: 8px; }
  .site-header__right        { gap: 8px; }
}

@media (max-width: 768px) {
  .site-main { padding: 20px 16px 48px; }

  .admin-table-wrap--history { max-height: 300px; overflow-y: auto; }

  .site-header__inner { padding: 0 16px; }
  .site-header__user { display: none; }

  .tile-grid { grid-template-columns: 1fr; gap: 14px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .login-card { padding: 32px 24px; }

  .admin-table th:nth-child(4),
  .admin-table td:nth-child(4),
  .admin-table th:nth-child(5),
  .admin-table td:nth-child(5) { display: none; }

  .page-title { font-size: 20px; margin-bottom: 20px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .btn-lg { font-size: 15px; }
}

/* Prevent iOS Safari from zooming on input focus (font-size must be >= 16px) */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
select,
textarea {
  font-size: 16px !important;
}
