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

/* ===== Login Overlay ===== */
.login-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: #f0fdf4;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px 32px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08); max-width: 360px; width: 100%;
  text-align: center;
}
.login-card h1 { color: #0d9488; font-size: 1.5rem; margin-bottom: 8px; }
.login-card p { color: #64748b; font-size: 0.9rem; margin-bottom: 24px; }
.login-card input {
  width: 100%; padding: 12px 16px; border: 2px solid #e2e8f0;
  border-radius: 10px; font-size: 1rem; outline: none; transition: border-color 0.2s;
}
.login-card input:focus { border-color: #0d9488; }
.login-card button {
  width: 100%; padding: 12px; margin-top: 16px;
  background: #0d9488; color: #fff; border: none; border-radius: 10px;
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: background 0.2s;
}
.login-card button:hover { background: #0f766e; }
.login-error { color: #ef4444; font-size: 0.85rem; margin-top: 12px; }

:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-light: #ccfbf1;
  --gradient: linear-gradient(135deg, #0d9488 0%, #10b981 50%, #a3e635 100%);
  --gradient-subtle: linear-gradient(135deg, #0d9488 0%, #10b981 60%, #34d399 100%);
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: Candara, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  padding-bottom: calc(70px + var(--safe-bottom));
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  background: var(--gradient-subtle);
  color: white;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  text-align: center;
  z-index: 100;
}

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

.header-subtitle {
  font-size: 0.8rem;
  opacity: 0.85;
  font-weight: 400;
}

/* ===== Tab Bar (Bottom Nav) ===== */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.65rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  color: var(--primary);
}

.tab-icon {
  width: 22px;
  height: 22px;
}

/* ===== Content Area ===== */
.content {
  padding: 12px;
  max-width: 600px;
  margin: 0 auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* ===== Sticky Header (search + badges) ===== */
.products-sticky-header {
  position: sticky;
  top: calc(var(--safe-top) + 40px);
  z-index: 50;
  background: var(--bg);
  padding-bottom: 8px;
}

/* ===== Search Bar ===== */
.search-bar {
  position: relative;
  padding: 8px 0;
  margin-bottom: 8px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.search-bar input:focus {
  border-color: var(--primary);
}

/* ===== Category Badges ===== */
.category-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 0 14px;
}
.category-badges.collapsed .category-badge:nth-child(n+4) {
  display: none;
}
.badge-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1.5px dashed var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  line-height: 1;
}
.badge-toggle svg,
.badge-toggle i {
  width: 14px;
  height: 14px;
  min-width: 14px;
  transition: transform .2s;
}
.category-badges:not(.collapsed) .badge-toggle svg,
.category-badges:not(.collapsed) .badge-toggle i {
  transform: rotate(180deg);
}
.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
}
.category-badge svg,
.category-badge i {
  width: 14px;
  height: 14px;
  min-width: 14px;
  flex-shrink: 0;
  display: inline-flex;
}
.category-badge:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.category-badge.active {
  background: var(--gradient-subtle);
  color: #fff;
  border-color: transparent;
}

/* ===== Scorecard ===== */
.scorecard {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  gap: 2px 0;
}
.scorecard-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  width: 100%;
  padding: 4px 0;
}
.scorecard-item:not(:last-child) {
  border-bottom: 1px solid var(--border);
}
.scorecard-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.scorecard-value {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}
.scorecard-highlight {
  color: var(--primary);
  font-size: 0.95rem;
}

/* ===== New Order Button ===== */
.btn-new-order {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px;
  margin-bottom: 24px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #059669 0%, #10b981 50%, #34d399 100%);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
  box-shadow: var(--shadow-lg);
}
.btn-new-order:active { opacity: 0.85; }
.btn-new-order svg { width: 22px; height: 22px; }

/* ===== Order Overlay ===== */
.order-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 300;
  flex-direction: column;
}
.order-overlay.open { display: flex; }
.order-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--gradient-subtle);
  color: white;
  flex-shrink: 0;
}
.order-back-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  display: flex;
  -webkit-tap-highlight-color: transparent;
}
.order-back-btn svg { width: 24px; height: 24px; }
.order-header h2 { font-size: 1rem; font-weight: 700; }
.order-search {
  position: relative;
  padding: 8px 12px;
  flex-shrink: 0;
}
.order-search .search-icon {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}
.order-search input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
}
.order-search input:focus { border-color: var(--primary); }
.order-badges {
  padding: 0 12px 4px;
  flex-shrink: 0;
}
.order-badges .category-badges {
  margin: 0;
}
.order-products {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px 90px;
}
.picker-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.picker-card.selected { border-color: var(--primary); }
.picker-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.picker-thumb {
  width: 50px;
  height: 50px;
  min-width: 50px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
}
.picker-thumb img { width: 100%; height: 100%; object-fit: cover; }
.picker-text { flex: 1; min-width: 0; }
.picker-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.picker-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qty-stepper {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.qty-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.qty-minus { border-radius: 8px 0 0 8px; }
.qty-plus { border-radius: 0 8px 8px 0; }
.qty-value {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.order-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: none;
  z-index: 301;
}
.order-bar.visible { display: block; }
.order-bar .btn-primary { margin-bottom: 0; }

/* ===== Batch Edit Button ===== */
.batch-edit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  margin-top: 8px;
  margin-bottom: 10px;
  border: 1.5px dashed var(--primary);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.batch-edit-btn svg { width: 16px; height: 16px; }

/* ===== Card List ===== */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Product Card ===== */
.product-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

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

.product-card-row {
  display: flex;
  gap: 12px;
  padding: 12px;
  align-items: center;
}

.product-thumb {
  width: 88px;
  height: 88px;
  min-width: 88px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
}

.product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-card-body {
  flex: 1;
  min-width: 0;
}

.product-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.product-brand {
  font-size: 0.8rem;
  color: var(--primary-dark);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 2px;
}

.product-spec-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.tag-hdsd {
  background: #fef3c7;
  color: #92400e;
}

.tag-tuoi {
  background: #ede9fe;
  color: #5b21b6;
}

.product-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.tag {
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: #ecfdf5;
  color: var(--primary-dark);
  font-weight: 500;
}

/* ===== Purchase Card ===== */
.purchase-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  gap: 10px;
  align-items: center;
}

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

