/*
 * ═══════════════════════════════════════════════════════════════
 *  CCare Kitchen — Design System
 *  All components defined here. Use these classes everywhere.
 *  Do not write inline styles for layout, spacing, or colour.
 * ═══════════════════════════════════════════════════════════════
 *
 *  TOKENS   →  :root in styles.css (--forest, --moss, --border…)
 *  PRIMITIVES → .btn, .card, input, select  in styles.css
 *  COMPONENTS → this file
 *
 *  Index:
 *    1. Page header
 *    2. Section tabs  (primary nav within a page)
 *    3. Filter chips  (content filtering — All | Meals | Grocery…)
 *    4. Filter bar    (search + chips layout)
 *    5. List / table  (rows, group headers, empty state)
 *    6. Status badges
 *    7. Action button row
 *    8. Info / alert banners
 *    9. Modals
 *   10. Stats summary row
 */

/* ═══════════════════════════════════════════════
   1. PAGE HEADER
   .ds-page-hd  — top of every tab/sub-page
   ═══════════════════════════════════════════════ */
.ds-page-hd {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.ds-page-title {
  font-family: 'Lora', serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--forest);
  letter-spacing: -.3px;
  line-height: 1.2;
}
.ds-page-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.4;
}
.ds-page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   2. SECTION TABS  (primary within-page navigation)
   Usage: <div class="ds-tabs"><button class="ds-tab active">…
   ═══════════════════════════════════════════════ */
.ds-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.ds-tabs::-webkit-scrollbar { display: none; }

