/* ==========================================================================
   linkmatter - Flat & Rounded Design System
   Rules: Strict Flat (No borders, No shadows, No gradients, No blur/transparency)
   Palette: 60% rgb(240, 240, 240), 30% rgb(40, 40, 40), 10% rgb(0, 170, 70)
   Typography: Fredoka (Playful yet Professional) & JetBrains Mono
   ========================================================================== */

:root {
  /* 60-30-10 Color System */
  --bg-main: rgb(240, 240, 240);
  --text-main: rgb(40, 40, 40);
  --accent: rgb(0, 170, 70);
  --accent-dark: rgb(0, 140, 58);
  --accent-soft: rgb(220, 242, 228);

  /* Auxiliary & Surface Tokens */
  --surface-card: rgb(255, 255, 255);
  --surface-dark: rgb(40, 40, 40);
  --text-muted: rgb(120, 120, 120);
  --danger: rgb(225, 45, 57);
  --danger-soft: rgb(254, 232, 234);

  /* Typography */
  --font-main: 'Fredoka', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Geometric Roundness Scale */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-sheet: 28px;
  --radius-pill: 9999px;
}

/* ==========================================================================
   Global Reset & Baseline
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: var(--font-main);
  border: none;
  box-shadow: none;
}

[x-cloak] {
  display: none !important;
}

html,
body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #000000;
  color: var(--text-main);
  -webkit-tap-highlight-color: transparent;
}

code,
pre,
.mono {
  font-family: var(--font-mono);
}

/* ==========================================================================
   Camera Scanner Viewport & Overlay
   ========================================================================== */
video,
#overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#overlay {
  pointer-events: none;
  z-index: 1;
}

/* ==========================================================================
   Top Status Bar (Flat Opaque Overlays on Camera)
   ========================================================================== */
.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: max(14px, env(safe-area-inset-top, 14px)) 16px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: auto;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  background: var(--surface-dark);
  padding: 6px 14px 6px 8px;
  border-radius: var(--radius-pill);
  user-select: none;
}

.app-logo-img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: block;
}

.user-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-dark);
  padding: 5px 6px 5px 12px;
  border-radius: var(--radius-pill);
}

.user-email {
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-admin-nav {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: opacity 0.15s ease;
}

.btn-admin-nav:hover {
  opacity: 0.9;
}

.btn-logout {
  background: var(--accent);
  color: #ffffff;
  border-radius: var(--radius-pill);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn-logout:active {
  opacity: 0.85;
}

.btn-login {
  background: var(--accent);
  color: #ffffff;
  border-radius: var(--radius-pill);
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn-login:active {
  opacity: 0.85;
}

/* ==========================================================================
   Bottom Sheet Panel (Strictly Flat & Rounded)
   ========================================================================== */
#bottom-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  background: var(--bg-main);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 14px 20px max(24px, env(safe-area-inset-bottom, 24px));
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-top-row {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  height: 14px;
  cursor: pointer;
  padding: 2px 0;
}

.panel-drag-pill {
  width: 44px;
  height: 5px;
  background-color: rgb(205, 205, 205);
  border-radius: var(--radius-pill);
}

.panel-loading {
  padding: 24px 0;
  text-align: center;
}

.loading-text {
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 600;
}

.panel-content {
  display: flex;
  flex-direction: column;
}

/* Key-Value Display List */
.kv-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 44vh;
  overflow-y: auto;
}

.kv-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.kv-key {
  flex: 0 0 35%;
  background-color: var(--surface-dark);
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  word-break: break-word;
}

.kv-val {
  flex: 1;
  background-color: var(--surface-card);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  word-break: break-word;
}

.empty-state {
  background: var(--surface-card);
  color: var(--text-muted);
  border-radius: var(--radius-md);
  padding: 20px 16px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

/* Scanned Generic QR Text Box */
.scanned-text-box {
  background-color: var(--surface-card);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  max-height: 40vh;
  overflow-y: auto;
  font-family: inherit;
}

.panel-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.unclaimed-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.not-found-state {
  text-align: center;
  padding: 8px 0;
}

/* ==========================================================================
   Flat Standard Button System
   ========================================================================== */
.btn {
  border-radius: var(--radius-md);
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  font-family: var(--font-main);
  transition: opacity 0.15s ease;
}

.btn:active {
  opacity: 0.85;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-dark {
  background-color: var(--accent);
  color: #ffffff;
}

.btn-dark:hover {
  background-color: var(--accent-dark);
}

.btn-light {
  background-color: var(--surface-card);
  color: var(--text-main);
}

.btn-open-url {
  text-decoration: none;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--accent);
  color: #ffffff;
}

/* ==========================================================================
   Edit Modal Dialog (Solid Flat Overlay & Card)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(40, 40, 40, 0.75);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: var(--bg-main);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 22px;
  gap: 16px;
  animation: modal-appear 0.18s ease-out;
}

@keyframes modal-appear {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-main);
}

.btn-close-modal {
  background: var(--surface-card);
  color: var(--text-main);
  border-radius: var(--radius-pill);
  width: 34px;
  height: 34px;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
  transition: opacity 0.15s ease;
}

.btn-close-modal:active {
  opacity: 0.8;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.edit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 46vh;
  overflow-y: auto;
}

.edit-row {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
}

.edit-key-input {
  flex: 0 0 35%;
  background-color: var(--surface-dark);
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 700;
  outline: none;
  font-family: var(--font-main);
}

.edit-key-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.edit-val-input {
  flex: 1;
  background-color: var(--surface-card);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  outline: none;
  font-family: var(--font-main);
}

.edit-val-input::placeholder {
  color: var(--text-muted);
}

.btn-remove-row {
  flex: 0 0 36px;
  height: 42px;
  background-color: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-md);
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-add-field {
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 700;
  background-color: var(--accent-soft);
  color: var(--accent-dark);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

/* ==========================================================================
   Admin Dashboard Layout & Components
   Clean 60-30-10 Flat Palette with Fredoka Rounded UI
   ========================================================================== */
.admin-body {
  width: 100%;
  min-height: 100vh;
  height: auto;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-main);
}

/* Access Gate / Login Screen */
.admin-gate-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.admin-gate-card {
  background: var(--surface-card);
  border-radius: var(--radius-xl);
  max-width: 420px;
  width: 100%;
  padding: 40px 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.gate-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.gate-logo-grayscale {
  filter: grayscale(1) opacity(0.5);
}

.gate-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
}

.gate-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
  font-weight: 500;
}

.gate-spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.btn-gate-action {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 700;
  background: var(--surface-dark);
  color: #ffffff;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.btn-gate-accent {
  background: var(--accent);
  color: #ffffff;
}

.btn-gate-accent:hover {
  background: var(--accent-dark);
}

.gate-badge-404 {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
}

.gate-actions-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.gate-link-back {
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  margin-top: 4px;
  transition: opacity 0.15s ease;
}

.gate-link-back:hover {
  text-decoration: underline;
  opacity: 0.9;
}

/* Admin Dashboard Container */
.admin-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 20px 80px;
}

