/* =========================================================
   Screen styles: page headers, dashboard, tables, builder,
   listings, modals, toasts
   ========================================================= */

/* ---------------------------------- page header ---------------------------------- */

.pagehead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.pagehead__title { font-size: 23px; font-weight: 800; letter-spacing: -.02em; }
.pagehead__sub { margin-top: 3px; font-size: 13.5px; color: var(--ink-400); }
.pagehead__actions { display: flex; gap: 9px; flex-wrap: wrap; }

.breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  font-size: 13px;
  color: var(--ink-400);
}
.breadcrumb a { color: var(--ink-500); }
.breadcrumb svg { opacity: .6; }

/* ---------------------------------- toolbar / filters ---------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}
.segmented button {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-500);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.segmented button:hover { color: var(--ink-900); }
.segmented button.is-active { background: var(--teal-500); color: #fff; }

.searchbox {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 340px;
}
.searchbox input { min-height: 42px; padding-inline-start: 36px; font-size: 14px; }
.searchbox svg {
  position: absolute;
  inset-inline-start: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-400);
  pointer-events: none;
}

/* ---------------------------------- dashboard ---------------------------------- */
/* Everything here is scoped to the dashboard screen (.dash wrapper) so shared
   primitives (toolbar, segmented, tables) keep their look on other screens.  */

.dash__toolbar { gap: var(--sp-2); }
.periodnav { display: inline-flex; align-items: center; gap: 2px; }
.periodnav .iconbtn { width: 36px; height: 36px; }
.periodnav__label {
  min-width: 168px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-700);
}
.dash__dates { display: inline-flex; align-items: center; gap: 8px; margin-inline-start: auto; }
.dash__dates input { min-height: 38px; width: auto; font-size: 13.5px; }
.dash__dates-sep { color: var(--ink-400); }

.dash__tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}
.dashtabs { display: inline-flex; gap: 2px; border-bottom: 1px solid var(--line-strong); }
.dashtabs button {
  margin-bottom: -1px;
  padding: 9px 15px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--ink-500);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.dashtabs button:hover { color: var(--ink-900); }
.dashtabs button.is-active { color: var(--teal-600); border-bottom-color: var(--teal-500); }

/* ---------------------------------- KPI cards ---------------------------------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.kpi {
  position: relative;
  padding: 15px 16px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.kpi::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  top: 0;
  height: 3px;
  background: var(--teal-500);
}
.kpi--zero::before { background: var(--line-strong); }

.kpi__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-400);
}
.kpi__value {
  margin-top: 8px;
  font-size: 19.5px;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--ink-900);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.kpi--zero .kpi__value { color: var(--ink-500); }

.kpi__delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-400);
  font-size: 11.5px;
  font-weight: 700;
}
.kpi__delta.up { background: var(--ok-bg); color: var(--ok); }
.kpi__delta.down { background: var(--danger-bg); color: var(--danger); }

/* ---------------------------------- dashboard grid ---------------------------------- */

.dashgrid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(310px, 1fr);
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
  align-items: stretch;
}
@media (max-width: 1080px) { .dashgrid { grid-template-columns: 1fr; } }

.dash__chartcard { display: flex; flex-direction: column; }
.dash__chartcard .chart {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 10px 18px 16px;
}

.chart { padding: 18px 20px 8px; }
.chart__svg { width: 100%; height: auto; display: block; }
.chart__bar { fill: var(--teal-500); transition: fill .15s; }
.chart__bar:hover { fill: var(--teal-600); }
.chart__bar--dim { fill: #a9dfe6; }
.chart__axis { stroke: var(--line); stroke-width: 1; }
.chart__label { font-size: 10.5px; fill: var(--ink-400); font-family: var(--font); }
.chart__value { font-size: 10.5px; fill: var(--ink-700); font-weight: 700; font-family: var(--font); }

/* outstanding hero + stat rows */
.dashout__hero { padding: 15px 20px 16px; border-bottom: 1px solid var(--line); }
.dashout__herolabel {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-400);
}
.dashout__herovalue {
  margin-top: 3px;
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  color: var(--warn);
}
.dashout__herovalue.is-clear { color: var(--ok); }
.dashout__rows .minirow { padding: 10px 20px; font-size: 13.5px; }

