:root {
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --navy-950: #090e1a;
  --navy-900: #0f172a;
  --navy-800: #1e293b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --emerald: #059669;
  --emerald-soft: #d1fae5;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --rose: #e11d48;
  --rose-soft: #ffe4e6;
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius-xl: 20px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 16px 36px rgba(15, 23, 42, 0.12);
}

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

html {
  scroll-padding-top: 76px;
  scroll-padding-bottom: 88px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", "Prompt", sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 84px;
}

/* Baseline-First Global Utilities */
.row-baseline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.badge-blue {
  background: var(--primary-soft);
  color: #1e40af;
}

.badge-green {
  background: var(--emerald-soft);
  color: #065f46;
}

.badge-amber {
  background: var(--amber-soft);
  color: #92400e;
}

.badge-rose {
  background: var(--rose-soft);
  color: #9f1239;
}

.badge-gold {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  color: #92400e;
  border: 1px solid #fcd34d;
}

/* Buttons - strict 44px touch target on mobile, 36px compact */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-sm {
  height: 34px;
  padding: 0 12px;
  font-size: 0.85rem;
  border-radius: 8px;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
}

.btn-emerald {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.22);
}

.btn-outline {
  background: #ffffff;
  color: var(--text-main);
  border-color: var(--border);
}

.btn-outline:hover {
  background: var(--bg-subtle);
}

.btn-ghost-dark {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-block {
  width: 100%;
}

/* Inputs & Selects - strict 44px height */
.input,
.select {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Top Sticky App Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0 16px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-inner {
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #ffffff;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
  line-height: 1;
}

.brand-sub {
  font-size: 0.72rem;
  color: #93c5fd;
  font-weight: 500;
  line-height: 1;
  margin-top: 3px;
}

/* Premium Hero Banner */
.hero-banner {
  background: radial-gradient(circle at top right, #1e3a8a 0%, #0f172a 55%, #090e1a 100%);
  color: #ffffff;
  padding: 28px 16px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.hero-container {
  max-width: 1040px;
  margin: 0 auto;
}

.hero-top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.hero-logo-lg {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  object-fit: cover;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.22);
  flex-shrink: 0;
}

.hero-h1 {
  font-size: clamp(1.35rem, 4.2vw, 2rem);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: #ffffff;
  margin-top: 6px;
}

.hero-desc {
  color: #cbd5e1;
  font-size: 0.95rem;
  margin-bottom: 18px;
  max-width: 720px;
}

/* 7 Pillars Horizontal Pill Bar on Mobile */
.pillars-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: none;
}

.pillars-scroll::-webkit-scrollbar {
  display: none;
}

.pillar-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e2e8f0;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pillar-chip.active,
.pillar-chip:hover {
  background: #2563eb;
  border-color: #60a5fa;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

/* Main Workspace Container */
.app-container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px;
}

/* Summary KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

@media (min-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.kpi-card.highlight {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  color: #ffffff;
  border-color: #1e40af;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.kpi-card.highlight .kpi-label {
  color: #93c5fd;
}

.kpi-value {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.kpi-card.highlight .kpi-sub {
  color: #cbd5e1;
}

/* Section Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

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

/* Tab Views */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Quick Action Tiles on Dashboard */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .quick-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.quick-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.quick-tile:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.quick-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.quick-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.quick-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Product POS Grid */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 840px) {
  .pos-layout {
    grid-template-columns: 1.35fr 1fr;
  }
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 10px;
}

.product-item {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  font-family: inherit;
}

.product-item:hover {
  border-color: var(--primary);
  background: #eff6ff;
}

.product-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
}

.product-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.product-price {
  font-size: 1rem;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

/* List Items (Bills, Stock, Expenses) */
.list-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-row {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (min-width: 640px) {
  .list-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.list-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

.list-sub {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* Modal for Receipt / QR PromptPay */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: #ffffff;
  border-radius: var(--radius-xl);
  max-width: 440px;
  width: 100%;
  padding: 22px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.qr-frame {
  background: #f8fafc;
  border: 2px dashed #93c5fd;
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
  margin: 14px 0;
}

.qr-grid-box {
  width: 148px;
  height: 148px;
  margin: 10px auto;
  border-radius: 12px;
  background:
    linear-gradient(90deg, #0f172a 25%, transparent 25%, transparent 75%, #0f172a 75%),
    linear-gradient(0deg, #0f172a 25%, transparent 25%, transparent 75%, #0f172a 75%);
  background-size: 24px 24px;
  background-color: #ffffff;
  border: 6px solid #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-center-pill {
  background: #2563eb;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 6px;
}

/* Mobile Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 6px;
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.06);
}

.nav-item {
  flex: 1;
  height: 54px;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-item.active {
  color: var(--primary);
  background: #eff6ff;
}

.nav-icon {
  font-size: 1.15rem;
  line-height: 1;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 82px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy-900);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 70;
  white-space: nowrap;
}

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

/* SEO Section at Bottom */
.seo-overview {
  max-width: 1040px;
  margin: 12px auto 24px;
  padding: 0 16px;
}

.pillars-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.pillar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.pillar-card h3 {
  font-size: 0.98rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-main);
}

.pillar-card p {
  font-size: 0.86rem;
  color: var(--text-secondary);
}

/* Ollama Cloud AI Co-Pilot Bar & Multi-UOM Styles */
.ai-copilot-bar {
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 60%, #1e3a8a 100%);
  border: 1px solid #3b82f6;
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  color: #ffffff;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.16);
}

.ai-command-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.ai-command-input {
  flex: 1;
  min-width: 210px;
  height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
}

.ai-command-input::placeholder {
  color: #cbd5e1;
}

.ai-command-input:focus {
  border-color: #60a5fa;
  background: rgba(255, 255, 255, 0.15);
}

.uom-selector-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.uom-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.14s ease;
}

.uom-btn:hover {
  border-color: var(--primary);
  background: #eff6ff;
}

.barcode-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1;
}
