/* ============================================================================
   App UI styles — built on the sidebar template design tokens
   (cards, tables, forms, buttons, modals, badges, print)
   ========================================================================== */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

.page-subtitle {
  color: rgb(var(--muted-foreground));
  font-size: 13px;
  margin: 2px 0 0;
}

.page-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
}

@media (max-width: 640px) {
  .page-actions {
    width: 100%;
    flex-wrap: wrap;
  }
}

.card {
  background: rgb(var(--card));
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg);
  padding: 20px;
}

.card + .card,
.mt {
  margin-top: 16px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 14px;
}

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.stat-card {
  background: rgb(var(--card));
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg);
  padding: 18px;
}

.stat-label {
  font-size: 12px;
  color: rgb(var(--muted-foreground));
  margin-bottom: 6px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
}

.stat-sub {
  font-size: 12px;
  color: rgb(var(--muted-foreground));
  margin-top: 4px;
}

/* POS-style product catalog */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.product-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  background: rgb(var(--card));
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 20px rgb(15 23 42 / 0.06);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.product-card:hover {
  transform: translateY(-3px);
  border-color: rgb(var(--primary) / 0.45);
  box-shadow: 0 14px 28px rgb(15 23 42 / 0.12);
}

.product-card.is-inactive { opacity: 0.72; }

.product-card-head {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  height: 210px;
  min-height: 210px;
  padding: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, rgb(var(--primary) / 0.12), rgb(var(--sidebar-accent) / 0.5));
}

.product-card-head::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg, rgb(15 23 42 / 0.05), transparent 58%, rgb(15 23 42 / 0.22));
  content: "";
  pointer-events: none;
}

.product-avatar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: linear-gradient(135deg, rgb(var(--primary)), rgb(var(--ring)));
  color: rgb(var(--primary-foreground));
  font-size: 42px;
  font-weight: 800;
  box-shadow: 0 8px 16px rgb(var(--primary) / 0.24);
}

.product-image {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 0;
  border-radius: 0;
  background: rgb(var(--card));
}

.product-card-head > .badge-pill {
  position: relative;
  z-index: 2;
}

.product-card-body {
  flex: 1;
  padding: 16px;
}

.product-code {
  color: rgb(var(--muted-foreground));
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.product-name {
  margin: 5px 0 2px;
  color: rgb(var(--foreground));
  font-size: 17px;
  line-height: 1.25;
}

.product-category {
  min-height: 18px;
  margin: 0;
  color: rgb(var(--muted-foreground));
  font-size: 12px;
}

.product-pack {
  margin: 8px 0 0;
  color: rgb(var(--primary));
  font-size: 12px;
  font-weight: 700;
}

.product-card-price {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgb(var(--border));
}

.product-card-price > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.product-label,
.product-unit {
  color: rgb(var(--muted-foreground));
  font-size: 11px;
}

.product-card-price strong {
  color: rgb(var(--primary));
  font-size: 22px;
}

.product-unit { white-space: nowrap; }

.product-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 14px;
  color: rgb(var(--muted-foreground));
  font-size: 11px;
}

.product-card-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid rgb(var(--border));
  background: rgb(var(--sidebar-accent) / 0.22);
}

.product-card-actions .btn { flex: 1; justify-content: center; }
.product-grid-empty { grid-column: 1 / -1; padding: 48px 20px; text-align: center; }

