/* =======================================================
   GLOBAL THEME VARIABLES (Editable via config.json)
======================================================= */
:root {
  --primary: #0b61ff;
  --primary-light: #e0ebff;
  --text: #0b2545;
  --bg: #f5f7fb;
  --card-bg: #ffffff;
  --border: #dbe7ff;
  --radius: 14px;
}

/* Simple theme helpers */
.theme-primary { color: var(--primary); }
.theme-bg      { background: var(--bg); }
.theme-card    { background: var(--card-bg); }
.theme-border  { border-color: var(--border); }

/* =======================================================
   RESET / BASE
======================================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
}

/* Prevent weird zoom tricks on mobile */
html {
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
}
body {
  max-width: 100%;
}

/* =======================================================
   LAYOUT
======================================================= */
.wrap {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

.card {
  width: 100%;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 6px 18px rgba(11, 37, 69, 0.06);
  display: block;
}


.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
}


@media (max-width: 980px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

h1, h2, h3, h4 {
  margin: 0 0 12px 0;
  color: var(--text);
}

.small {
  font-size: 13px;
  color: #475569;
}

/* FLEX UTILS */
.flex {
  display: flex;
  align-items: center;
}
.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.flex-col {
  display: flex;
  flex-direction: column;
}

/* =======================================================
   BUTTONS
======================================================= */
button,
.btn {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--primary);
  color: white;
  font-size: 15px;
  transition: 0.15s ease;
}

button:hover,
.btn:hover {
  opacity: 0.9;
}

button:disabled,
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-danger {
  background: #ef4444 !important;
}

/* =======================================================
   FORM CONTROLS
======================================================= */
input,
select,
textarea {
  width: 100%;
  padding: 8px;
  font-size: 16px;          /* avoid iOS auto-zoom */
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

/* Restrict 100% width to proper forms (not table cells) */
.form-vertical input,
.form-vertical select,
.form-vertical textarea,
.form-control {
  width: 100%;
}

/* =======================================================
   TABLES (BASE)
======================================================= */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px;
  border-bottom: 1px solid #eef6ff;
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
}

thead {
  background: var(--primary-light);
}

/* PRODUCTS TABLE */
#prodTable {
  min-width: 600px;
}
#prodTable td:nth-child(2) {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Generic orders table class (desktop) */
.orders-table {
  width: 100%;
}

/* Desktop: show full table, more space */
@media (min-width: 721px) {
  .orders-table {
    table-layout: auto;
    min-width: 900px;
  }

  .orders-table th,
  .orders-table td {
    padding: 12px 14px;
    font-size: 15px;
    white-space: nowrap;
    vertical-align: middle;
  }
}

/* =======================================================
   MOBILE ADAPTATION
======================================================= */
@media (max-width: 640px) {
  .wrap {
    padding: 12px;
  }

  .card {
    padding: 12px;
  }

  .btn {
    width: 100%;
  }

  /* Stack catalog products vertically */
  .product {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  #cartList {
    max-height: 220px;
  }
}

/* =======================================================
   MOBILE ORDERS — CARD VIEW
======================================================= */
/* Desktop: table visible, mobile cards hidden */
.orders-list-mobile {
  display: none;
}

@media (max-width: 720px) {
  /* Hide table on mobile, we use cards instead */
  .orders-table {
    display: none;
  }

  .orders-list-mobile {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 4px;
  }

  .order-card {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 12px;
    background: #ffffff;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
  }

  .order-card-main {
    cursor: pointer;
  }

  .order-card-line {
    font-size: 13px;
    margin-bottom: 4px;
  }
  .order-card-line span {
    font-weight: 600;
    color: #4b5563;
    margin-right: 4px;
  }

  .order-card-line b {
    font-weight: 600;
  }

  .order-card-status {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
  }

  .order-card-status label {
    font-size: 12px;
    color: #6b7280;
  }

  .order-card-status select {
    width: 100%;
    font-size: 14px;
    padding: 6px 8px;
  }

  .order-card-details {
    margin-top: 8px;
    border-top: 1px dashed #e5e7eb;
    padding-top: 6px;
    font-size: 13px;
    color: #475569;
    display: none;
  }

  .order-card-details table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 4px;
  }

  .order-card-details th,
  .order-card-details td {
    padding: 4px 6px;
    font-size: 12px;
  }

  .order-card-details th {
    background: #eef6ff;
  }
}

/* =======================================================
   PRODUCT / CATALOG CARDS (order page)
======================================================= */
.product {
  display: flex;
  justify-content: space-between;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #eef6ff;
  background: #fff;
  margin-bottom: 10px;
  gap: 12px;
}

