/* Components. Class names are shared by every dashboard page.
   Older page markup (button, card, badge, table, field, alert...) uses the same names. */

/* --- icons -------------------------------------------------------------------------------- */
.icon { width: 18px; height: 18px; flex: 0 0 auto; stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }

.icon-chip { width: 34px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center; flex: 0 0 auto; }
.tone-green  { background: var(--accent-soft); color: var(--accent); }
.tone-amber  { background: var(--amber-soft);  color: var(--amber); }
.tone-red    { background: var(--red-soft);    color: var(--red); }
.tone-blue   { background: var(--blue-soft);   color: var(--blue); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }
.tone-neutral{ background: var(--surface-2);   color: var(--text-2); }

/* --- buttons ------------------------------------------------------------------------------ */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 40px; padding: 0 var(--s-4);
  font: 600 var(--fs-md) var(--font); line-height: 1; white-space: nowrap; text-decoration: none;
  border-radius: var(--r-sm); border: 1px solid transparent; cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), color var(--t-fast);
}
.button:active { transform: translateY(1px); }
.button[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }
.button-primary { background: var(--accent); color: var(--text-on-accent); box-shadow: 0 6px 20px rgba(62, 207, 142, 0.22); }
.button-primary:hover { background: var(--accent-hover); color: var(--text-on-accent); transform: translateY(-1px); }
.button-secondary { background: var(--surface-1); color: var(--text-1); border-color: var(--line); }
.button-secondary:hover { background: var(--surface-2); color: var(--text-1); border-color: var(--line-strong); }
.button-ghost { background: transparent; color: var(--text-2); }
.button-ghost:hover { background: var(--surface-2); color: var(--text-1); }
.button-danger { background: var(--red-soft); color: var(--red); border-color: rgba(242, 109, 109, 0.35); }
.button-danger:hover { background: var(--red); color: #1a0606; }
.button-block { width: 100%; }
.button-sm { min-height: 32px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.button-icon { width: 40px; padding: 0; }
.button-link-danger { background: none; border: 0; padding: 0; min-height: var(--tap); color: var(--red);
  font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* --- cards -------------------------------------------------------------------------------- */
.card {
  background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-card); padding: var(--s-5); margin-bottom: var(--s-4); min-width: 0;
  animation: ds-rise var(--t-slow) var(--ease) both;
}
.card-head, .section-header { display: flex; align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap; gap: var(--s-3); margin-bottom: var(--s-4); }
.card-head p, .section-header p { margin-top: 2px; color: var(--text-3); font-size: var(--fs-sm); }
.card h2 + p { margin-top: 2px; }
.card > h2 { margin-bottom: var(--s-3); }
.card h3 { margin: var(--s-4) 0 var(--s-2); }

/* --- stat cards --------------------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--s-4); margin-bottom: var(--s-4); }
.stat {
  position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 2px;
  padding: 18px; border-radius: var(--r-lg); background: var(--surface-1);
  border: 1px solid var(--line); box-shadow: var(--shadow-card);
  transition: transform var(--t-med) var(--ease), border-color var(--t-med) var(--ease);
  animation: ds-rise var(--t-slow) var(--ease) both;
}
.stat:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.stat::after { content: ""; position: absolute; right: -50px; bottom: -70px; width: 170px; height: 170px;
  border-radius: 50%; background: radial-gradient(closest-side, rgba(62, 207, 142, 0.14), transparent); pointer-events: none; }
.stat.tone-amber-glow::after { background: radial-gradient(closest-side, rgba(242, 184, 75, 0.14), transparent); }
.stat.tone-red-glow::after { background: radial-gradient(closest-side, rgba(242, 109, 109, 0.14), transparent); }
.stat.tone-violet-glow::after { background: radial-gradient(closest-side, rgba(167, 139, 250, 0.16), transparent); }
.stat-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); color: var(--text-2); font-size: var(--fs-sm); }
.stat-value { font-size: var(--fs-stat); font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; margin-top: var(--s-2); }
.stat-value small { font-size: var(--fs-lg); font-weight: 500; color: var(--text-3); letter-spacing: 0; }
.stat-label, .stat-foot { color: var(--text-3); font-size: var(--fs-sm); }
.stats .stat:nth-child(2) { animation-delay: 40ms; }
.stats .stat:nth-child(3) { animation-delay: 80ms; }
.stats .stat:nth-child(4) { animation-delay: 120ms; }

/* --- badges / pills ---------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.5; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.9; }
.badge.no-dot::before { display: none; }
.badge-ok, .badge-status-active, .badge-availability-available, .badge-kind-new { background: var(--accent-soft); color: var(--accent); }
.badge-status-draft, .badge-availability-inactive, .badge-info { background: var(--blue-soft); color: var(--blue); }
.badge-status-archived, .badge-availability-not_sold_in_country, .badge-kind-unchanged { background: var(--surface-2); color: var(--text-3); }
.badge-availability-low_stock, .badge-kind-changed, .badge-warn { background: var(--amber-soft); color: var(--amber); }
.badge-availability-out_of_stock, .badge-kind-invalid, .badge-error { background: var(--red-soft); color: var(--red); }

/* --- alerts & toasts --------------------------------------------------------------------- */
.alert { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md); margin-bottom: var(--s-4); border: 1px solid transparent; font-size: var(--fs-md); }
.alert-success { background: var(--accent-soft); color: #bff3da; border-color: rgba(62, 207, 142, 0.25); }
.alert-error { background: var(--red-soft); color: #ffd0d0; border-color: rgba(242, 109, 109, 0.3); }
.alert-info { background: var(--blue-soft); color: #d4e5ff; border-color: rgba(110, 168, 254, 0.25); }
.alert-warning { background: var(--amber-soft); color: #ffe8bd; border-color: rgba(242, 184, 75, 0.25); }
.alert ul { margin: var(--s-1) 0 0; padding-left: 1.1rem; }

.toast-region { position: fixed; top: var(--s-4); right: var(--s-4); z-index: 60; display: grid; gap: var(--s-2); width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop); animation: ds-rise var(--t-med) var(--ease) both; }
.toast .toast-close { margin-left: auto; background: none; border: 0; color: var(--text-3); cursor: pointer; padding: 2px; border-radius: 6px; }
.toast .toast-close:hover { color: var(--text-1); }
.toast-success { border-left: 3px solid var(--accent); }
.toast-error { border-left: 3px solid var(--red); }
.toast-info { border-left: 3px solid var(--blue); }
.toast.is-leaving { opacity: 0; transform: translateY(-6px); transition: all var(--t-med) var(--ease); }

/* --- forms -------------------------------------------------------------------------------- */
.form { display: grid; gap: var(--s-4); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: var(--s-4); align-items: start; }
.field { display: grid; gap: 6px; align-content: start; }
.field label, .field-label { font-weight: 600; font-size: var(--fs-sm); color: var(--text-2); }
.field small { color: var(--text-3); font-size: var(--fs-xs); }
/* a field with a validation error: red border and the message right under it */
.field [aria-invalid="true"] { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.field small.field-error { color: var(--red); font-weight: 600; }
.required { color: var(--red); }
input[type="text"], input[type="password"], input[type="number"], input[type="search"],
select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  font: var(--fs-md) var(--font); color: var(--text-1);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); background: var(--surface-1); }
textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.code-textarea { font-family: var(--font-mono); font-size: var(--fs-sm); min-height: 220px; tab-size: 4; }
select { appearance: none; padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
input[type="file"] { min-height: var(--tap); padding: 8px 0; font: inherit; color: var(--text-2); }
input[type="file"]::file-selector-button { margin-right: var(--s-3); padding: 8px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-1); font: 600 var(--fs-sm) var(--font); cursor: pointer; }
.readonly-value { min-height: 42px; display: flex; align-items: center; font-family: var(--font-mono); color: var(--text-1); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.inline-form { display: grid; gap: var(--s-3); align-items: end; margin-bottom: var(--s-3); }
.error-list { margin: var(--s-1) 0 0; padding-left: 1.1rem; }

/* --- tables ------------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--r-md); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
.table th { text-align: left; font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-3); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr { transition: background var(--t-fast) var(--ease); }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.table tbody tr:last-child td { border-bottom: 0; }

/* --- toolbar, filters, chips, segmented -------------------------------------------------- */
.toolbar, .filters { display: grid; gap: var(--s-3); }
.filters-actions { display: flex; align-items: flex-end; gap: var(--s-2); }
.search-input { position: relative; }
.search-input .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-input input { padding-left: 38px; }
.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--bg-0); border: 1px solid var(--line); }
.segmented a, .segmented button { padding: 5px 12px; font: 600 var(--fs-xs) var(--font); border-radius: 7px; color: var(--text-3);
  background: none; border: 0; cursor: pointer; text-decoration: none; }
.segmented .is-active, .segmented [aria-pressed="true"] { background: var(--surface-3); color: var(--text-1); }

/* --- page header, breadcrumbs, tabs ------------------------------------------------------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-5); }
.page-header p { color: var(--text-3); margin-top: 4px; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.page-actions form { margin: 0; }
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-3); margin-bottom: var(--s-2); }
.breadcrumbs a { color: var(--text-2); }
.breadcrumbs a:hover { color: var(--text-1); }
.tabs { display: flex; gap: 2px; overflow-x: auto; margin-bottom: var(--s-4); padding: 4px; border-radius: var(--r-md);
  background: var(--surface-1); border: 1px solid var(--line); -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs a { flex: 0 0 auto; display: inline-flex; align-items: center; min-height: 34px; padding: 0 14px; border-radius: var(--r-sm);
  color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; text-decoration: none; transition: all var(--t-fast) var(--ease); }
.tabs a:hover { color: var(--text-1); background: var(--surface-2); }
.tabs a[aria-current="true"], .tabs a.is-active { color: var(--text-1); background: var(--surface-3); }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); margin: var(--s-4) 0; }

/* --- description lists, lists, timeline -------------------------------------------------- */
.details { display: grid; grid-template-columns: 1fr; gap: 2px var(--s-5); margin: 0; }
.details dt { color: var(--text-3); font-size: var(--fs-sm); padding-top: var(--s-2); }
.details dd { margin: 0; padding-bottom: var(--s-2); border-bottom: 1px solid var(--line-soft); }
.details dd:last-child { border-bottom: 0; }
.faq dt { font-weight: 650; margin-top: var(--s-4); }
.faq dd { margin: var(--s-1) 0 0; color: var(--text-2); }
.warning-list, .issues { margin: 0; padding-left: 1.1rem; }
.warning-list li, .issues li { margin-bottom: 6px; }

.list-rows { display: grid; gap: 2px; }
.list-row { display: flex; align-items: center; gap: var(--s-3); padding: 10px; border-radius: var(--r-sm); transition: background var(--t-fast) var(--ease); }
.list-row:hover { background: var(--surface-2); }
.list-row .meta { color: var(--text-3); font-size: var(--fs-sm); }
.list-row .end { margin-left: auto; text-align: right; color: var(--text-3); font-size: var(--fs-sm); white-space: nowrap; }

/* --- empty state --------------------------------------------------------------------------- */
.empty { display: grid; justify-items: center; gap: var(--s-3); text-align: center; padding: var(--s-8) var(--s-4); color: var(--text-2); }
.empty .icon-chip { width: 48px; height: 48px; border-radius: 14px; }
.empty .icon-chip .icon { width: 22px; height: 22px; }
.empty p { max-width: 46ch; color: var(--text-3); }

/* --- charts ------------------------------------------------------------------------------- */
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line-soft); stroke-width: 1; }
.chart .axis-label { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .area { fill: url(#ds-area-gradient); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart .point { fill: var(--bg-0); stroke: var(--accent); stroke-width: 2.4; }
.bar-track { fill: var(--surface-2); }
.bar-fill { fill: var(--accent); transform-box: fill-box; transform-origin: left; animation: ds-grow 700ms var(--ease) both; }
.bar-fill.is-low { fill: var(--amber); }
.bar-fill.is-out { fill: var(--red); }
.bar-threshold { fill: var(--text-3); }
.seg-ok { fill: var(--accent); } .seg-low { fill: var(--amber); } .seg-out { fill: var(--red); } .seg-none { fill: var(--surface-3); }
.seg-draft { fill: var(--blue); } .seg-archived { fill: var(--text-3); }
.donut-track { fill: none; stroke: var(--surface-3); }
.donut-seg { fill: none; stroke-linecap: butt; }
.donut-seg.seg-ok { stroke: var(--accent); } .donut-seg.seg-draft { stroke: var(--blue); } .donut-seg.seg-archived { stroke: var(--text-3); }
.donut-value { fill: var(--text-1); font: 700 24px var(--font); }
.donut-caption { fill: var(--text-3); font: 500 11px var(--font); }
.bar-rows { display: grid; gap: var(--s-3); }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 52px; align-items: center; gap: var(--s-3); }
.bar-row .label { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .value { text-align: right; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); margin-top: var(--s-3); color: var(--text-2); font-size: var(--fs-sm); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; }
.swatch-ok { background: var(--accent); } .swatch-low { background: var(--amber); } .swatch-out { background: var(--red); }
.swatch-none { background: var(--surface-3); } .swatch-draft { background: var(--blue); } .swatch-archived { background: var(--text-3); }
.chart-empty { display: grid; place-items: center; min-height: 200px; border: 1px dashed var(--line); border-radius: var(--r-md); }

/* --- dialog -------------------------------------------------------------------------------- */
dialog.confirm-dialog { max-width: 440px; width: calc(100vw - 32px); padding: 0; border: 1px solid var(--line-strong);
  border-radius: var(--r-lg); background: var(--surface-1); color: var(--text-1); box-shadow: var(--shadow-pop); }
dialog.confirm-dialog::backdrop { background: rgba(5, 7, 9, 0.7); backdrop-filter: blur(3px); }
dialog.confirm-dialog[open] { animation: ds-rise var(--t-med) var(--ease) both; }
.confirm-body { padding: var(--s-6); display: grid; gap: var(--s-3); }
.confirm-actions { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-4) var(--s-6); border-top: 1px solid var(--line); }

/* --- misc ---------------------------------------------------------------------------------- */
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; flex: 0 0 auto;
  background: var(--violet-soft); color: var(--violet); font-weight: 700; font-size: var(--fs-sm); text-transform: uppercase; }
