/* ============================================================
   レゴ在庫管理 - スタイルシート
   ============================================================ */

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

:root {
  --lego-red: #E3000B;
  --lego-red-dark: #B50009;
  --lego-yellow: #FFD700;
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --border: #E0E0E0;
  --text-primary: #1A1A2E;
  --text-secondary: #6B7280;
  --text-hint: #9CA3AF;
  --success: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.16);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 56px;
  --nav-h: 64px;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
               "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   APP SHELL
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  height: calc(var(--vh, 1vh) * 100);
  max-width: 600px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
  box-shadow: var(--shadow-lg);
}

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--lego-red);
  color: white;
  flex-shrink: 0;
  gap: 10px;
}

.header-logo { font-size: 22px; }

.header-title {
  flex: 1;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.sync-status {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  margin-right: 6px;
  white-space: nowrap;
}

.header-count {
  font-size: 12px;
  background: rgba(255,255,255,0.2);
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}

/* ---- Main / Tab Area ---- */
.app-main {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-content {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.tab-content.active { display: block; }

/* ---- Summary Cards ---- */
.summary-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.summary-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
}
.summary-card-wide {
  grid-column: 1 / -1;
}
.summary-icon { font-size: 28px; line-height: 1; }
.summary-body { flex: 1; min-width: 0; }
.summary-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 4px;
}
.summary-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}
.summary-unit {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 3px;
}
.summary-card-wide .summary-value {
  color: var(--lego-red);
}

/* ---- Bottom Navigation ---- */
.bottom-nav {
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-hint);
  transition: color 0.15s;
  padding: 6px 0;
}
.nav-btn.active { color: var(--lego-red); }
.nav-btn:active { background: var(--bg); }

.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 10px; font-weight: 600; letter-spacing: 0.3px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }

.btn-primary { background: var(--lego-red); color: white; }
.btn-primary:hover { background: var(--lego-red-dark); }
.btn-secondary {
  background: #F0F0F0;
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-danger { background: var(--danger); color: white; }
.btn-large { padding: 14px 32px; font-size: 16px; border-radius: var(--radius); }
.btn-small { padding: 7px 14px; font-size: 13px; }
.btn-block { width: 100%; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.required { color: var(--lego-red); }
.form-hint { font-size: 11px; color: var(--text-hint); margin-top: 4px; line-height: 1.5; }
.form-hint a { color: var(--lego-red); }

.form-input, .select-input, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color 0.15s;
  font-family: inherit;
}
.form-input:focus, .select-input:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--lego-red);
}
.form-textarea { resize: vertical; min-height: 80px; }
.select-input { appearance: none; 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 d='M1 1l5 5 5-5' stroke='%236B7280' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* Qty Control */
.qty-control {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
}
.qty-btn {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background 0.15s;
}
.qty-btn:hover { background: var(--bg); }
.qty-input {
  width: 64px;
  text-align: center;
  padding: 8px 4px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 18px;
  font-weight: 700;
}

/* ============================================================
   CARDS & SURFACE
   ============================================================ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
}

/* ============================================================
   SCANNER TAB
   ============================================================ */
.scanner-container { position: relative; }

.start-scan-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 40px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.scan-icon { font-size: 56px; }
.scan-hint { color: var(--text-secondary); line-height: 1.7; font-size: 15px; }

#scanner-reader {
  border-radius: var(--radius);
  overflow: hidden;
}
/* Override html5-qrcode default styles */
#scanner-reader video { border-radius: var(--radius); }
#reader__scan_region { border-radius: var(--radius); }

.scan-status {
  text-align: center;
  padding: 10px;
  color: var(--lego-red);
  font-weight: 600;
  font-size: 14px;
}

/* HIDリーダー（OPN-3102i）常時待機インジケータ */
.bt-reader-indicator {
  display: block;
  width: fit-content;
  margin: 12px auto 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(10, 143, 95, .12);
  color: #0a8f5f;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
#bt-scan-last { text-align: center; }

/* HIDリーダー用の画面外キャプチャ欄（フォーカス可能・不可視。iOSズーム防止のため16px） */
.bt-capture-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  margin: 0;
  font-size: 16px;
  z-index: -1;
  pointer-events: none;
}