/* Dashboard-only visual treatment */
.dashboard-page {
  min-height: 100%;
  margin: -16px;
  padding: 24px;
  background:
    radial-gradient(circle at 0% 0%, rgb(129 140 248 / 0.2), transparent 28%),
    radial-gradient(circle at 100% 12%, rgb(45 212 191 / 0.16), transparent 26%),
    linear-gradient(145deg, #f8faff 0%, #f5f3ff 52%, #f0fdfa 100%);
}

.dashboard-page .page-head {
  padding: 18px 20px;
  border: 1px solid rgb(255 255 255 / 0.8);
  border-radius: var(--radius-lg);
  background: linear-gradient(115deg, rgb(255 255 255 / 0.9), rgb(238 242 255 / 0.78));
  box-shadow: 0 12px 28px rgb(79 70 229 / 0.08);
}

.dashboard-page .grid-stats .stat-card {
  position: relative;
  overflow: hidden;
  border-color: rgb(255 255 255 / 0.75);
  box-shadow: 0 10px 24px rgb(51 65 85 / 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.dashboard-page .grid-stats .stat-card::after {
  position: absolute;
  right: -24px;
  bottom: -34px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.32);
  content: "";
}

.dashboard-page .grid-stats .stat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 30px rgb(51 65 85 / 0.14);
}

.dashboard-page .grid-stats .stat-card:nth-child(1) { border-top: 3px solid #6366f1; background: linear-gradient(135deg, #ffffff, #eef2ff); }
.dashboard-page .grid-stats .stat-card:nth-child(2) { border-top: 3px solid #0ea5e9; background: linear-gradient(135deg, #ffffff, #eff6ff); }
.dashboard-page .grid-stats .stat-card:nth-child(3) { border-top: 3px solid #10b981; background: linear-gradient(135deg, #ffffff, #ecfdf5); }
.dashboard-page .grid-stats .stat-card:nth-child(4) { border-top: 3px solid #f59e0b; background: linear-gradient(135deg, #ffffff, #fffbeb); }
.dashboard-page .grid-stats .stat-card:nth-child(5) { border-top: 3px solid #f43f5e; background: linear-gradient(135deg, #ffffff, #fff1f2); }
.dashboard-page .grid-stats .stat-card:nth-child(6) { border-top: 3px solid #8b5cf6; background: linear-gradient(135deg, #ffffff, #f5f3ff); }
.dashboard-page .grid-stats .stat-card:nth-child(7) { border-top: 3px solid #14b8a6; background: linear-gradient(135deg, #ffffff, #f0fdfa); }
.dashboard-page .grid-stats .stat-card:nth-child(8) { border-top: 3px solid #f97316; background: linear-gradient(135deg, #ffffff, #fff7ed); }
.dashboard-page .grid-stats .stat-card:nth-child(9) { border-top: 3px solid #ec4899; background: linear-gradient(135deg, #ffffff, #fdf2f8); }

.dashboard-page > div[style*="grid-template-columns"] > .card {
  background: rgb(var(--card) / 0.92);
  box-shadow: 0 10px 24px rgb(51 65 85 / 0.06);
}

.dashboard-page .bar-val {
  background: linear-gradient(180deg, #8b5cf6, #06b6d4);
}

[data-theme="dark"] .dashboard-page {
  background:
    radial-gradient(circle at 0% 0%, rgb(99 102 241 / 0.25), transparent 30%),
    radial-gradient(circle at 100% 12%, rgb(20 184 166 / 0.18), transparent 28%),
    linear-gradient(145deg, #0f172a 0%, #171433 54%, #062c2b 100%);
}

[data-theme="dark"] .dashboard-page .page-head {
  border-color: rgb(148 163 184 / 0.16);
  background: linear-gradient(115deg, rgb(30 41 59 / 0.94), rgb(49 46 129 / 0.55));
  box-shadow: 0 12px 28px rgb(2 6 23 / 0.28);
}

[data-theme="dark"] .dashboard-page .grid-stats .stat-card {
  border-color: rgb(148 163 184 / 0.16);
  box-shadow: 0 12px 26px rgb(2 6 23 / 0.24);
}

[data-theme="dark"] .dashboard-page .grid-stats .stat-card:nth-child(1) { background: linear-gradient(135deg, #1e1b4b, #312e81); }
[data-theme="dark"] .dashboard-page .grid-stats .stat-card:nth-child(2) { background: linear-gradient(135deg, #172554, #075985); }
[data-theme="dark"] .dashboard-page .grid-stats .stat-card:nth-child(3) { background: linear-gradient(135deg, #052e2b, #065f46); }
[data-theme="dark"] .dashboard-page .grid-stats .stat-card:nth-child(4) { background: linear-gradient(135deg, #422006, #92400e); }
[data-theme="dark"] .dashboard-page .grid-stats .stat-card:nth-child(5) { background: linear-gradient(135deg, #4c0519, #9f1239); }
[data-theme="dark"] .dashboard-page .grid-stats .stat-card:nth-child(6) { background: linear-gradient(135deg, #2e1065, #6d28d9); }
[data-theme="dark"] .dashboard-page .grid-stats .stat-card:nth-child(7) { background: linear-gradient(135deg, #042f2e, #0f766e); }
[data-theme="dark"] .dashboard-page .grid-stats .stat-card:nth-child(8) { background: linear-gradient(135deg, #431407, #c2410c); }
[data-theme="dark"] .dashboard-page .grid-stats .stat-card:nth-child(9) { background: linear-gradient(135deg, #500724, #be185d); }

@media (max-width: 640px) {
  .dashboard-page {
    margin: -16px;
    padding: 16px;
  }

  .dashboard-page .page-head {
    padding: 16px;
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid rgb(var(--border));
  background: rgb(var(--card));
  color: rgb(var(--foreground));
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  line-height: 1.4;
}

.btn:hover { border-color: rgb(var(--primary)); color: rgb(var(--primary)); }

.btn-primary {
  background: rgb(var(--primary));
  border-color: rgb(var(--primary));
  color: rgb(var(--primary-foreground));
}
.btn-primary:hover { opacity: 0.9; color: rgb(var(--primary-foreground)); }

.btn-danger { color: #dc2626; }
.btn-danger:hover { border-color: #dc2626; background: #fef2f2; color: #dc2626; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.actions-cell { white-space: nowrap; display: flex; gap: 6px; }

/* Tables */
.table-wrap {
  overflow-x: auto;
  background: rgb(var(--card));
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid rgb(var(--border));
  vertical-align: middle;
}

.data-table th {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgb(var(--muted-foreground));
  background: rgb(var(--sidebar-accent) / 0.5);
  white-space: nowrap;
}

.data-table tbody tr:hover { background: rgb(var(--sidebar-accent) / 0.35); }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .muted { color: rgb(var(--muted-foreground)); }
.table-total-row td { font-weight: 700; background: rgb(var(--sidebar-accent) / 0.5); }

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

label.lbl {
  font-size: 12px;
  font-weight: 600;
  color: rgb(var(--muted-foreground));
}

input[type="text"], input[type="number"], input[type="date"], input[type="time"],
input[type="password"], input[type="email"], input[type="tel"], input[type="url"], select, textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  color: rgb(var(--foreground));
  background: rgb(var(--background));
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: rgb(var(--ring));
  box-shadow: 0 0 0 3px rgb(var(--ring) / 0.25);
}

textarea { min-height: 80px; resize: vertical; }

.checks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-md);
  font-size: 13px;
  cursor: pointer;
  background: rgb(var(--background));
}

.check-item input { accent-color: rgb(var(--primary)); }

.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  align-items: flex-end;
  gap: 14px;
  margin: 0 0 18px;
  padding: 16px;
  background: rgb(var(--card));
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 22px rgb(15 23 42 / 0.05);
}

.filter-bar .form-group {
  min-width: 0;
}

.filter-bar .form-group > input,
.filter-bar .form-group > select {
  min-height: 38px;
}

.filter-bar .check-item {
  min-height: 38px;
  margin: 0;
  align-self: end;
}

.filter-bar > .btn {
  width: 100%;
  min-height: 38px;
  justify-content: center;
}

@media (max-width: 640px) {
  .filter-bar {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px;
  }

  .filter-bar .check-item,
  .filter-bar > .btn {
    width: 100%;
  }
}

/* Badges */
.badge-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.b-green { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.b-red   { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.b-amber { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.b-blue  { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.b-gray  { background: rgb(var(--sidebar-accent)); color: rgb(var(--muted-foreground)); border-color: rgb(var(--border)); }

/* Flash messages */
.flash-stack { margin-bottom: 16px; }

.flash {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 8px;
  border: 1px solid transparent;
}

.flash-success { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.flash-info    { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.55);
}

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

.modal {
  background: rgb(var(--card));
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgb(var(--border));
  font-weight: 600;
}

.modal-body { padding: 18px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid rgb(var(--border));
}

/* Sale line items editor */
.item-row-grid {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) 90px 110px 110px 110px 36px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.item-head-grid {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) 90px 110px 110px 110px 36px;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: rgb(var(--muted-foreground));
  margin-bottom: 6px;
  padding: 0 2px;
}

.rm-row {
  height: 34px;
  border: 1px solid rgb(var(--border));
  background: rgb(var(--card));
  border-radius: var(--radius-md);
  font-size: 16px;
  cursor: pointer;
  color: rgb(var(--muted-foreground));
}
.rm-row:hover { color: #dc2626; border-color: #dc2626; }

.line-stock { font-size: 12px; color: rgb(var(--muted-foreground)); border: none !important; background: transparent !important; padding-left: 0; }
.line-amt { border: none !important; background: transparent !important; padding-left: 0; font-weight: 600; }

.sale-totals { max-width: 320px; margin-left: auto; margin-top: 14px; }
.sale-totals .row { display: flex; justify-content: space-between; padding: 6px 2px; font-size: 14px; }
.sale-totals .row.grand { font-weight: 700; font-size: 16px; border-top: 1px solid rgb(var(--border)); margin-top: 4px; padding-top: 10px; }

/* Invoice print sheet */
.invoice-sheet {
  background: #fff;
  color: #111;
  max-width: 720px;
  margin: 0 auto;
  padding: 28px;
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg);
}
.invoice-sheet h2 { margin: 0; }
.invoice-meta { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 14px 0; font-size: 13px; }
.invoice-sheet table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
.invoice-sheet th, .invoice-sheet td { border: 1px solid #d4d4d8; padding: 7px 10px; text-align: left; }
.invoice-sheet th { background: #fafafa; }

/* Charts (pure CSS bars) */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-val {
  width: 70%;
  max-width: 46px;
  background: rgb(var(--primary) / 0.85);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
}
.bar-lbl { font-size: 10px; color: rgb(var(--muted-foreground)); white-space: nowrap; }

/* Auth page */
.auth-wrap {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-x: hidden;
  background:
    radial-gradient(800px 400px at 20% -10%, rgb(var(--ring) / 0.18), transparent),
    radial-gradient(700px 380px at 110% 110%, rgb(var(--primary) / 0.15), transparent);
}

.auth-card {
  width: min(100%, calc(100vw - 48px));
  max-width: 400px;
  min-width: 0;
  background: rgb(var(--card));
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.08);
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: rgb(var(--primary));
  color: rgb(var(--primary-foreground));
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 12px;
}

@media (max-width: 640px) {
  .auth-wrap {
    padding: 16px;
  }

  .auth-card {
    width: 100%;
    max-width: 100%;
    padding: 22px;
  }
}

.map-frame {
  height: 480px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid rgb(var(--border));
}
#liveMap, #historyMap { height: 100%; width: 100%; }

.empty-state {
  text-align: center;
  color: rgb(var(--muted-foreground));
  padding: 32px 16px;
  font-size: 13px;
}

.text-right { text-align: right; }
.flex { display: flex; }
.gap { gap: 10px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.mt0 { margin-top: 0; }
.mb { margin-bottom: 16px; }
.muted { color: rgb(var(--muted-foreground)); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.w-auto { width: auto; }

/* Print */
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area {
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
  }
  .no-print { display: none !important; }
  .invoice-sheet { border: none; }
}

@media (max-width: 720px) {
  .item-row-grid, .item-head-grid {
    grid-template-columns: 1fr 70px 90px 90px 36px;
  }
  .line-stock { display: none; }
}