.p-left {
  max-width: 65%;
}

.qty {
  width: 80px;
}

.catalog {
  max-height: 500px;
  overflow-y: auto;
  padding-right: 6px;
}
.catalog::-webkit-scrollbar {
  width: 6px;
}
.catalog::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 6px;
}

/* Inactive product highlight */
.row-inactive {
  border-left: 4px solid #ef4444;
  background: #fff2f2;
}

/* CART */
.cart-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed #eef6ff;
  gap: 12px;
}

/* =======================================================
   INVOICE / PRINT SUPPORT (used by invoice.html)
======================================================= */
.invoice-container {
  max-width: 820px;
  margin: auto;
}

/* generic container used in invoice.html */
.container {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 12px;
}

.invoice-header {
  padding: 10px 0 8px 0;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(11,37,69,0.04);
}
.invoice-header .company {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  margin-bottom: 6px;
}

/* Print button (invoice) */
.print-btn {
  float: right;
  margin: 6px 0 12px 12px;
  background: white;
  color: var(--text);
  border: 1px solid rgba(11,37,69,0.06);
  padding: 8px 12px;
  border-radius: 8px;
}

/* table variant used inside invoice */
.table {
  width: 100%;
  border-collapse: collapse;
}
.table thead th {
  background: var(--primary-light);
  font-weight: 600;
  padding: 10px 12px;
}
.table tbody td {
  padding: 10px 12px;
  color: #475569;
}

.grand-total {
  font-weight: 700;
  margin-top: 12px;
  font-size: 1.05rem;
  color: var(--text);
}

@media (max-width: 640px) {
  .print-btn {
    float: none;
    display: inline-block;
    width: auto;
    margin-bottom: 12px;
  }
}

@media print {
  body {
    background: white;
  }
  .btn,
  .print-btn {
    display: none !important;
  }
  .card {
    box-shadow: none;
    border: none;
    padding: 0;
  }
  .container {
    max-width: 100%;
    padding: 0;
    margin: 0;
  }
  table,
  .table {
    min-width: 0 !important;
    width: 100% !important;
  }
}

/* =======================================================
   AUTH / SMALL CARDS (login, track)
======================================================= */
.page-center {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

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

.track-card {
  width: 100%;
  max-width: 480px;
}

.form-vertical label {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  color: var(--text);
}
.form-vertical input {
  margin-top: 4px;
}
.form-vertical button {
  margin-top: 12px;
}

/* Legacy box */
.box {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 6px 18px rgba(11,37,69,0.06);
  width: 100%;
  max-width: 380px;
  margin: 40px auto;
}
/* Hide right-side panels on mobile */
@media (max-width: 720px) {
  .products-list-mobile {
  display: none !important;
}
  .desktop-only {
    display: none !important;
  }
}


/* PRODUCT MOBILE CARDS (P3 STYLE) */
.product-card {
  border: 1px solid #e5e7eb;
  background: #fff;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 10px;
}

.product-card-head {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 6px;
}

.product-card-line {
  margin: 2px 0;
  font-size: 14px;
  color: #475569;
}

.product-card-actions {
  margin-top: 8px;
}

.product-card-details {
  display: none;
  margin-top: 8px;
  padding: 10px;
  border-top: 1px solid #e2e8f0;
  font-size: 14px;
  background: #f8fafc;
}

/* Hide only desktop product table on mobile */
@media(max-width:720px){
  #prodTable {
    display: none;
  }
}
/* Hide mobile product cards in desktop */
@media (min-width: 721px) {
  .products-list-mobile {
    display: none !important;
  }
}
.product-card.inactive {
  border-left: 4px solid #ef4444 !important;
  background: #fff2f2 !important;
}





/* Strong override: hide desktop-only panels on mobile */
@media (max-width: 720px) {
  .desktop-only,
  .desktop-only.card,
  .desktop-only * {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
  }

   .grid {
    grid-template-columns: 1fr !important;
  }
}

.desktop-only {
    overflow-x: auto;
  }


  .variant-row {
  display: flex;
  align-items: center;
  margin: 6px 0;
  padding: 6px;
  border-bottom: 1px solid #eee;
}

.variant-size {
  width: 90px;
  font-weight: 600;
}