kbd { font: 600 11px var(--font); padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--text-3); background: var(--bg-0); }
.divider { height: 1px; background: var(--line); border: 0; margin: var(--s-4) 0; }
.grid-2, .grid-main { display: grid; grid-template-columns: 1fr; gap: 0 var(--s-4); }

@media (min-width: 768px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .field-wide { grid-column: 1 / -1; }
  .details { grid-template-columns: minmax(160px, max-content) 1fr; }
  .details dt { padding: var(--s-2) 0; border-bottom: 1px solid var(--line-soft); }
  .details dd { padding: var(--s-2) 0; }
  .filters { grid-template-columns: 2fr 1fr 1fr auto; align-items: end; }
  .inline-form { grid-template-columns: minmax(140px, 180px) 1fr auto; }
}
@media (min-width: 980px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-main { grid-template-columns: 2fr 1fr; }
}

/* phones: tables become stacked cards */
@media (max-width: 767px) {
  .responsive-table thead { display: none; }
  .responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td { display: block; width: 100%; }
  .responsive-table tr { border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: var(--s-2); padding: var(--s-2) var(--s-3); background: var(--surface-1); }
  .responsive-table td { display: flex; justify-content: space-between; gap: var(--s-4); padding: 6px 0; border: 0; text-align: right; }
  .responsive-table td::before { content: attr(data-label); color: var(--text-3); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; text-align: left; }
  /* product names get ~40% of the row so they are readable; the bar takes the rest */
  .bar-row { grid-template-columns: minmax(96px, 40%) 1fr 34px; gap: var(--s-2); }
  .bar-row .label { white-space: normal; line-height: 1.3; }
}