/* Manual Entry Card */
#manual-entry-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   INVENTORY TAB
   ============================================================ */
.inventory-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.search-bar { width: 100%; }
.search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text-primary);
}
.search-input:focus { outline: none; border-color: var(--lego-red); }

.filter-bar {
  display: flex;
  gap: 8px;
}
.filter-bar .select-input { flex: 1; font-size: 13px; padding: 8px 10px; }

.inventory-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 80px;
}

/* Inventory Card */
.inventory-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s;
}
.inventory-card:active { transform: scale(0.99); box-shadow: var(--shadow-md); }

.card-image {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.no-image {
  font-size: 32px;
  opacity: 0.4;
}

.card-info {
  flex: 1;
  min-width: 0;
}
.card-set-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--lego-red);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-theme {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.card-pieces {
  font-size: 11px;
  color: var(--text-hint);
}
.card-meta {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.card-status-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}
.status-owned { background: #D1FAE5; color: #065F46; }
.status-listing { background: #DBEAFE; color: #1E40AF; }
.status-wishlist { background: #FEF3C7; color: #92400E; }
.status-sold { background: #F3F4F6; color: #6B7280; }
.import-row-dup { opacity: 0.5; }
.import-dup-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 6px;
  background: #F3F4F6;
  color: #6B7280;
  vertical-align: middle;
}
.card-location-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
  background: #EEF2FF;
  color: #3730A3;
}
.card-price-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
  background: #F0FDF4;
  color: #166534;
}

.card-count {
  text-align: center;
  flex-shrink: 0;
  min-width: 48px;
}
.count-num {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}
.count-label {
  font-size: 11px;
  color: var(--text-secondary);
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
  right: calc(50% - 300px + 16px);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--lego-red);
  color: white;
  font-size: 26px;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.93); }
@media (max-width: 600px) {
  .fab { right: 16px; }
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-secondary);
}
.empty-icon { font-size: 52px; opacity: 0.5; }
.empty-state p { font-size: 15px; font-weight: 600; }
.empty-hint { font-size: 12px; color: var(--text-hint); font-weight: 400; }

/* ============================================================
   IMPORT TAB
   ============================================================ */
.import-container { padding-bottom: 40px; }

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 36px 20px;
  border: 2.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 20px;
  cursor: default;
}
.drop-zone.drag-over {
  border-color: var(--lego-red);
  background: #FFF5F5;
}
.drop-icon { font-size: 44px; }
.drop-text { color: var(--text-secondary); font-size: 13px; line-height: 1.6; }

.import-guide { display: flex; flex-direction: column; gap: 12px; }

