/* =========================================
   COMPONENTS — cards, KPIs, charts, tables, badges, buttons, forms, modals,
   toasts, banners, tabs, empty / loading states, row actions, export menu
   ========================================= */

/* =========================================
   CARDS
   ========================================= */
.card {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  min-width: 0;
}
.card:hover { box-shadow: var(--shadow); }
.card-title { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.card-subtitle { font-size: 0.8rem; color: var(--text-muted); }

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 16px; margin-bottom: 24px; }
/* Column counts that divide the card count evenly, sized by the content area
   (not the viewport) so display scaling (125%, 150%) and the sidebar width
   never leave a single card alone on the last row. */
.page-content { container: page / inline-size; }
.kpi-grid:has(> .kpi-card:nth-child(6):last-child) { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpi-grid:has(> .kpi-card:nth-child(4):last-child) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi-grid:has(> .kpi-card:nth-child(3):last-child) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@container page (max-width: 1199px) {
  .kpi-grid:has(> .kpi-card:nth-child(6):last-child) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@container page (max-width: 759px) {
  .kpi-grid:has(> .kpi-card:nth-child(4):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container page (max-width: 639px) {
  .kpi-grid:has(> .kpi-card:nth-child(6):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container page (max-width: 539px) {
  .kpi-grid:has(> .kpi-card:nth-child(3):last-child) { grid-template-columns: 1fr; }
}
@container page (max-width: 439px) {
  .kpi-grid:has(> .kpi-card:nth-child(6):last-child),
  .kpi-grid:has(> .kpi-card:nth-child(4):last-child) { grid-template-columns: 1fr; }
}
.kpi-card {
  container-type: inline-size; min-width: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
  transition: var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow); }

.kpi-label { font-size: 0.92rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; line-height: 1.3; margin-bottom: 6px; }
.kpi-value { font-size: clamp(1.05rem, 11cqi, 1.7rem); font-weight: 800; color: var(--text-primary); letter-spacing: -0.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-change { font-size: 0.75rem; margin-top: 4px; font-weight: 500; }
.kpi-change.up { color: var(--success); }
.kpi-change.down { color: var(--danger); }

/* Chart Cards */
.chart-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; margin-bottom: 24px; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  overflow: hidden;
}
.chart-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chart-title { font-size: 0.95rem; font-weight: 600; }
.chart-grid > * {
  min-width: 0 !important;
  max-width: 100% !important;
}
.chart-canvas-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}
.chart-canvas-wrap { height: 240px; }

/* =========================================
   TABLES
   ========================================= */
.table-container { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { background: var(--surface-2); }
.data-table thead th { padding: 12px 16px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table tbody tr { transition: var(--transition); border-bottom: 1px solid var(--border); }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--primary-lighter); }
.data-table td { padding: 13px 16px; font-size: 0.87rem; color: var(--text-primary); vertical-align: middle; white-space: nowrap; }

/* =========================================
   BADGES / STATUS
   ========================================= */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.01em;
  color: var(--text-secondary); white-space: nowrap;
}
.badge::before {
  content: ""; flex-shrink: 0;
  width: 7px; height: 7px; border-radius: 50%; background: currentColor;
}
/* The dot marks a status; labels, roles, counts and icon badges don't get one */
.badge.plain::before, .badge:has(svg)::before { display: none; }
.badge.blue { color: #1558b0; }
.badge.green { color: #15803d; }
.badge.yellow { color: #b45309; }
.badge.red { color: #b91c1c; }
.badge.purple { color: #6d28d9; }
.badge.gray { color: #475569; }
/* Account warning next to a name (e.g. Invite pending): a filled pill so it reads at a glance */
.badge.account-flag {
  gap: 4px; padding: 2px 8px; margin-left: 4px; vertical-align: 1px;
  font-size: 0.72rem; border-radius: 999px;
  background: #fef3c7; border: 1px solid #fcd34d;
}
.badge.account-flag svg { flex-shrink: 0; }

/* =========================================
   BUTTONS
   ========================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; transition: var(--transition);
  text-decoration: none; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-blue); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-full { width: 100%; }
.btn-text { background: none; border: none; cursor: pointer; color: var(--primary); font-size: 0.82rem; font-weight: 500; padding: 4px 8px; border-radius: var(--radius-sm); transition: var(--transition); }
.btn-text:hover { background: var(--primary-light); }

.btn-icon-sm {
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-secondary);
  transition: var(--transition);
}
.btn-icon-sm:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.btn-icon-sm.danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-light); }

/* =========================================
   FORMS
   ========================================= */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.87rem; color: var(--text-primary);
  background: var(--surface);
  font-family: inherit;
  transition: var(--transition); outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,111,217,0.1);
}
.form-textarea { min-height: 90px; resize: vertical; }
.form-select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* Filter bar */
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.filter-bar .form-input, .filter-bar .form-select { width: auto; }

/* Search box with a clear "X" (searchClearButton() in app.js); the wrapper carries the width */
.search-field { position: relative; display: inline-flex; align-items: center; max-width: 100%; }
.filter-bar .search-field > .form-input { width: 100%; padding-right: 34px; }
.search-field-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; border: none; border-radius: 50%; cursor: pointer;
  background: var(--bg); color: var(--text-secondary); display: flex; align-items: center; justify-content: center;
}
.search-field-clear:hover { background: var(--border); color: var(--text-primary); }
.search-field > input:placeholder-shown ~ .search-field-clear { display: none; }

/* =========================================
   MODAL
   ========================================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,27,46,0.45); backdrop-filter: blur(4px);
  z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.modal {
  background: var(--surface); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 520px;
  max-height: 90vh; display: flex; flex-direction: column;
  animation: slideUp 0.2s ease;
}
.modal-wide { max-width: 720px; }
.modal-xl { max-width: 1040px; }

@keyframes slideUp { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: var(--radius-sm); transition: var(--transition); }
.modal-close:hover { background: var(--bg); color: var(--text-primary); }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-shrink: 0; }

/* =========================================
   TOAST
   ========================================= */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 12px 16px;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px;
  font-size: 0.85rem; font-weight: 500; min-width: 260px; max-width: 360px;
  animation: slideInRight 0.3s ease;
  border-left: 4px solid var(--primary);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slideInRight { from { transform: translateX(100%); opacity:0; } to { transform: translateX(0); opacity:1; } }
@keyframes slideOutRight { from { transform: translateX(0); opacity:1; } to { transform: translateX(100%); opacity:0; } }

/* =========================================
   OFFLINE BANNER (connectionMonitor in app.js)
   ========================================= */
.offline-banner {
  position: fixed; top: 16px; left: 50%; z-index: 10000;
  transform: translate(-50%, -150%); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 10px;
  max-width: calc(100vw - 32px); padding: 10px 18px;
  background: #fff7ed; color: #9a3412; border: 1px solid #fdba74;
  border-radius: 999px; box-shadow: var(--shadow-lg);
  font-size: 0.85rem; font-weight: 500;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.offline-banner.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.offline-banner.online { background: #ecfdf5; color: #065f46; border-color: #6ee7b7; }
.offline-banner svg { flex-shrink: 0; }
.app-offline :is(.btn-primary, .btn-success, .btn-danger, .btn-warning, button[type="submit"]):not([data-offline-ok]) {
  opacity: 0.5; cursor: not-allowed;
}

/* =========================================
   ALERT BANNERS
   ========================================= */
.alert-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius);
  margin-bottom: 12px; font-size: 0.85rem; font-weight: 500;
  border: 1px solid transparent;
}
.alert-banner.info { 
  background: rgba(30,111,217, 0.05); 
  border-color: rgba(30,111,217, 0.2); 
  color: var(--primary); 
}
.alert-banner.warning { 
  background: rgba(245,158,11, 0.05); 
  border-color: rgba(245,158,11, 0.2); 
  color: #b45309; 
}
.alert-banner.danger { 
  background: rgba(239,68,68, 0.05); 
  border-color: rgba(239,68,68, 0.2); 
  color: #b91c1c; 
}

.alert-banner.success {
  background: rgba(16,185,129, 0.05); 
  border-color: rgba(16,185,129, 0.2); 
  color: #15803d; 
}

/* =========================================
   TABS
   ========================================= */
.tabs { display: flex; gap: 2px; background: var(--bg); padding: 4px; border-radius: var(--radius); margin-bottom: 20px; }
.tab-btn { flex: 1; padding: 8px 14px; border: none; background: none; cursor: pointer; font-size: 0.82rem; font-weight: 600; border-radius: 7px; color: var(--text-secondary); transition: var(--transition); }
.tab-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

/* =========================================
   EMPTY STATE
   ========================================= */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.5; }
.empty-title { font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-desc { font-size: 0.85rem; color: var(--text-muted); }

/* Table loading: a spinner row while the first rows load, then a dimmed table while a filter reloads */
@keyframes spin { to { transform: rotate(360deg); } }

/* Page-header Refresh button (refreshButtonHTML in app.js): the icon spins while loading, then shows a check */
.btn-refresh { gap: 7px; }
.btn-refresh-icons { position: relative; display: inline-flex; width: 15px; height: 15px; flex-shrink: 0; }
.btn-refresh-icons svg { position: absolute; inset: 0; transition: opacity 0.2s ease, transform 0.2s ease; }
.btn-refresh-done { opacity: 0; transform: scale(0.6); color: var(--success); }
.btn-refresh:hover .btn-refresh-icon { transform: rotate(45deg); }
.btn-refresh.is-refreshing { border-color: var(--primary); color: var(--primary); background: var(--primary-light); cursor: progress; transform: none; }
.btn-refresh.is-refreshing .btn-refresh-icon { animation: spin 0.8s linear infinite; }
.btn-refresh.is-done { border-color: var(--success); color: var(--success); }
.btn-refresh.is-done .btn-refresh-icon { opacity: 0; transform: scale(0.6); }
.btn-refresh.is-done .btn-refresh-done { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .btn-refresh.is-refreshing .btn-refresh-icon { animation-duration: 2s; }
}
.table-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 48px 20px; color: var(--text-secondary); font-size: 0.875rem; font-weight: 500; }
.table-loading svg { color: var(--primary); animation: spin 0.9s linear infinite; }
.table-container.is-loading { position: relative; }
.table-container.is-loading tbody { opacity: 0.45; pointer-events: none; transition: opacity 0.15s ease; }
.table-container.is-loading::after {
  content: ''; position: absolute; top: 56px; left: 50%; width: 26px; height: 26px; margin-left: -13px;
  border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Expandable Action Buttons */
/* Pre-allocate width for the table cell so the layout doesn't shift when buttons expand */
.data-table td:has(.btn-expandable),
.table td:has(.btn-expandable) {
    min-width: 140px;
}
.data-table td:has(.btn-expandable:nth-child(2)),
.table td:has(.btn-expandable:nth-child(2)) {
    min-width: 180px;
}
.data-table td:has(.btn-expandable:nth-child(3)),
.table td:has(.btn-expandable:nth-child(3)) {
    min-width: 220px;
}
.data-table td:has(.btn-expandable:nth-child(4)),
.table td:has(.btn-expandable:nth-child(4)) {
    min-width: 260px;
}
.data-table td:has(.btn-expandable:nth-child(5)),
.table td:has(.btn-expandable:nth-child(5)) {
    min-width: 300px;
}
.data-table td:has(.btn-expandable:nth-child(6)),
.table td:has(.btn-expandable:nth-child(6)) {
    min-width: 340px;
}

.btn-expandable {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  height: 32px;
  max-width: 32px;
  padding: 0 7px !important;
  border-radius: 8px;
  overflow: hidden;
  white-space: nowrap;
  transition: max-width 0.25s cubic-bezier(0.2, 0.8, 0.2, 1); /* Removed delay, slightly faster close */
  box-sizing: border-box;
  vertical-align: middle;
}
.btn-expandable > svg {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
  stroke-width: 2px;
}
.btn-expandable .btn-text {
  opacity: 0;
  margin-left: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: inherit;
  background: transparent;
  padding: 0;
  transition: opacity 0.15s ease 0s; /* Fade out immediately on mouse out */
}
.btn-expandable .btn-text:hover {
  background: transparent;
}
.btn-expandable:hover {
  max-width: 140px;
  transition: max-width 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) 0s; /* Expand immediately on hover */
}
.btn-expandable:hover .btn-text {
  opacity: 1;
  transition: opacity 0.25s ease 0.15s; /* Fade in slightly after expanding */
}
/* Row actions: fixed-width box so a button expanding on hover never resizes the table column */
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  width: 260px; /* 5 buttons + room for one expanded label */
}
.data-table td:has(.row-actions),
.table td:has(.row-actions) {
  min-width: 0 !important;
  width: 260px;
  white-space: nowrap;
}
/* Delete stays pinned to the right edge so it lines up on every row */
.row-actions .btn-outline-danger {
  margin-left: auto;
}
.btn-outline-danger {
  border-color: var(--danger) !important;
  color: var(--danger) !important;
}
.btn-outline-danger:hover {
  background: var(--danger) !important;
  color: #fff !important;
}
/* Progress bar */
.progress-wrap { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 99px; transition: width 0.5s ease; }
.progress-bar.blue { background: var(--primary); }
.progress-bar.green { background: var(--success); }
.progress-bar.yellow { background: var(--warning); }
.progress-bar.red { background: var(--danger); }

/* Stock level indicator */
.stock-dot { width: 8px; height: 8px; border-radius: 50%; }

/* Tag */
.tag { display: inline-flex; align-items: center; padding: 2px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.72rem; color: var(--text-secondary); font-weight: 500; }

/* Table Toolbar */
.table-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }

/* Section title */
.section-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.section-title::after { content:''; flex:1; height:1px; background:var(--border); }

/* Export button menu (CSV / PDF) */
.export-menu {
  position: absolute; z-index: 3000; min-width: 190px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.export-menu button {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: none; border: none; border-radius: var(--radius-sm); cursor: pointer;
  font: inherit; font-size: 0.88rem; font-weight: 600; color: var(--text-primary); text-align: left;
}
.export-menu button:hover, .export-menu button:focus-visible { background: var(--primary-light); color: var(--primary); outline: none; }
.export-menu button svg { flex-shrink: 0; color: var(--text-secondary); }
.export-menu button:hover svg { color: var(--primary); }
.export-menu small { display: block; font-size: 0.75rem; font-weight: 400; color: var(--text-muted); }

.kpi-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; font-weight: 500; }
.kpi-sub.danger { color: var(--danger); font-weight: 600; }

/* "Load more" under long lists (pageList / loadMoreHTML in app.js) */
.list-load-more { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px; font-size: 0.8rem; }
.data-table tbody tr.list-load-more-row:hover { background: transparent; }
.list-load-more-row td { white-space: normal; }

/* Collapsible question-and-answer cards: the FAQ page's answers (calcExplainHTML in app.js, faq.js) */
.calc-explain { background: var(--surface); border: 1px solid var(--border-color); border-radius: 12px; margin-bottom: 20px; min-width: 0; }
.calc-explain > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 14px 20px; font-size: 0.95rem; font-weight: 700; color: var(--text-primary);
}
.calc-explain > summary::-webkit-details-marker { display: none; }
.calc-explain > summary > svg:first-child { color: var(--primary); flex-shrink: 0; }
.calc-explain > summary:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; border-radius: 12px; }
.calc-explain-chevron { margin-left: auto; flex-shrink: 0; color: var(--text-secondary); transition: transform 0.2s ease; }
.calc-explain[open] .calc-explain-chevron { transform: rotate(180deg); }
.calc-explain-body { padding: 0 20px 18px; font-size: 0.85rem; line-height: 1.65; color: var(--text-secondary); }
.calc-explain-body strong { color: var(--text-primary); font-weight: 700; }
.calc-explain-body ol { list-style: decimal; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.calc-explain-body p { margin-top: 10px; }
.calc-explain-body h4 { margin: 16px 0 8px; font-size: 0.88rem; font-weight: 700; color: var(--text-primary); }
.calc-explain-math {
  background: var(--surface-2); border: 1px solid var(--border-color); border-radius: 8px; padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace; font-size: 0.8rem; line-height: 1.8;
  color: var(--text-primary); white-space: pre; overflow-x: auto;
}
.calc-explain-table { width: 100%; max-width: 560px; border-collapse: collapse; font-size: 0.8rem; margin-bottom: 10px; }
.calc-explain-table th, .calc-explain-table td { padding: 5px 10px; border-bottom: 1px solid var(--border-color); text-align: right; white-space: nowrap; }
.calc-explain-table th:first-child, .calc-explain-table td:first-child { text-align: left; }
.calc-explain-table th { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); }
.calc-explain-table td { color: var(--text-primary); }
.calc-explain-table tfoot td { font-weight: 700; border-bottom: none; }
.calc-explain-scroll { overflow-x: auto; }
@media (max-width: 640px) {
  .calc-explain > summary { padding: 12px 14px; }
  .calc-explain-body { padding: 0 14px 14px; }
}

/* What "low stock" means, under the low-stock alerts (lowStockNoteHTML in app.js) */
.low-stock-note { width: 100%; font-size: 0.78rem; font-weight: 400; color: var(--text-secondary); line-height: 1.5; }
.low-stock-note a { color: inherit; font-weight: 600; text-decoration: underline; }

/* Small "How is this calculated?" link next to a computed figure; opens its FAQ answer (faqLinkHTML in faq.js) */
.faq-link {
  display: inline-flex; align-items: center; gap: 4px; vertical-align: middle;
  font-size: 0.78rem; font-weight: 600; color: var(--primary); text-decoration: none; white-space: nowrap;
}
.faq-link:hover span { text-decoration: underline; }
.faq-link svg { flex-shrink: 0; }
.low-stock-note .faq-link { color: inherit; font-size: inherit; }
.page-header-row > .faq-link { align-self: center; }