/* top products ranked list */
.toplist { margin: 0; padding: 4px 0; list-style: none; }
.toplist li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
}
.toplist li:last-child { border-bottom: 0; }
.toplist__rank {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--teal-050);
  color: var(--teal-600);
  font-size: 11.5px;
  font-weight: 800;
}
.toplist__name { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; color: var(--ink-700); }
.toplist__sub { display: block; font-size: 12px; font-weight: 500; color: var(--ink-400); }
.toplist__amt { font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink-900); }

/* dash-scoped table polish: report totals rows + costing columns */
.dash table.data tfoot td {
  padding-top: 12px;
  border-top: 2px solid var(--line-strong);
  border-bottom: 0;
  background: var(--surface-2);
  font-weight: 700;
  color: var(--ink-900);
}
.dash table.data .cell-pos { font-weight: 600; }
.dash table.data .cell-neg { font-weight: 700; color: var(--danger); }

/* product costing summary strip (By product) */
.reportstats {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  flex-wrap: wrap;
  padding: 13px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.reportstat { display: flex; flex-direction: column; gap: 1px; }
.reportstat__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-400);
}
.reportstat__value {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  color: var(--ink-900);
}
.reportstat--profit .reportstat__value { color: var(--ok); }
.reportstats__note { margin-inline-start: auto; }
.reportstats--hint { color: var(--ink-500); font-size: 13.5px; }

.minirow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.minirow:last-child { border-bottom: 0; }
.minirow__label { color: var(--ink-500); }
.minirow__value { font-weight: 700; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .kpi__value { font-size: 17px; }
  .dash__dates { margin-inline-start: 0; width: 100%; }
  .periodnav__label { min-width: 110px; font-size: 13px; }
}

/* ---------------------------------- tables ---------------------------------- */

.tablecard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.tablewrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th {
  padding: 11px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-400);
  text-align: start;
  white-space: nowrap;
}
table.data td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-700);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fbfdfd; }
table.data .right, table.data th.right { text-align: end; }
table.data .actions { text-align: end; white-space: nowrap; }
table.data .actions .iconbtn { width: 32px; height: 32px; }
table.data .cell-main { font-weight: 600; color: var(--ink-900); }
table.data .cell-sub { font-size: 12.5px; color: var(--ink-400); }

.rowlink { color: var(--teal-600); font-weight: 700; cursor: pointer; }
.rowlink:hover { text-decoration: underline; }

/* ---------------------------------- builder ---------------------------------- */

.builder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 46%);
  gap: var(--sp-4);
  align-items: start;
}
@media (max-width: 1180px) { .builder { grid-template-columns: 1fr; } }

.builder__panel { padding: 20px; }
.builder__section { margin-bottom: var(--sp-5); }
.builder__section:last-child { margin-bottom: 0; }

.builder__sectitle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 13px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-400);
}
.builder__sectitle::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.builder__actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding-top: 16px;
  margin-top: 6px;
  background: linear-gradient(to top, #fff 72%, rgba(255,255,255,0));
}

.lines { display: flex; flex-direction: column; gap: 9px; }

.lineitem {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) 74px 110px 74px 110px 34px;
  gap: 8px;
  align-items: end;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
@media (max-width: 760px) {
  .lineitem { grid-template-columns: repeat(2, 1fr); }
  .lineitem .lineitem__amt { grid-column: 1 / -1; }
}
.lineitem .field { margin-bottom: 0; }
.lineitem__label { display: block; margin-bottom: 4px; font-size: 11px; font-weight: 700; color: var(--ink-400); text-transform: uppercase; letter-spacing: .04em; }
.lineitem input { min-height: 38px; font-size: 14px; }
.lineitem__amt {
  align-self: center;
  text-align: end;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-900);
}
.lineitem__del { align-self: center; justify-self: end; }