/* line chart: fixed height, card-wide, undistorted strokes */
.chart-line { height: 220px; }
.chart-line .line, .chart-line .grid-line { vector-effect: non-scaling-stroke; }
.chart-ticks { display: flex; justify-content: space-between; margin-top: 6px; color: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
/* big numbers stay on one line with their unit */
.stat-value { white-space: nowrap; font-size: clamp(26px, 2.2vw + 8px, var(--fs-stat)); }
/* thin bars: fixed height (the SVG stretches only horizontally) */
.bar-row .chart { height: 10px; }
.stack-row .chart, .chart.stacked { height: 10px; }
/* search icon sits inside the input (below the label), not centred on the whole field */
.search-input .icon { top: auto; bottom: 12px; transform: none; }
@media (max-width: 767px) {
  /* card rows: label on the left, the whole cell content (name, line break, SKU) on the right */
  .responsive-table td { display: block; text-align: right; overflow: hidden; }
  .responsive-table td::before { float: left; margin-right: var(--s-4); line-height: 1.9; }
}
/* a paragraph directly inside a card gets breathing room before what follows */
.card > p { margin-bottom: var(--s-3); }
.card > p:last-child { margin-bottom: 0; }
/* stat cards: 2 x 2 until there is room for 4 in a row */
.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 1180px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
/* date fields look like every other input (dark theme calendar icon via color-scheme) */
input[type="date"] {
  /* min-width: 0 — the browser's own minimum is wider than half a phone screen */
  width: 100%; min-width: 0; max-width: 100%; min-height: 42px; padding: 9px 12px; font: var(--fs-md) var(--font); color: var(--text-1);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); color-scheme: dark;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
input[type="date"]:hover { border-color: var(--line-strong); }
input[type="date"]:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
