/*
 * app.css — screen UI only. Nothing in here affects the printed sheet.
 * (Except one thing on purpose: the [fill="#000"] rules tint the logos on
 * screen exactly the way labels.css tints them on paper.)
 */

:root {
  --ink: #0d1117;
  --muted: #5b6572;
  --line: #d7dce2;
  --line-soft: #eceff3;
  --canvas: #eef0f3;
  --accent: #0f5f57;
  --accent-soft: #eef4f3;
}

* {
  box-sizing: border-box;
}

/* The whole UI opens and closes panels by flipping the hidden attribute, but
   .modal and .popover both declare display:flex — and an author display rule
   beats the browser's plain [hidden] default, so Close, Done and the backdrop
   click appeared to do nothing. This makes the attribute win everywhere. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* off-screen canvas used to measure logo artwork */
.logo-measure-stage {
  position: absolute;
  left: -99999px;
  top: 0;
  width: 0;
  height: 0;
  overflow: hidden;
  visibility: hidden;
}

/* ------------------------------------------------------------------ chrome */

#topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0;
  white-space: nowrap;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spacer {
  flex: 1 1 auto;
}

/* The shell the topbar and the two panes hang on. Without this the page was a
   plain block: #workspace grew to whatever its cards needed, body's
   overflow:hidden clipped the rest, and there was no scroll area to scroll in
   — add a dozen labels and the bottom cards simply disappeared. print.css
   turns this back into a normal block for the paper. */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

#workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(600px, 1.25fr) minmax(430px, 1fr);
  /* An unconstrained grid row grows to whatever its tallest item needs, so with
     a dozen cards the row became taller than the window, .pane-edit never
     overflowed, and body's overflow:hidden simply cut the rest off. minmax(0…)
     pins the row to the workspace height, which is what gives the pane
     something to scroll inside. */
  grid-template-rows: minmax(0, 1fr);
}

.pane {
  min-width: 0;
  min-height: 0;
}

.pane-edit {
  overflow: auto;
  /* the 16px that used to sit here now belongs to .stats, so the sticky bar can
     reach the top edge of the scroll area and hide the cards under it */
  padding: 0 20px 48px;
}

.pane-preview {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: #e3e7ec;
}

.preview-bar {
  flex: none;
  display: flex;
  align-items: center;
  /* the note now carries the black-logos warning too, and a narrow pane should
     drop it to a second line rather than push the sheet sideways */
  flex-wrap: wrap;
  gap: 10px;
  padding: 9px 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}

#preview-note.mono {
  color: #8a5300;
  font-weight: 600;
}

.preview-scroll {
  flex: 1 1 auto;
  overflow: auto;
  padding: 14px;
}

#print-root {
  width: -moz-fit-content;
  width: fit-content;
  margin: 0 auto;
}

/* screen-only paper look; print.css strips it */
.preview-scroll .sheet {
  background: #fff;
  box-shadow: 0 2px 12px rgba(10, 20, 30, 0.2), 0 0 0 1px rgba(10, 20, 30, 0.09);
  margin: 0 0 16px;
}

.preview-scroll .sheet:last-child {
  margin-bottom: 4px;
}

/* ------------------------------------------------------------------ buttons */

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 13px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: #b6c0cb;
  background: #f7f9fb;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 95, 87, 0.22);
  border-color: var(--accent);
}

.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.btn.tiny {
  padding: 5px 9px;
  font-size: 12px;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.btn.ghost:hover {
  background: #f2f5f7;
}

.link {
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.link:hover {
  background: var(--accent-soft);
}

.link.danger {
  color: #9c2b21;
}

.link.danger:hover {
  background: #fbecea;
}

/* ------------------------------------------------------------------- stats */

.stats {
  /* Counts, + Add label, Duplicate last and Clear batch stay reachable: with a
     long batch they are the buttons you keep needing, and scrolling used to put
     them out of sight above the pane. */
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 -20px 14px;
  padding: 16px 20px 8px;
  background: var(--canvas);
  border-bottom: 1px solid var(--line);
}

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 13px;
  min-width: 96px;
}

.stat b {
  display: block;
  font-size: 19px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat span {
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

#stat-warn {
  align-self: center;
  background: #fdf3e6;
  border: 1px solid #f0d3ad;
  color: #7d4a12;
  border-radius: 10px;
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 600;
}

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

#cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.card:focus-within {
  border-color: #b9c3cd;
  box-shadow: 0 1px 8px rgba(10, 20, 30, 0.07);
}

.card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: #fbfcfd;
}

.card-no {
  flex: none;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.picker {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.picker:hover {
  border-color: var(--accent);
  background: #fbfdfd;
}

.picker:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 95, 87, 0.2);
  border-color: var(--accent);
}

.brand-cell {
  flex: none;
  width: 184px;
  gap: 8px;
}