.ds-tab {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.ds-tab:hover:not(.active) {
  color: var(--forest);
  border-bottom-color: var(--mint);
}
.ds-tab.active {
  color: var(--forest);
  border-bottom-color: var(--forest);
}
/* Alias for existing class name — both work */
.stock-sub-tab { composes: ds-tab; }

/* ═══════════════════════════════════════════════
   3. FILTER CHIPS  (content type / status filtering)
   Usage: <div class="ds-chips"><button class="ds-chip active">All <span>5</span>
   ═══════════════════════════════════════════════ */
.ds-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.ds-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: #fff;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  line-height: 1;
}
.ds-chip:hover:not(.active) {
  border-color: var(--sage);
  color: var(--forest);
  background: #f4faf6;
}
.ds-chip.active {
  background: var(--forest);
  border-color: var(--forest);
  color: #fff;
}
.ds-chip .ds-chip-ct {
  font-size: 10px;
  font-weight: 700;
  background: rgba(255,255,255,.2);
  color: inherit;
  border-radius: 10px;
  padding: 1px 5px;
  line-height: 1.2;
}
.ds-chip.active .ds-chip-ct {
  background: rgba(255,255,255,.25);
}
/* Colour variants for status chips */
.ds-chip.chip-ok     { border-color: var(--mint); color: var(--moss); background: #f0f7f3; }
.ds-chip.chip-warn   { border-color: #f0d090; color: #8a5a00; background: #fef9e8; }
.ds-chip.chip-error  { border-color: #f5c4ae; color: var(--tc); background: #fdf0ea; }
.ds-chip.chip-blue   { border-color: #c0d8f5; color: var(--blue); background: var(--blue-light); }

/* ═══════════════════════════════════════════════
   4. FILTER BAR  (search input + chips + extras)
   Usage: <div class="ds-filter-bar">
   ═══════════════════════════════════════════════ */
.ds-filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.ds-search {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  transition: border-color .15s;
}
.ds-search:focus-within { border-color: var(--sage); }
.ds-search-icon { font-size: 14px; color: var(--muted); flex-shrink: 0; }
.ds-search input {
  border: none;
  padding: 0;
  font-size: 13px;
  background: none;
  width: 100%;
  color: var(--text);
  outline: none;
}
.ds-search input::placeholder { color: var(--muted); }
.ds-filter-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   5. LIST / TABLE
   ═══════════════════════════════════════════════ */

/* Container */
.ds-list {
  background: #fff;
  border-radius: 13px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}

/* Column header row (optional — use for tabular data) */
.ds-list-thead {
  display: grid;
  padding: 8px 16px;
  background: #f8f5f0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

/* Group / section header row */
.ds-list-group {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  background: var(--forest);
  color: #fff;
}
.ds-list-group-icon { font-size: 16px; line-height: 1; }
.ds-list-group-name {
  font-weight: 700;
  font-size: 13px;
  flex: 1;
}
.ds-list-group-ct {
  font-size: 11px;
  opacity: .65;
  font-weight: 500;
}

/* Standard data row */
.ds-list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-top: 1px solid #f0ede8;
  font-size: 13px;
  transition: background .1s;
  cursor: pointer;
}
.ds-list-row:first-child { border-top: none; }
.ds-list-row:hover { background: #fdfaf6; }
.ds-list-row.active { background: #f0f7f3; }
.ds-list-row.row-warn { background: #fffbf0; }
.ds-list-row.row-error { background: #fff5f3; }

/* Row inner layout helpers */
.ds-row-main { flex: 1; min-width: 0; }
.ds-row-title {
  font-weight: 600;
  color: var(--forest);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ds-row-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.ds-row-value {
  font-weight: 700;
  font-size: 14px;
  color: var(--forest);
  flex-shrink: 0;
}
.ds-row-unit {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
  margin-left: 2px;
}
.ds-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .15s;
}
.ds-list-row:hover .ds-row-actions { opacity: 1; }

/* Empty state */
.ds-list-empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}
.ds-list-empty-icon { font-size: 40px; margin-bottom: 12px; }
.ds-list-empty-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--forest);
  margin-bottom: 6px;
}
.ds-list-empty-body {
  font-size: 13px;
  max-width: 380px;
  margin: 0 auto 20px;
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════
   6. STATUS BADGES
   Usage: <span class="ds-badge ds-badge-ok">Active</span>
   ═══════════════════════════════════════════════ */
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid transparent;
  line-height: 1.4;
}
.ds-badge-ok      { background: #edf7f1; color: var(--moss);   border-color: var(--mint); }
.ds-badge-warn    { background: #fef9e8; color: #8a5a00;       border-color: #f0d090; }
.ds-badge-error   { background: #fdf0ea; color: var(--tc);     border-color: #f5c4ae; }
.ds-badge-info    { background: var(--blue-light); color: var(--blue); border-color: #c0d8f5; }
.ds-badge-purple  { background: var(--purple-light); color: var(--purple); border-color: #c9bde8; }
.ds-badge-neutral { background: #f0ede8; color: var(--muted);  border-color: var(--border); }
.ds-badge-dark    { background: var(--forest); color: #fff;    border-color: var(--forest); }
/* Dot indicator */
.ds-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ds-dot-ok    { background: var(--moss); }
.ds-dot-warn  { background: #e9a84c; }
.ds-dot-error { background: var(--tc); }
.ds-dot-muted { background: #ccc; }

/* ═══════════════════════════════════════════════
   7. ACTION BUTTON ROW
   Usage: <div class="ds-actions"><button class="btn btn-p">…
   ═══════════════════════════════════════════════ */
.ds-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.ds-actions-right { justify-content: flex-end; }

/* Icon button — small round action */
.ds-icon-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.ds-icon-btn:hover {
  border-color: var(--sage);
  color: var(--forest);
  background: #f4faf6;
}
.ds-icon-btn.danger:hover {
  border-color: var(--tc);
  color: var(--tc);
  background: var(--tc-light);
}

/* ═══════════════════════════════════════════════
   8. INFO / ALERT BANNERS
   ═══════════════════════════════════════════════ */
.ds-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.5;
}
.ds-banner-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.ds-banner-info   { background: var(--blue-light);  border-color: #c0d8f5;  color: #1a3a6b; }
.ds-banner-warn   { background: #fef9e8;             border-color: #f0d090;  color: #7a5a00; }
.ds-banner-error  { background: var(--tc-light);     border-color: #f5c4ae;  color: #8a2000; }
.ds-banner-ok     { background: #edf7f1;             border-color: var(--mint); color: #1a4a30; }
.ds-banner-neutral{ background: #f8f5f1;             border-color: var(--border); color: var(--text); }

/* ═══════════════════════════════════════════════
   9. MODALS  (standard structure)
   ═══════════════════════════════════════════════ */
.ds-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.ds-modal {
  background: #fff;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,.3);
  max-height: 94vh;
  width: 640px;
  max-width: 98vw;
}
.ds-modal-lg { width: 900px; }
.ds-modal-sm { width: 480px; }

.ds-modal-header {
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.ds-modal-title {
  font-family: 'Lora', serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--forest);
  line-height: 1.2;
}
.ds-modal-subtitle {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}
.ds-modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
  padding: 2px;
  line-height: 1;
  transition: color .15s;
}
.ds-modal-close:hover { color: var(--text); }

.ds-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
}
.ds-modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* Modal tabs (within a modal) */
.ds-modal-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}
.ds-modal-tabs::-webkit-scrollbar { display: none; }
.ds-modal-tab {
  padding: 8px 16px;
  background: none;
  border: none;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1.5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.ds-modal-tab:hover:not(.active) { color: var(--forest); }
.ds-modal-tab.active { color: var(--forest); border-bottom-color: var(--forest); }

/* ═══════════════════════════════════════════════
   10. STATS / SUMMARY ROW
   Usage: <div class="ds-stats"><div class="ds-stat">…
   ═══════════════════════════════════════════════ */
.ds-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.ds-stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 13px 16px;
  text-align: center;
}
.ds-stat-value {
  font-family: 'Lora', serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--forest);
  line-height: 1.1;
  display: block;
}
.ds-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-top: 3px;
  display: block;
}
/* Colour variants */
.ds-stat-ok    { border-color: var(--mint); background: #f0f7f3; }
.ds-stat-ok .ds-stat-value { color: var(--moss); }
.ds-stat-warn  { border-color: #f0d090; background: #fef9e8; }
.ds-stat-warn .ds-stat-value { color: #8a5a00; }
.ds-stat-error { border-color: #f5c4ae; background: #fdf0ea; }
.ds-stat-error .ds-stat-value { color: var(--tc); }

/* ═══════════════════════════════════════════════
   FORM SECTION
   Standard labelled field groups inside modals/forms
   ═══════════════════════════════════════════════ */
.ds-form-section {
  background: #f8f5f1;
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.ds-form-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 12px;
}
.ds-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.ds-form-grid-full { grid-column: 1 / -1; }
.ds-form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 560px) {
  .ds-form-grid { grid-template-columns: 1fr; }
}
.ds-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 5px;
}
.ds-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  box-sizing: border-box;
  outline: none;
  transition: border-color .15s;
}
.ds-input:focus { border-color: var(--moss); }

/* ═══════════════════════════════════════════════
   UTILITY HELPERS
   ═══════════════════════════════════════════════ */
.ds-divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
  border: none;
}
.ds-muted   { color: var(--muted); }
.ds-forest  { color: var(--forest); }
.ds-mono    { font-family: monospace; }
.ds-truncate{ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-flex-center { display: flex; align-items: center; gap: 8px; }
.ds-flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Loading state */
.ds-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
  font-size: 13px;
  gap: 8px;
}

/* ═══════════════════════════════════════
   BACKWARD COMPAT — old class aliases
   Maps legacy class names to design system
   ═══════════════════════════════════════ */

/* stock-type-pill → ds-chip behaviour already handled by JS;
   keep old class styled same as ds-chip for any remaining HTML */
.stock-type-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: #fff;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.stock-type-pill:hover:not(.active) {
  border-color: var(--sage);
  color: var(--forest);
  background: #f4faf6;
}
.stock-type-pill.active {
  background: var(--forest);
  border-color: var(--forest);
  color: #fff;
}
.pill-ct {
  font-size: 10px;
  font-weight: 700;
  background: rgba(255,255,255,.2);
  border-radius: 10px;
  padding: 1px 5px;
}
.stock-type-pill.active .pill-ct { background: rgba(255,255,255,.25); }

/* stock-filter-bar → ds-filter-bar */
.stock-filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.stock-filter-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

/* stock-actions-row → ds-actions */
.stock-actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

/* Alert chips in stock — keep existing sac- classes, just normalise */
.stock-alert-chips { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.sac-count {
  font-weight: 700;
  margin-right: 2px;
}

/* info-box → ds-banner-neutral */
.info-box {
  background: var(--blue-light);
  border: 1.5px solid #c0d8f5;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: #1a3a6b;
  margin-bottom: 14px;
}

/* cat-type-ct (old count badge inside underline tab) */
.cat-type-ct {
  font-size: 10px;
  font-weight: 700;
  margin-left: 3px;
  color: var(--muted);
}
