/* ==========================================================================
   BoxGauge Live Inventory — inv.drb.wang
   Ultra-Crisp White / Light Theme (with Dark Mode Support)
   ========================================================================== */

:root {
  /* Crisp White Palette (Default) */
  --bg-primary: #f8fafc;
  --bg-surface: rgba(255, 255, 255, 0.92);
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-subtle: #f1f5f9;
  
  --border-subtle: #e2e8f0;
  --border-focus: #3b82f6;
  --border-glow: rgba(37, 99, 235, 0.25);
  
  --accent-cyan: #0284c7;
  --accent-blue: #2563eb;
  --accent-emerald: #059669;
  --accent-amber: #d97706;
  --accent-purple: #7c3aed;
  --accent-rose: #e11d48;
  
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-faint: #94a3b8;
  
  --card-shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.05), 0 2px 6px -1px rgba(15, 23, 42, 0.03);
  --card-shadow-hover: 0 10px 25px -3px rgba(15, 23, 42, 0.09), 0 4px 10px -2px rgba(15, 23, 42, 0.04);
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Dark Theme Overrides (if toggled) */
[data-theme="dark"] {
  --bg-primary: #070a12;
  --bg-surface: rgba(16, 23, 38, 0.88);
  --bg-card: rgba(22, 32, 54, 0.9);
  --bg-card-hover: rgba(28, 42, 70, 0.98);
  --bg-subtle: rgba(10, 16, 28, 0.6);
  
  --border-subtle: rgba(255, 255, 255, 0.09);
  --border-focus: #00d9f5;
  --border-glow: rgba(0, 229, 153, 0.3);
  
  --accent-cyan: #00d9f5;
  --accent-blue: #38bdf8;
  --accent-emerald: #00e599;
  --accent-amber: #ffaa00;
  --accent-purple: #a855f7;
  --accent-rose: #f43f5e;
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  
  --card-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
  --card-shadow-hover: 0 10px 25px -3px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(circle at 10% 10%, rgba(37, 99, 235, 0.05) 0%, transparent 45%),
    radial-gradient(circle at 90% 90%, rgba(5, 150, 105, 0.04) 0%, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow-x: hidden;
  line-height: 1.5;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  padding-bottom: calc(75px + var(--safe-bottom));
}

/* ==========================================================================
   Header & Navigation
   ========================================================================== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  padding: calc(12px + var(--safe-top)) 16px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
}

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

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

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(5, 150, 105, 0.12));
  border: 1px solid rgba(37, 99, 235, 0.25);
  color: var(--accent-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.1);
}

[data-theme="dark"] .brand-icon {
  background: linear-gradient(135deg, rgba(0, 217, 245, 0.2), rgba(0, 229, 153, 0.2));
  border-color: rgba(0, 229, 153, 0.35);
  color: var(--accent-emerald);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #0f172a 40%, var(--accent-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="dark"] .brand-title {
  background: linear-gradient(135deg, #ffffff 40%, var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: -0.01em;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
}

.theme-toggle-btn:active {
  transform: scale(0.92);
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: all 0.3s ease;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-amber);
  box-shadow: 0 0 6px var(--accent-amber);
  animation: pulseDot 2s infinite ease-in-out;
}

.connection-pill.online {
  border-color: rgba(5, 150, 105, 0.35);
  color: #047857;
  background: #ecfdf5;
}

[data-theme="dark"] .connection-pill.online {
  background: rgba(0, 229, 153, 0.12);
  color: var(--accent-emerald);
  border-color: rgba(0, 229, 153, 0.35);
}

.connection-pill.online .status-dot {
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ==========================================================================
   Stats Carousel
   ========================================================================== */

.stats-carousel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--card-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:active {
  transform: scale(0.98);
}

.stat-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.stat-meta {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.stat-num {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  white-space: nowrap;
}

.stat-name {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ==========================================================================
   Search Box
   ========================================================================== */

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-faint);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 38px;
  font-size: 0.88rem;
  font-family: var(--font-sans);
  color: var(--text-main);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: all 0.2s ease;
}

.search-box input::placeholder {
  color: var(--text-faint);
}

.search-box input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.clear-btn {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 0.9rem;
  padding: 4px 8px;
  cursor: pointer;
}

/* ==========================================================================
   Tabs Navigation
   ========================================================================== */

.view-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--accent-blue);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .tab-btn.active {
  background: rgba(0, 217, 245, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 217, 245, 0.3);
  box-shadow: 0 2px 8px rgba(0, 217, 245, 0.15);
}

.tab-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  background: var(--bg-card);
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

.tab-btn.active .tab-badge {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
  font-weight: 700;
}

[data-theme="dark"] .tab-btn.active .tab-badge {
  background: var(--accent-cyan);
  color: #070a12;
  border-color: transparent;
}

/* ==========================================================================
   Main Content & Dynamic Cards
   ========================================================================== */

.app-main {
  flex: 1;
  padding: 12px 16px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.list-meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.action-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  color: var(--text-main);
  cursor: pointer;
  font-size: 0.85rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.action-btn:active {
  transform: scale(0.95);
}

.items-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* RFID Inspection Card */
.rfid-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--card-shadow);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.rfid-card:hover {
  box-shadow: var(--card-shadow-hover);
  border-color: #cbd5e1;
}

.rfid-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--accent-blue);
}

[data-theme="dark"] .rfid-card::before {
  background: var(--accent-cyan);
}

.rfid-card.new-item {
  animation: newCardPulse 1.8s ease-out;
}

@keyframes newCardPulse {
  0% { box-shadow: 0 0 25px rgba(5, 150, 105, 0.6); border-color: var(--accent-emerald); }
  100% { box-shadow: var(--card-shadow); border-color: var(--border-subtle); }
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.rfid-pill {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

[data-theme="dark"] .rfid-pill {
  color: var(--accent-cyan);
  background: rgba(0, 217, 245, 0.12);
  border-color: rgba(0, 217, 245, 0.25);
}

.rfid-pill:active {
  background: #dbeafe;
}

.shelf-tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  color: #6d28d9;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

[data-theme="dark"] .shelf-tag {
  background: rgba(168, 85, 247, 0.15);
  border-color: rgba(168, 85, 247, 0.35);
  color: #c084fc;
}

.card-title-row {
  display: flex;
  flex-direction: column;
}

.card-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.25;
}

.card-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 3px;
}

.sku-badge {
  font-family: var(--font-mono);
  color: #334155;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
}

[data-theme="dark"] .sku-badge {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: transparent;
}

/* Specs Badges Grid */
.specs-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--bg-subtle);
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.spec-item {
  display: flex;
  flex-direction: column;
}

.spec-lbl {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.spec-val {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding-top: 4px;
}

/* Product Card */
.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: var(--card-shadow);
  transition: all 0.2s ease;
}

.product-card:hover {
  box-shadow: var(--card-shadow-hover);
  border-color: #cbd5e1;
}

.product-meta {
  display: flex;
  flex-direction: column;
}

.product-qty-badge {
  text-align: right;
}

.qty-big {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent-emerald);
}

.qty-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Shelves Grid */
.shelves-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.shelf-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--card-shadow);
}

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

.shelf-name {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text-main);
}

/* Empty State & Spinner */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Footer */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  padding: 10px 16px calc(10px + var(--safe-bottom)) 16px;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.02);
}

.station-meta {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.station-badge {
  font-family: var(--font-mono);
  font-weight: 700;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  border: 1px solid var(--accent-emerald);
  color: #ffffff;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
