/* === Reset & Base === */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, sans-serif;
  background: #f5f5f5;
  color: #1c1c1e;
  min-height: 100vh;
  overflow-x: hidden;
}

/* === LOGIN PAGE === */
.login-page {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fff;
  padding: 32px 24px;
}
.login-page.active { display: flex; }

.logo-area { text-align: center; margin-bottom: 48px; }
.logo-icon {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, #34c759, #30d158);
  border-radius: 20px;
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: #fff; font-weight: 700;
  box-shadow: 0 4px 16px rgba(52,199,89,0.3);
}
.login-page h1 { font-size: 28px; font-weight: 700; }
.subtitle { font-size: 15px; color: #8e8e93; margin-top: 4px; }

.login-form { width: 100%; max-width: 400px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #8e8e93; }
.form-group input {
  width: 100%; padding: 16px; background: #f2f2f7; border: none; border-radius: 14px;
  font-size: 17px; outline: none; -webkit-appearance: none; transition: background 0.2s;
}
.form-group input:focus { background: #e8e8ed; }

.login-error { color: #ff3b30; font-size: 14px; font-weight: 500; min-height: 20px; margin-bottom: 4px; text-align: center; }

.btn-login {
  width: 100%; padding: 16px;
  background: linear-gradient(135deg, #34c759, #30d158);
  color: #fff; border: none; border-radius: 14px;
  font-size: 17px; font-weight: 600; cursor: pointer;
  -webkit-appearance: none; transition: opacity 0.2s;
}
.btn-login:active { opacity: 0.85; }
.btn-login:disabled { opacity: 0.5; cursor: not-allowed; }

/* === APP PAGE === */
.app-page { display: none; min-height: 100vh; min-height: 100dvh; padding-bottom: 90px; }
.app-page.active { display: block; }

.header { padding: 16px 20px 8px; }
.header-top { display: flex; justify-content: space-between; align-items: flex-start; }
.header h1 { font-size: 32px; font-weight: 800; letter-spacing: -0.5px; }
.greeting { font-size: 15px; color: #8e8e93; margin-bottom: 2px; }
.logout-btn {
  background: #f2f2f7; border: none; border-radius: 12px;
  width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #8e8e93; transition: all 0.15s;
}
.logout-btn:hover { background: #e8e8ed; color: #ff3b30; }

/* === Search === */
.search-bar {
  margin: 8px 20px 12px; background: #e8e8ed; border-radius: 12px;
  padding: 0 14px; display: flex; align-items: center; position: relative;
}
.search-bar svg { color: #8e8e93; flex-shrink: 0; }
.search-bar input {
  flex: 1; border: none; padding: 14px 10px; font-size: 17px;
  background: transparent; outline: none; color: #1c1c1e; min-width: 0;
}
.search-bar input::placeholder { color: #8e8e93; }
.search-clear {
  display: none; background: #8e8e93; color: #fff; border: none;
  width: 22px; height: 22px; border-radius: 50%; font-size: 14px;
  cursor: pointer; line-height: 1; padding: 0;
}
.search-clear.visible { display: flex; align-items: center; justify-content: center; }

/* === Pull to Refresh === */
.pull-indicator {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0; height: 0; overflow: hidden; transition: all 0.3s;
  font-size: 13px; color: #8e8e93; font-weight: 500;
}
.pull-indicator.visible { height: 44px; padding: 10px 0; }
.pull-indicator.refreshing .pull-spinner { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* === Filter + Sort Row === */
.filter-sort-row {
  display: flex; align-items: center; gap: 8px; padding: 4px 20px 12px;
}
.filter-chips {
  display: flex; gap: 8px; flex: 1;
  overflow-x: auto; scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }
.filter-chip {
  background: #fff; border: 1.5px solid #e0e0e0; border-radius: 20px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; color: #8e8e93;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: all 0.15s; -webkit-tap-highlight-color: transparent;
}
.filter-chip:active { transform: scale(0.95); }
.filter-chip.active { background: #34c759; border-color: #34c759; color: #fff; }
.filter-chip[data-filter="out-of-stock"].active { background: #ff3b30; border-color: #ff3b30; }
.filter-chip[data-filter="low-stock"].active { background: #ff9500; border-color: #ff9500; }
.filter-chip[data-filter="stale"].active { background: #8e8e93; border-color: #8e8e93; }

.sort-select {
  background: #fff; border: 1.5px solid #e0e0e0; border-radius: 12px;
  padding: 8px 12px; font-size: 13px; font-weight: 600; color: #1c1c1e;
  cursor: pointer; -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238e8e93' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
  padding-right: 28px; flex-shrink: 0;
}
.sort-select:focus { outline: none; border-color: #34c759; }

/* === Stock Set Row (detail page) === */
.stock-set-row {
  display: flex; gap: 10px; margin-top: 16px; justify-content: center;
}
.stock-set-input {
  width: 100px; padding: 10px 14px; border: 1.5px solid #e0e0e0; border-radius: 12px;
  font-size: 17px; font-weight: 600; text-align: center; outline: none;
  -webkit-appearance: none; -moz-appearance: textfield;
}
.stock-set-input:focus { border-color: #34c759; }
.stock-set-input::-webkit-inner-spin-button,
.stock-set-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stock-set-btn {
  padding: 10px 20px; background: #007aff; color: #fff; border: none;
  border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s;
}
.stock-set-btn:active { opacity: 0.8; }
.stock-set-btn:disabled { opacity: 0.5; }

.last-updated {
  margin-top: 12px; font-size: 12px; color: #8e8e93; font-weight: 500;
}
.last-updated.stale { color: #ff9500; }

/* === Card timestamp === */
.card-time { font-size: 11px; color: #c7c7cc; margin-top: 1px; }

/* === Quick Stats === */
.quick-stats { display: flex; gap: 10px; padding: 4px 20px 16px; overflow-x: auto; scrollbar-width: none; }
.quick-stats::-webkit-scrollbar { display: none; }
.quick-stat {
  background: #fff; border-radius: 16px; padding: 14px 18px;
  min-width: 110px; flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.qs-label { font-size: 12px; color: #8e8e93; font-weight: 500; }
.qs-value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.qs-value.danger { color: #ff3b30; }

.section-title {
  padding: 4px 20px 8px; font-size: 13px; font-weight: 600;
  color: #8e8e93; text-transform: uppercase; letter-spacing: 0.5px;
}

/* === Cards List === */
.cards-list { padding: 0 20px; }

.card {
  background: #fff; border-radius: 16px; padding: 14px 16px;
  margin-bottom: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px;
  cursor: pointer; transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden; min-width: 0;
}
.card.out-of-stock { opacity: 0.55; }
.card:active { transform: scale(0.98); }

.card-icon {
  width: 44px; height: 44px; background: #f2f2f7; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.card-info { flex: 1; min-width: 0; }
.card-title {
  font-size: 15px; font-weight: 600; line-height: 1.3;
}
.card-sub { font-size: 12px; color: #8e8e93; margin-top: 2px; }

.card-right {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
  margin-left: auto;
}
.stock-btn {
  width: 36px; height: 36px; border-radius: 10px; border: none;
  font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-weight: 600; transition: transform 0.1s;
}
.stock-btn:active { transform: scale(0.9); }
.stock-btn.minus { background: #fff2f2; color: #ff3b30; }
.stock-btn.plus { background: #f0faf2; color: #34c759; }
.stock-count {
  font-size: 18px; font-weight: 700; min-width: 30px; text-align: center;
}
.stock-count.low { color: #ff3b30; }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 16px; color: #8e8e93; }

/* === Loading Skeleton === */
.card.skeleton { pointer-events: none; }
.skeleton-icon {
  width: 48px; height: 48px; background: #e8e8ed; border-radius: 14px;
  flex-shrink: 0; animation: pulse 1.5s ease-in-out infinite;
}
.skeleton-text { flex: 1; }
.skeleton-line {
  height: 14px; background: #e8e8ed; border-radius: 7px;
  margin-bottom: 8px; animation: pulse 1.5s ease-in-out infinite;
}
.skeleton-line.w30 { width: 30%; }
.skeleton-line.w40 { width: 40%; }
.skeleton-line.w50 { width: 50%; }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w70 { width: 70%; }
.skeleton-line.w80 { width: 80%; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* === Bottom Nav === */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid #d1d1d6;
  display: flex; padding: 8px 0 env(safe-area-inset-bottom, 12px);
  z-index: 100;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 2px; font-size: 10px; font-weight: 500; color: #8e8e93;
  cursor: pointer; padding: 6px 0; transition: color 0.15s;
}
.nav-item.active { color: #34c759; }
.nav-item svg { width: 24px; height: 24px; }

/* === Detail Page === */
.detail-page {
  display: none; position: fixed; inset: 0; background: #f5f5f5;
  z-index: 200; overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.detail-page.active { display: block; transform: translateX(0); }
.detail-page.entering { display: block; }

.detail-header {
  padding: 16px 20px; display: flex; align-items: center; justify-content: space-between;
  background: rgba(245,245,245,0.9); backdrop-filter: blur(20px);
  position: sticky; top: 0; z-index: 10;
}
.detail-back {
  background: none; border: none; font-size: 17px; color: #34c759;
  font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 4px;
}
.detail-save-btn {
  background: #34c759; color: #fff; border: none; border-radius: 10px;
  padding: 8px 20px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: opacity 0.2s;
}
.detail-save-btn:active { opacity: 0.8; }
.detail-save-btn:disabled { opacity: 0.5; }

.detail-body { padding: 8px 20px 40px; }
.detail-icon { font-size: 48px; text-align: center; margin-bottom: 8px; }
.detail-body h2 { font-size: 26px; font-weight: 700; text-align: center; margin-bottom: 2px; }
.sku-text { font-size: 14px; color: #8e8e93; text-align: center; margin-bottom: 20px; }

.detail-stock-section {
  background: #fff; border-radius: 18px; padding: 24px;
  margin: 0 0 24px; text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.detail-stock-section .label { font-size: 13px; color: #8e8e93; font-weight: 600; margin-bottom: 12px; }
.detail-stock-controls { display: flex; align-items: center; justify-content: center; gap: 28px; }
.detail-stock-controls .stock-btn { width: 56px; height: 56px; border-radius: 16px; font-size: 28px; }
.detail-stock-controls .stock-count { font-size: 48px; font-weight: 700; min-width: 70px; }

.detail-field { margin-bottom: 20px; }
.detail-field label { display: block; font-size: 13px; font-weight: 600; color: #8e8e93; margin-bottom: 6px; }
.detail-field input, .detail-field textarea {
  width: 100%; padding: 16px; background: #fff; border: none; border-radius: 14px;
  font-size: 17px; outline: none; font-family: inherit;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04); -webkit-appearance: none;
  transition: box-shadow 0.2s;
}
.detail-field input:focus, .detail-field textarea:focus {
  box-shadow: 0 0 0 3px rgba(52,199,89,0.2), 0 1px 4px rgba(0,0,0,0.04);
}
.detail-field textarea { min-height: 100px; resize: none; }

.variations-list { display: flex; flex-direction: column; gap: 8px; }
.variation-card {
  background: #fff; border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  display: flex; align-items: center; justify-content: space-between;
}
.variation-name { font-size: 15px; font-weight: 600; }
.variation-details { font-size: 12px; color: #8e8e93; margin-top: 2px; }
.variation-stock { display: flex; align-items: center; gap: 6px; }
.variation-stock .stock-btn { width: 32px; height: 32px; border-radius: 8px; font-size: 16px; }
.variation-stock .stock-count { font-size: 16px; min-width: 24px; }

/* === Toast === */
.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%) translateY(-100px);
  background: rgba(0,0,0,0.8); backdrop-filter: blur(10px);
  color: #fff; padding: 10px 20px; border-radius: 12px;
  font-size: 14px; font-weight: 500; z-index: 9999;
  transition: transform 0.3s ease; pointer-events: none; white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: rgba(255,59,48,0.9); }
.toast.success { background: rgba(52,199,89,0.9); }

/* ======================================
   RESPONSIVE — REACTIVE TO DISPLAY SIZE
   ====================================== */

/* Small phones (< 375px) */
@media (max-width: 374px) {
  .header h1 { font-size: 26px; }
  .quick-stat { min-width: 90px; padding: 10px 14px; }
  .qs-value { font-size: 20px; }
  .card { padding: 12px; gap: 10px; }
  .card-icon { width: 40px; height: 40px; font-size: 18px; border-radius: 12px; }
  .card-title { font-size: 14px; }
  .stock-btn { width: 32px; height: 32px; font-size: 18px; border-radius: 8px; }
  .stock-count { font-size: 16px; min-width: 24px; }
  .detail-stock-controls .stock-btn { width: 48px; height: 48px; font-size: 24px; }
  .detail-stock-controls .stock-count { font-size: 40px; }
}

/* Tablets (768px+) — 2 column grid */
@media (min-width: 768px) {
  body { max-width: 100%; }

  .login-form { max-width: 420px; }

  .app-page { max-width: 100%; padding-bottom: 0; }

  .header { padding: 24px 32px 12px; }
  .header h1 { font-size: 36px; }

  .search-bar { margin: 8px 32px 16px; max-width: 500px; }

  .filter-sort-row { padding: 4px 32px 12px; }
  .quick-stats { padding: 4px 32px 20px; gap: 14px; }
  .quick-stat { min-width: 140px; padding: 18px 22px; }
  .qs-value { font-size: 28px; }

  .section-title { padding: 4px 32px 10px; }

  .cards-list {
    padding: 0 32px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .cards-list .card { margin-bottom: 0; }

  .bottom-nav { display: none; }

  /* Show a horizontal nav instead */
  .header-top { align-items: center; }
}

/* Desktop (1024px+) — 3 column grid with sidebar feel */
@media (min-width: 1024px) {
  .app-page { max-width: 1200px; margin: 0 auto; }

  .cards-list {
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    padding: 0 40px;
  }

  .header { padding: 28px 40px 12px; }
  .search-bar { margin: 8px 40px 16px; max-width: 560px; }
  .filter-sort-row { padding: 4px 40px 12px; }
  .quick-stats { padding: 4px 40px 20px; }
  .section-title { padding: 4px 40px 10px; }

  .detail-page {
    left: auto; right: 0; width: 500px;
    border-left: 1px solid #e0e0e0;
    box-shadow: -4px 0 24px rgba(0,0,0,0.08);
  }
}

/* Large desktop (1440px+) — 4 columns */
@media (min-width: 1440px) {
  .app-page { max-width: 1400px; }
  .cards-list { grid-template-columns: repeat(4, 1fr); }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
  .header h1 { font-size: 24px; }
  .header { padding: 8px 20px 4px; }
  .quick-stats { padding: 4px 20px 8px; }
  .quick-stat { padding: 8px 14px; min-width: 90px; }
  .qs-value { font-size: 18px; }
  .card { padding: 10px 14px; margin-bottom: 6px; }
  .cards-list { padding: 0 20px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .cards-list .card { margin-bottom: 0; }
  .bottom-nav { padding: 4px 0 4px; }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  /* Only activate if user wants it - can be toggled in settings */
}

/* PWA installed — no bottom padding needed for notch */
@media (display-mode: standalone) {
  body { padding-top: env(safe-area-inset-top); }
  .bottom-nav { padding-bottom: env(safe-area-inset-bottom, 12px); }
}