.variant-units button {
  margin-right: 6px;
  padding: 4px 10px;
  border: none;
  background: var(--accent, #4e8cff);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
}

.qty-input {
  margin-left: auto;
  width: 70px;
  padding: 4px;
}


/* =======================================================
   CATALOG V2 – EXPANDABLE ITEMS + VARIANTS
======================================================= */

.catalog-header {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.catalog-header input {
  flex: 1;
}

.expand-controls {
  display: flex;
  gap: 6px;
}

/* Ghost button for secondary actions */
.btn-ghost {
  background: #ffffff;
  color: var(--primary);
  border: 1px solid var(--border);
  padding: 6px 10px;
  font-size: 13px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}

/* Item card inside catalog */
.catalog-item {
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  margin-bottom: 10px;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.04);
}

/* Accordion */
.item-details {
  border-radius: 12px;
  overflow: hidden;
}

.item-details[open] {
  border-color: var(--primary-light);
  background: #f8fafc;
}

.item-summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
}

.item-summary::-webkit-details-marker {
  display: none;
}

.item-details summary::before {
  content: "▸";
  margin-right: 8px;
  font-size: 12px;
  transition: transform 0.15s ease;
  color: #64748b;
}

.item-details[open] summary::before {
  transform: rotate(90deg);
}

.item-title {
  font-weight: 600;
}

.item-meta {
  font-size: 12px;
  color: #64748b;
}

.item-body {
  padding: 8px 12px 12px;
  border-top: 1px solid #e2e8f0;
}

/* Type Blocks */
.type-block {
  margin-top: 4px;
}

.type-header {
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  margin: 6px 0;
}

/* Variant row */
.variant-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px dashed #e5e7eb;
  gap: 8px;
}

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

.variant-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.variant-size {
  font-weight: 600;
  font-size: 14px;
}

.variant-unit {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-light);
  color: #1e293b;
}

.variant-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.variant-qty {
  width: 70px;
  padding: 6px 8px;
  font-size: 14px;
}

/* Override old variant styles if any */
.variant-units button {
  all: unset;
}

/* Mobile tweaks */
@media (max-width: 640px) {
  .catalog-header {
    flex-direction: column;
    align-items: stretch;
  }

  .expand-controls {
    justify-content: flex-start;
  }

  .variant-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .variant-actions {
    width: 100%;
    justify-content: flex-start;
  }
}


/* =======================================================
   UNIT FILTER CHIPS
======================================================= */
.unit-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 10px;
}

.unit-chip {
  border-radius: 999px;
  padding: 4px 10px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  font-size: 12px;
  cursor: pointer;
  color: #475569;
}

.unit-chip.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: #0f172a;
  font-weight: 600;
}

@media (max-width: 640px) {
  .unit-filters {
    justify-content: flex-start;
  }
}
/* =======================================================
   TYPE + UNIT GROUPING IN CATALOG
======================================================= */

.type-block {
  margin-top: 4px;
}

.type-header {
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  margin: 6px 0 2px;
}

.unit-block {
  margin: 4px 0 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px dashed #e2e8f0;
}

.unit-header {
  font-size: 12px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 4px;
}

/* The variant-row / actions styling you had is reused */

/* ------------------------------
   MOBILE FIX PACK (Admin v2)
-------------------------------- */

/* 1. Improve header responsiveness */
@media (max-width: 640px) {
  .admin-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .admin-top-right {
    width: 100%;
    justify-content: space-between;
  }

  .tab-bar {
    flex-wrap: wrap;
    width: 100%;
  }

  .tab-link {
    flex: 1;
    text-align: center;
  }
}

/* 2. Fix grid panels squeezing on mobile */
@media (max-width: 720px) {
  .grid {
    grid-template-columns: 1fr !important;
  }
}

/* 3. FORCE desktop-only right panels to hide */
@media (max-width: 720px) {
  .desktop-only {
    display: none !important;
  }
}

/* 4. Fix card spacing / width on mobile */
@media (max-width: 640px) {
  .card {
    padding: 14px;
    border-radius: 10px;
  }
}

/* 5. Orders table → convert to cards properly */
@media (max-width: 720px) {
  .orders-table {
    display: none !important;
  }
  #ordersListMobile {
    display: flex !important;
    flex-direction: column;
    gap: 10px;
  }
}

/* 6. Product table → convert to cards on mobile */
@media (max-width: 720px) {
  #prodTable {
    display: none !important;
  }

  .products-list-mobile {
    display: block !important;
  }
}

/* 7. Product editor moves below selected product */
@media (max-width: 720px) {
  #productEditorWrapper {
    margin-top: 12px;
  }
}

/* 8. Fix button stretching on mobile */
@media (max-width: 640px) {
  .btn {
    width: 100%;
  }
}

@media (max-width:720px) {
  .products-list-mobile {
    display: block !important;
  }
}