/* Editor pages (order, sample): sticky header, numbered sections in sheet order,
   a rail that follows the scroll, chips, the tests combobox and pack cards.
   Colours come from the app tokens; the few extra ones live here. */
:root {
  --line: #DDE3E8;
  --line-soft: #E6EBEE;
  --input-border: #CFD8DE;
  --surface-alt: #FBFCFD;
  --navy: #12293A;
  --ink-subtle: #7B8894;
  --amber-bg: #FFFBEB;
  --amber-border: #F3D9A4;
  --amber-rule: #D99A0B;
  --amber-ink: #6B4905;
}

/* Shell */
.ed { display: block; }
.ed-head { position: sticky; top: 0; z-index: 20; margin: -24px calc(-1 * var(--page-pad)) 0; padding: 14px var(--page-pad) 12px; background: rgba(238, 241, 245, 0.96); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.ed-head__row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; max-width: 1180px; }
.ed-head__text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ed-head__title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ed-head__title h1 { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; }
.ed-head__sub { margin: 0; color: var(--muted); font-size: 13px; }
.ed-head__actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; flex-shrink: 0; padding-top: 22px; }
.ed-banner { max-width: 1180px; margin-top: 10px; padding: 9px 12px; border: 1px solid var(--amber-border); border-left: 3px solid var(--amber-rule); border-radius: 7px; background: var(--amber-bg); color: var(--amber-ink); font-size: 13px; font-weight: 500; }
.ed-errors { margin-top: 16px; max-width: 1180px; }
.ed-body { display: grid; grid-template-columns: minmax(0, 1fr) 212px; gap: 26px; align-items: start; max-width: 1180px; padding: 20px 0 120px; }
.ed-sections { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.ed-rail { position: sticky; top: 112px; display: flex; flex-direction: column; gap: 14px; }
.ed--banner .ed-rail { top: 160px; }

/* Sections */
.esec { background: var(--surface); border: 1px solid var(--line); border-radius: 11px; }
.esec__head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface-alt); border-bottom: 1px solid var(--line-soft); border-radius: 11px 11px 0 0; }
.esec__num { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 6px; background: var(--navy); color: #fff; font-weight: 700; font-size: 11.5px; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.esec__title { font-size: 15px; font-weight: 700; }
.esec__hint { color: var(--ink-subtle); font-size: 12px; font-weight: 500; }
.esec__actions { margin-left: auto; display: inline-flex; gap: 8px; }
.esec__ref { color: #9AA8B2; font-size: 9.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; white-space: nowrap; }
.esec__actions + .esec__ref { margin-left: 8px; }
.esec__head > .esec__ref:last-child:not(.esec__actions + .esec__ref) { margin-left: auto; }
.esec__body { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.esec--mandatory .esec__head { background: var(--bad-tint); }
.esec--mandatory .esec__num { background: var(--bad); }
.esec--mandatory .esec__title { color: var(--bad); }

/* Field grid */
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px 18px; }
.fgrid--dense { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld--span2 { grid-column: span 2; }
.fld--full { grid-column: 1 / -1; }
.fld__label, .fgrid .field__label { font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); }
.fld__hint, .fgrid .field__hint { font-size: 11.5px; line-height: 1.35; font-weight: 500; color: var(--ink-subtle); }
.fld__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.fld .input, .fld .select, .fld .textarea, .fgrid .field .input, .fgrid .field .select { font-weight: 600; font-size: 13.5px; border-color: var(--input-border); }
.fld .input:focus, .fld .select:focus, .fld .textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.fld--invalid .input { border-color: var(--bad); }
.textarea--short { min-height: 64px; }
.subpanel { background: var(--surface-alt); border: 1px solid var(--line-soft); border-radius: 9px; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.subpanel__title { font-family: var(--font-body); font-size: 12.5px; font-weight: 700; letter-spacing: 0.02em; color: var(--ink); }
.money { display: flex; gap: 6px; }
.money__cur { width: 96px; flex-shrink: 0; }
.money .input { flex: 1; min-width: 0; }
@media (max-width: 640px) { .fld--span2 { grid-column: auto; } }

/* Toggle chips (real checkbox underneath) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tchip { position: relative; display: inline-flex; cursor: pointer; }
.tchip__input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.tchip__face { display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px; border: 1px solid var(--input-border); border-radius: 999px; background: #fff; color: #41525F; font-size: 12.5px; font-weight: 600; line-height: 1.2; transition: background 120ms ease, border-color 120ms ease, color 120ms ease; }
.tchip__face:hover { border-color: var(--accent); color: var(--accent-strong); }
.tchip__input:checked + .tchip__face { background: var(--accent); border-color: var(--accent-strong); color: #fff; }
.tchip__input:focus-visible + .tchip__face { outline: 2px solid var(--accent); outline-offset: 2px; }
.tchip--danger .tchip__input:checked + .tchip__face { background: var(--bad); border-color: #8F1D17; }
.tchip__on { display: none; }
.tchip__input:checked + .tchip__face .tchip__on { display: inline; }
.tchip__input:checked + .tchip__face .tchip__off { display: none; }
.tchip__icon { width: 19px; height: 19px; flex-shrink: 0; }
.tchip__face:has(.tchip__icon) { padding: 7px 13px 7px 10px; }
.mdrow { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 9px; }
.mdrow .fld__hint { margin-top: 3px; }

/* Tests combobox */
.tpick__presets { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tpick__presets-label { font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-subtle); margin-right: 2px; }
.tpick__preset { padding: 5px 11px; border: 1px solid var(--input-border); border-radius: 999px; background: #fff; color: var(--ink-2); font: 600 11.5px var(--font-body); cursor: pointer; }
.tpick__preset:hover { border-color: var(--accent); color: var(--accent-strong); }
.tpick__preset--clear { border-color: transparent; color: var(--ink-subtle); }
.tpick { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; min-height: 44px; padding: 8px 10px; border: 1px solid var(--input-border); border-radius: 8px; background: #fff; cursor: text; }
.tpick:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.tpick__tokens { display: contents; }
.tk { display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 10px; border-radius: 6px; background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 600; line-height: 1.2; }
.tk__x { width: 16px; height: 16px; border: 0; border-radius: 4px; background: rgba(255, 255, 255, 0.18); color: #fff; font-size: 13px; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.tk__x:hover { background: rgba(255, 255, 255, 0.32); }
.tpick__input { flex: 1; min-width: 150px; border: 0; outline: 0; padding: 4px 2px; background: transparent; font: 600 13.5px var(--font-body); color: var(--ink); }
.tpick__input::placeholder { color: #9AA8B2; font-weight: 500; }
.tpick__toggle { border: 0; background: transparent; color: var(--accent-strong); font: 600 12px var(--font-body); cursor: pointer; padding: 4px 6px; }
.tpick__pop { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30; max-height: 290px; overflow: auto; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 14px 34px rgba(16, 34, 46, 0.14); }
.tpick__group { padding: 8px 10px 4px; color: #9AA8B2; font-size: 9.5px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.tpick__opt { display: flex; justify-content: space-between; align-items: center; padding: 9px 10px; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; }
.tpick__opt:hover, .tpick__opt[aria-selected="true"] { background: #F4F7F9; }
.tpick__add { color: var(--accent); font-size: 11.5px; font-weight: 700; }
.tpick__empty { padding: 12px 10px; color: var(--ink-subtle); font-size: 13px; }

/* Pack cards */
.packs { display: flex; flex-direction: column; gap: 14px; }
.packs:empty { display: none; }
.packs-empty { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 16px; border: 1px dashed var(--input-border); border-radius: 9px; color: var(--ink-subtle); font-size: 13px; }
.packs:has([data-nested-form-target="row"]:not([hidden])) + .packs-empty { display: none; }
.pk { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.pk__head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--navy); color: #fff; }
.pk__letter { width: 26px; height: 26px; border-radius: 7px; background: #fff; color: var(--navy); font-weight: 800; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.pk__letter:empty::before { content: "·"; color: var(--ink-subtle); }
.pk__pick { flex: 1; min-width: 0; }
.pk__head .autocomplete__selected { background: transparent; padding: 0; min-height: 0; gap: 10px; }
.pk__thumb { width: 38px; height: 38px; object-fit: contain; background: #fff; border-radius: 6px; }
.pk__code { color: #fff; font-weight: 700; font-size: 13.5px; }
.pk__head .pk__meta { color: #A8BCC9; font-size: 11.5px; font-weight: 500; }
.pk__change, .pk__remove { border: 0; border-radius: 6px; padding: 6px 10px; font: 600 12px var(--font-body); cursor: pointer; }
.pk__change { background: rgba(255, 255, 255, 0.14); color: #fff; }
.pk__change:hover { background: rgba(255, 255, 255, 0.24); }
.pk__remove { background: transparent; color: #E8B3AE; flex-shrink: 0; }
.pk__remove:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
.pk__body:empty { display: none; }
.pk__table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.pk__table th { padding: 8px 12px; text-align: left; background: #F4F7F9; color: var(--ink-2); font-size: 9.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.pk__table td { padding: 8px 12px; border-top: 1px solid var(--line-soft); vertical-align: middle; font-variant-numeric: tabular-nums; }
.pk__table th:first-child, .pk__table td:first-child { padding-left: 16px; }
.pk__qty-head, .pk__qty { text-align: right; width: 130px; }
.pk__qty .input { width: 110px; text-align: right; margin-left: auto; }
.pk__foot { background: var(--surface-alt); border-top: 1px solid var(--line-soft); padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.pk__summary { display: flex; gap: 18px; flex-wrap: wrap; color: var(--ink-subtle); font-size: 12.5px; font-weight: 500; }
.pk__margin { color: var(--accent-strong); font-weight: 700; }

/* Rail */
.erail { background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.erail__label { padding: 4px 8px 8px; font-size: 10px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-subtle); }
.erail__row { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 7px; color: var(--ink-2); font-size: 13px; font-weight: 600; text-decoration: none; }
.erail__row:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.erail__row.is-active { background: var(--accent-soft); color: var(--accent-strong); }
.erail__num { width: 19px; height: 19px; border-radius: 5px; background: #E4EAEE; color: var(--ink-2); font-size: 10.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.erail__row.is-active .erail__num { background: var(--accent); color: #fff; }
.erail__title { flex: 1; min-width: 0; }
.erail__count { color: var(--ink-subtle); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.erail__count:empty { display: none; }
.totals { background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; }
.totals__label { font-size: 10px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-subtle); margin-bottom: 6px; }
.totals__big { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.totals__unit { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.totals__sub { color: var(--ink-subtle); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.totals__rule { border: 0; border-top: 1px solid var(--line-soft); margin: 10px 0; }
.totals__line { font-size: 13px; font-variant-numeric: tabular-nums; }
.totals__note { color: var(--ink-subtle); font-size: 11.5px; line-height: 1.35; margin-top: 2px; }

/* Sticky footer bar */
.ed-bar { position: fixed; left: var(--sidebar-w); right: 0; bottom: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px var(--page-pad); background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(8px); border-top: 1px solid var(--line); }
.ed-bar__stats { display: flex; gap: 18px; flex-wrap: wrap; color: var(--ink-subtle); font-size: 12.5px; font-weight: 500; }
.ed-bar__stats strong { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.ed-bar__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.ed-bar__note { color: var(--amber-ink); font-size: 12px; font-weight: 600; margin-right: 6px; }

@media (max-width: 1100px) {
  .ed-body { grid-template-columns: minmax(0, 1fr); }
  .ed-rail { position: static; }
}
@media (max-width: 900px) {
  .ed-head { margin: -16px -16px 0; padding: 12px 16px; }
  .ed-bar { left: 0; }
}

/* Show pages: the same numbered sections, read-only */
.esec { scroll-margin-top: 200px; }
.sheet-sections .esec__body .kv { gap: 12px 20px; }
.sheet-sections .subpanel { margin-top: 2px; }
.sheet-sections .pack-card { border: 1px solid var(--line); border-radius: 10px; }
.sheet-sections .esec__body .table-wrap { margin: 0 -16px -16px; }
.sheet-sections .esec__body .pack-card .table-wrap, .sheet-sections .esec__body .picture + .table-wrap { margin: 0; }
.sheet-sections .esec__body .grid-table { border-top: 1px solid var(--line-soft); }
.mandatory--plain { margin-top: 0; border-radius: 6px; }
.mandatory--plain .mandatory__row:first-child { border-top: 0; }
.chip--icon svg, .chip--icon img { width: 18px; height: 18px; }
.picture--medium { max-width: 320px; }
.sheet-sections .pack-card { grid-template-columns: 100px minmax(0, 1fr); padding: 14px 16px; }
.table--tight th, .table--tight td { padding-left: 10px; padding-right: 10px; }
.table--tight th:first-child, .table--tight td:first-child { padding-left: 12px; }
.table--tight th:last-child, .table--tight td:last-child { padding-right: 12px; }

/* Phones: section headers wrap and pack tables scroll inside their card */
.esec__head { flex-wrap: wrap; row-gap: 4px; }
.pk__sizes { overflow-x: auto; }
@media (max-width: 720px) {
  .esec__ref { display: none; }
  .esec__actions { margin-left: auto; }
  .ed-head__actions { padding-top: 0; }
  .ed-head__row { flex-direction: column; }
  .ed-bar { flex-wrap: wrap; }
  .ed-bar__stats { display: none; }
}