.bmark {
  flex: none;
  width: 34px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.bmark:empty {
  display: none;
}

.bmark svg,
.bmark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.bmark [fill="#000"] {
  fill: var(--logo-ink, #000) !important;
}

.bmark [stroke="#000"] {
  stroke: var(--logo-ink, #000) !important;
}

.bname {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
}

.bnone {
  color: #97a1ac;
  font-size: 12.5px;
}

.att-input {
  flex: 1 1 190px;
  min-width: 150px;
}

.copies-field {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.card-note {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.card-acts {
  flex: none;
  display: flex;
  gap: 2px;
}

.cell-input {
  width: 100%;
  border: 1px solid transparent;
  background: #f5f7f9;
  border-radius: 7px;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
}

.cell-input::placeholder {
  color: #a4adb8;
}

.cell-input:hover {
  border-color: var(--line);
}

.cell-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(15, 95, 87, 0.14);
}

.cell-input.num {
  width: 62px;
  text-align: center;
}

.lines {
  width: 100%;
  border-collapse: collapse;
}

.lines thead th {
  background: #fff;
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

.lines tbody td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.lines tbody tr:last-child td {
  border-bottom: 0;
}

.lines .h-ck {
  width: 78px;
  text-align: center;
}

.lines .h-num {
  width: 112px;
  text-align: right;
}

.lines td.ck {
  text-align: center;
}

.ck-box {
  display: flex;
  justify-content: center;
  align-items: center;
}

.ck-box input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.lines input.qty {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.card-foot {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.card-foot b {
  color: var(--ink);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.card-flag {
  margin-left: auto;
  background: #fdf3e6;
  border: 1px solid #f0d3ad;
  color: #7d4a12;
  border-radius: 999px;
  padding: 2px 11px;
  font-size: 11.5px;
  font-weight: 600;
}

#cards-empty {
  margin-top: 12px;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 26px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

#cards-empty p {
  margin: 0 0 12px;
}

/* ------------------------------------------------------------- brand picker */

.popover {
  position: fixed;
  z-index: 50;
  width: 300px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(10, 20, 30, 0.18);
}

.pop-head {
  flex: none;
  display: flex;
  gap: 6px;
  align-items: center;
}

.pop-search {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
}

.pop-search:focus {
  outline: none;
  border-color: var(--accent);
}

.pop-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 8px -4px 0;
  padding: 0 4px;
}

.pop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 5px 8px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.pop-item:hover {
  background: #f2f5f7;
}

.pop-item.on {
  background: var(--accent-soft);
}

.pop-item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(15, 95, 87, 0.35);
}

.pop-mark {
  flex: none;
  width: 36px;
  height: 26px;
  padding: 2px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.pop-mark svg,
.pop-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.pop-mark [fill="#000"] {
  fill: var(--logo-ink, #000) !important;
}

.pop-mark [stroke="#000"] {
  stroke: var(--logo-ink, #000) !important;
}

.pop-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.pop-tick {
  flex: none;
  color: var(--accent);
  font-weight: 800;
}

.pop-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--muted);
}

.pop-foot .pop-count {
  flex: 1 1 auto;
}

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(13, 17, 23, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-box {
  width: min(680px, 100%);
  max-height: 100%;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(10, 20, 30, 0.3);
  padding: 18px 20px 16px;
}

.modal-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.modal-head h2 {
  flex: 1 1 auto;
  margin: 0;
  font-size: 17px;
  font-weight: 800;
}

.modal-sub {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.modal-box h3 {
  margin: 18px 0 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.field {
  display: block;
  margin-top: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.field > span {
  display: block;
  margin-bottom: 4px;
}

.field.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--ink);
}

.field.inline input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* The factory list box: one name per line, so it reads like the file it saves
   to. No soft wrapping — a long name scrolls sideways rather than looking like
   two factories. */
.factory-list {
  min-height: 88px;
  line-height: 1.55;
  resize: vertical;
  white-space: pre;
  overflow-x: auto;
}

.factory-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.factory-actions .modal-sub {
  margin: 0;
}

.color-list {
  margin-top: 10px;
  max-height: 300px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 4px;
}

.crow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 13px;
}

.crow:nth-child(even) {
  background: #fafbfc;
}

.cname {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cpick {
  flex: none;
  width: 36px;
  height: 26px;
  padding: 1px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.chex {
  flex: none;
  width: 68px;
  font-size: 11.5px;
  color: var(--muted);
}

.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  font-size: 12.5px;
}

.modal-foot #set-status {
  flex: 1 1 auto;
}

#set-status.ok {
  color: var(--accent);
  font-weight: 600;
}

#set-status.warn {
  color: #7d4a12;
  font-weight: 600;
}

/* The black-logos note under the checkbox: it has to say plainly that the
   colour list below is not what is printing right now. */
.modal-sub.ok {
  color: var(--accent);
}

.modal-sub.warn {
  color: #7d4a12;
  font-weight: 600;
}

/* ------------------------------------------------------------------- misc */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 16px);
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  max-width: 74vw;
  pointer-events: none;
  z-index: 80;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.warn {
  background: #8a3b12;
}

.toast.ok {
  background: var(--accent);
}

.footnote {
  margin: 14px 2px 0;
  font-size: 12px;
  color: var(--muted);
}

.footnote b {
  color: var(--ink);
}

.sheet-tag {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

@media (max-width: 1180px) {
  #workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .pane-preview {
    border-left: none;
    border-top: 1px solid var(--line);
  }
}