/* Admin Top Header */
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 24px;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-logo-img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.admin-brand-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-brand-text .brand-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.2px;
}

.admin-badge {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
}

.admin-user-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-scanner-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-card);
  color: var(--text-main);
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.nav-scanner-btn:hover {
  background: var(--surface-dark);
  color: #ffffff;
}

.admin-user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-card);
  padding: 5px 6px 5px 12px;
  border-radius: var(--radius-pill);
}

.admin-email {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-user-pill .btn-logout {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
}

.admin-user-pill .btn-logout:hover {
  background: var(--danger);
  color: #ffffff;
}

/* Dashboard Action Bar */
.admin-main {
  margin-top: 16px;
}

.admin-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.3px;
}

.page-subtitle {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-add-pack {
  width: auto;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  background: var(--accent);
  color: #ffffff;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
}

.btn-add-pack:hover {
  background: var(--accent-dark);
}

.btn-content-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

.btn-spinner-dark {
  border-color: rgba(0, 0, 0, 0.2);
  border-top-color: #000000;
}

/* Feedback Alert / Toast */
.toast-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 600;
  animation: modal-appear 0.2s ease-out;
}

.toast-success {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.toast-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.toast-close {
  background: none;
  color: inherit;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

/* Batches List */
.packs-loading,
.empty-packs-state {
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  padding: 56px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
}

.empty-icon-box {
  font-size: 38px;
  margin-bottom: 4px;
}

.empty-title {
  color: var(--text-main);
  font-size: 18px;
  font-weight: 700;
}

.empty-desc {
  font-size: 14px;
  font-weight: 500;
  max-width: 320px;
  line-height: 1.5;
  color: var(--text-muted);
}

.packs-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Pack Card (Item Row) */
.pack-card {
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  transition: opacity 0.15s ease;
}

.pack-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
}

.pack-date {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.2px;
}

.pack-id-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pack-id-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.pack-id-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  background: var(--bg-main);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-copy-id {
  background: var(--bg-main);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
}

.btn-copy-id:hover {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.pack-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}

.badge-count {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

.btn-toggle-codes {
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 0.15s ease;
}

.btn-toggle-codes:hover {
  color: var(--text-main);
}

/* Pack Action Buttons (Right) */
.pack-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-export {
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-main);
  transition: opacity 0.15s ease;
}

.btn-export-content {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-export-pdf {
  background: var(--accent);
  color: #ffffff;
}

.btn-export-pdf:hover {
  background: var(--accent-dark);
}

.btn-export-csv {
  background: var(--bg-main);
  color: var(--text-main);
}

.btn-export-csv:hover {
  background: var(--surface-dark);
  color: #ffffff;
}

.btn-export:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Expandable Codes Drawer */
.pack-codes-drawer {
  width: 100%;
  margin-top: 12px;
  padding-top: 16px;
}

.codes-loading {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  padding: 12px 0;
}

.codes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
}

.code-pill {
  background: var(--bg-main);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.code-num {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
}

.code-text {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.5px;
}

.code-status {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
}

.status-unclaimed {
  background: var(--surface-card);
  color: var(--text-muted);
}

.status-claimed {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

/* Mobile Responsiveness */
@media (max-width: 640px) {
  .admin-container {
    padding: 12px 14px 60px;
  }

  .pack-card {
    flex-direction: column;
    align-items: stretch;
  }

  .pack-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .admin-action-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-add-pack {
    width: 100%;
    justify-content: center;
  }
}