.lineitem__pick { position: relative; }
.lineitem__sugg {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0; right: 0;
  max-height: 218px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
}
.lineitem__sugg button {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  font: inherit;
  font-size: 13.5px;
  text-align: start;
  cursor: pointer;
}
.lineitem__sugg button:last-child { border-bottom: 0; }
.lineitem__sugg button:hover { background: var(--teal-050); }
.lineitem__sugg small { display: block; color: var(--ink-400); }

.totals {
  margin-top: var(--sp-4);
  padding: 15px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.totals__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  font-size: 14px;
  color: var(--ink-700);
}
.totals__row span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; }
.totals__row--grand {
  margin-top: 7px;
  padding-top: 11px;
  border-top: 2px dashed var(--line-strong);
  font-size: 17px;
  color: var(--ink-900);
}
.totals__row--grand span:last-child { font-weight: 800; color: var(--teal-600); }
.totals__row .rate-in {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.totals__row .rate-in input {
  width: 74px;
  min-height: 34px;
  padding: 4px 8px;
  font-size: 13.5px;
  text-align: end;
}

.builder__previewhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.builder__previewhead h3 { font-size: 13px; font-weight: 700; color: var(--ink-400); text-transform: uppercase; letter-spacing: .06em; }

.previewscroll {
  max-height: calc(100vh - 190px);
  overflow: auto;
  padding: 14px;
  background: #d8e1e4;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
}
@media (max-width: 1180px) { .previewscroll { max-height: 640px; } }

/* ---------------------------------- listings forms ---------------------------------- */

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--sp-4);
  align-items: start;
}
@media (max-width: 1080px) { .split { grid-template-columns: 1fr; } }

.formcard { padding: 20px; }
.formcard h3 { font-size: 16px; font-weight: 800; margin-bottom: 4px; }
.formcard .formcard__sub { font-size: 13px; color: var(--ink-400); margin-bottom: 18px; }
.formcard__actions { display: flex; gap: 9px; margin-top: 18px; }

/* ---------------------------------- document actions ---------------------------------- */

.docactions {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}

/* ---------------------------------- modal ---------------------------------- */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(11, 33, 41, .55);
  backdrop-filter: blur(2px);
}

.modal {
  width: min(520px, 100%);
  max-height: calc(100vh - 60px);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
}
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 17px 20px;
  border-bottom: 1px solid var(--line);
}
.modal__title { font-size: 16.5px; font-weight: 800; }
.modal__body { padding: 20px; }
.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 15px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}
.modal--wide { width: min(760px, 100%); }

/* ---------------------------------- toasts ---------------------------------- */

.toasts {
  position: fixed;
  inset-inline-end: 20px;
  bottom: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-width: min(360px, calc(100vw - 40px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 15px;
  border-radius: var(--r-md);
  background: var(--ink-900);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-3);
  animation: toast-in .18s ease;
}
.toast--ok { background: var(--ok); }
.toast--err { background: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------------- settings ---------------------------------- */

.settingsgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--sp-4);
  align-items: start;
}

.logoPicker {
  display: flex;
  align-items: center;
  gap: 15px;
}
.logoPicker__preview {
  width: 74px; height: 74px;
  object-fit: contain;
  padding: 6px;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
}

.dangerzone {
  border-color: #f0cfcc;
}
.dangerzone .card__title { color: var(--danger); }

/* ---------------------------------- print stage (screen) ---------------------------------- */

.printstage {
  position: fixed;
  inset: 0;
  z-index: 80;
  overflow: auto;
  padding: 26px 16px 60px;
  background: #c9d4d8;
}