.purchase-thumb {
  width: 68px;
  height: 68px;
  min-width: 68px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
}

.purchase-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pill-icon {
  width: 32px;
  height: 32px;
  color: var(--primary);
  opacity: 0.5;
  margin: auto;
  display: block;
}

.purchase-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
}

.purchase-card-body {
  flex: 1;
  min-width: 0;
}

.purchase-line1 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.purchase-line2,
.purchase-line3 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.purchase-line2 {
  margin-bottom: 2px;
}

.purchase-spec {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.purchase-price {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text);
}

.purchase-qty {
  display: inline-block;
  background: #ecfdf5;
  color: #000000;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.purchase-brand {
  font-size: 0.8rem;
  color: var(--primary-dark);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.purchase-line4 {
  font-size: 0.75rem;
  font-style: italic;
  text-align: right;
  color: #dc2626;
  margin-top: 2px;
}

.purchase-total {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ===== Batch Group ===== */
.batch-group {
  margin-bottom: 20px;
}

.batch-header {
  background: var(--gradient-subtle);
  color: white;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  position: relative;
  user-select: none;
}

.batch-items {
  overflow: hidden;
  transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  opacity: 1;
}

.batch-group.collapsed .batch-items {
  height: 0 !important;
  opacity: 0;
}

.batch-group.collapsed .batch-header {
  margin-bottom: 0;
}
.batch-group.collapsed .batch-edit-btn {
  display: none;
}

.batch-group.batch-pending .batch-header {
  background: linear-gradient(135deg, #eab308 0%, #facc15 50%, #fde047 100%);
}

.batch-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  line-height: 1.6;
}

.batch-label {
  font-size: 0.95rem;
  font-weight: 700;
}

.batch-highlight {
  font-size: 0.9rem;
  font-weight: 700;
  color: #ffffff;
}

.batch-count {
  font-size: 0.8rem;
  opacity: 0.85;
}

.batch-detail {
  font-size: 0.8rem;
  opacity: 0.9;
}

.batch-date {
  font-size: 0.8rem;
  opacity: 0.85;
}

/* ===== Modal ===== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  justify-content: center;
  align-items: flex-end;
  padding: 0;
}

.modal.open {
  display: flex;
}

body.modal-open {
  overflow: hidden;
  touch-action: none;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  position: relative;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 2px;
  padding-right: 40px;
}

.modal-brand {
  font-size: 0.85rem;
  color: var(--primary-dark);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 8px;
}

.modal-top-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.modal-top-info {
  flex: 1;
  min-width: 0;
}

.modal-thumb {
  width: 110px;
  height: 110px;
  min-width: 110px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
}

.modal-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}

.modal-section {
  margin-bottom: 16px;
}

.modal-section h3 {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.modal-section p {
  font-size: 0.9rem;
  line-height: 1.6;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-label {
  color: var(--text-secondary);
}

.detail-value {
  font-weight: 600;
  text-align: right;
}

/* ===== Công dụng List ===== */
.congdung-list {
  list-style: none;
  padding: 0;
}

.congdung-list li {
  font-size: 0.85rem;
  line-height: 1.6;
  padding: 6px 0 6px 20px;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.congdung-list li:last-child {
  border-bottom: none;
}

.congdung-list li::before {
  content: '•';
  position: absolute;
  left: 4px;
  color: var(--primary);
  font-weight: bold;
}

/* ===== Export Button ===== */
.btn-export {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 16px auto 0;
  padding: 10px 20px;
  background: var(--gradient-subtle);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
}
.btn-export:hover { opacity: .85; }
.btn-export:disabled { opacity: .5; cursor: not-allowed; }
.btn-export svg, .btn-export-icon { width: 18px; height: 18px; }

/* ===== Settings ===== */
.settings-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 16px;
  box-shadow: var(--shadow);
}

.settings-card h2 {
  font-size: 1rem;
  margin-bottom: 16px;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--gradient-subtle);
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  margin-bottom: 8px;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.status-msg {
  font-size: 0.8rem;
  margin-top: 10px;
  text-align: center;
  color: var(--primary);
}

.status-msg.error {
  color: #dc2626;
}

.app-info {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
}

.app-info p {
  margin-bottom: 4px;
}

/* ===== Loading Spinner ===== */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.85rem;
}