.guide-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.guide-title { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.guide-steps { padding-left: 18px; }
.guide-steps li { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; line-height: 1.6; }
.guide-steps code {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  color: var(--lego-red);
}
.guide-note {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
}
.guide-note p { font-size: 12px; color: #92400E; line-height: 1.7; }

/* ============================================================
   SETTINGS TAB
   ============================================================ */
.settings-container { padding-bottom: 40px; }

.settings-group {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.settings-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.settings-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }
.settings-actions { display: flex; flex-direction: column; gap: 8px; }
.settings-danger { border: 1px solid #FCA5A5; }
.settings-version {
  text-align: center;
  margin-top: 20px;
  color: var(--text-hint);
  font-size: 12px;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.active {
  display: flex;
  opacity: 1;
  pointer-events: auto;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.modal-overlay.center-modal {
  align-items: center;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(20px);
  transition: transform 0.2s;
  overflow: hidden;
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal-overlay.center-modal .modal {
  border-radius: var(--radius);
  max-height: 85vh;
}

.modal-wide { max-width: min(600px, 96vw); }

.modal-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.modal-set-num { font-size: 12px; color: var(--lego-red); font-weight: 700; }

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
  background: var(--surface);
}

/* Scan Result */
.scan-result-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.result-image {
  width: 90px;
  height: 90px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: white;
}
.result-info { flex: 1; }
.result-set-num { font-size: 12px; font-weight: 700; color: var(--lego-red); }
.result-name { font-size: 15px; font-weight: 700; margin-top: 4px; line-height: 1.4; }
.result-theme { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.result-count-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.result-current-count { font-weight: 700; font-size: 16px; color: var(--text-primary); }
.result-new-count { font-weight: 800; font-size: 18px; color: var(--lego-red); }
.arrow { color: var(--lego-red); font-size: 16px; }

/* Edit modal image */
.edit-image-container { text-align: center; margin-bottom: 14px; }

/* 購入情報 */
.form-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-bottom: 12px;
}
.purchase-add-row {
  display: flex;
  gap: 8px;
}
.shop-input-row {
  display: flex;
  gap: 8px;
}
.shop-input-row .select-input,
.shop-input-row .form-input { flex: 1; }
.purchase-add-row .form-group { margin-bottom: 8px; }
.purchase-history-box {
  background: var(--bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.purchase-history-box:empty { display: none; }
.purchase-row {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  gap: 8px;
}
.purchase-row:last-child { border-bottom: none; }
.purchase-row-date  { color: var(--text-secondary); min-width: 82px; font-size:12px; }
.purchase-row-shop  { color: var(--text-secondary); flex: 1; font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.purchase-row-price { font-weight: 700; min-width: 80px; text-align:right; }
.purchase-row-qty   { color: var(--text-secondary); min-width: 30px; text-align:right; font-size:12px; }
.purchase-row-del   {
  background: none;
  border: none;
  color: var(--text-hint);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.purchase-row-del:hover { color: var(--danger); }
.purchase-row-edit {
  background: none;
  border: none;
  color: var(--text-hint);
  font-size: 13px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}
.purchase-row-edit:hover { color: var(--primary); }
.purchase-row-editing {
  background: #FFF9C4;
  border-radius: var(--radius-sm);
  outline: 2px solid #F59E0B;
}
.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.purchase-avg-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  background: #EEF2FF;
  font-size: 12px;
  font-weight: 700;
  color: #3730A3;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

/* 販売・収益情報ボックス */
.sale-calc-box {
  background: #F0FDF4;
  border: 1px solid #BBF7D0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
}
.sale-calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 13px;
}
.sale-calc-row + .sale-calc-row {
  border-top: 1px solid #D1FAE5;
}
.sale-calc-row-total {
  background: #DCFCE7;
  margin: 0 -14px -10px;
  padding: 6px 14px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.sale-calc-row-total .sale-calc-label {
  font-weight: 700;
}
.sale-calc-label {
  color: var(--text-secondary);
  font-weight: 500;
}
.sale-calc-value {
  font-weight: 700;
  color: var(--text-primary);
}

/* Import Preview Table */
.table-container {
  overflow-x: auto;
  margin: 0 -16px;
  padding: 0 16px;
}
.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 480px;
}
.preview-table th {
  background: var(--bg);
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}
.preview-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.preview-table tr:last-child td { border-bottom: none; }
.name-cell {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--lego-red);
}

.import-skipped-msg {
  background: #FEF3C7;
  border: 1px solid #FDE68A;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: #92400E;
  margin-bottom: 12px;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1A1A2E;
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s;
  opacity: 0;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.toast-error { background: var(--danger); }
.toast.toast-warning { background: var(--warning); color: #1A1A2E; }

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 300;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: white;
  font-weight: 600;
}
.loading-overlay.visible {
  display: flex;
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   PURCHASE HISTORY MODAL
   ============================================================ */
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.history-table th {
  background: var(--bg);
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
}
.history-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ============================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================ */
@media (max-width: 360px) {
  .card-image { width: 60px; height: 60px; }
  .count-num { font-size: 22px; }
  .nav-label { font-size: 9px; }
}
