/* Screens specific to invoices, pickers and settings. Tokens only. */

.dash-cols { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--s4); align-items: start; }
@media (max-width: 1000px) { .dash-cols { grid-template-columns: 1fr; } }

/* --- invoice form ------------------------------------------------------ */

.inv-form { display: grid; grid-template-columns: 1fr 320px; gap: var(--s4); align-items: start; }
.inv-side { position: sticky; top: calc(var(--s6) + var(--s5)); }

.summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4);
}
.summary-head {
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3);
  margin-bottom: var(--s3);
}
.sum-row {
  display: flex; justify-content: space-between; gap: var(--s3);
  padding: 5px 0;
  font-size: var(--fs-sm);
  color: var(--ink-2);
}
.sum-row .num { font-variant-numeric: tabular-nums; color: var(--ink); }
.sum-total {
  border-top: 1px solid var(--line);
  margin-top: var(--s2); padding-top: var(--s3);
  font-size: var(--fs-lg); font-weight: 650; color: var(--ink);
}
.sum-total .num { font-family: var(--font-serif); font-size: var(--fs-xl); }
.sum-balance { font-weight: 650; color: var(--warn); }
.sum-balance .num { color: var(--warn); }
.sum-words {
  margin-top: var(--s3); padding-top: var(--s3);
  border-top: 1px dashed var(--line);
  font-size: var(--fs-xs); color: var(--ink-3); font-style: italic;
}
.sum-note {
  margin-top: var(--s3);
  display: flex; gap: var(--s2); align-items: center;
  background: var(--warn-soft); color: var(--warn);
  padding: var(--s2) var(--s3); border-radius: var(--radius-sm);
  font-size: var(--fs-xs); font-weight: 550;
}
.sum-note .icon { width: 15px; height: 15px; flex: none; }

/* Primary action lives in the summary on desktop and in the sticky bar on
   mobile -- exactly one of the two is visible at any width. */
.summary-save { margin-top: var(--s4); }
@media (max-width: 1000px) { .summary-save { display: none; } }

/* chosen customer / empty pick */
.pick-empty {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%;
  padding: var(--s4);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-2);
  font: inherit; text-align: left;
  cursor: pointer;
  transition: border-color .14s var(--ease), background .14s var(--ease);
}
.pick-empty:hover { border-color: var(--accent); background: var(--accent-soft); }
.pick-empty > .icon:first-child { width: 22px; height: 22px; color: var(--ink-3); flex: none; }
.pick-empty > div { flex: 1; }
.pick-empty > .icon:last-child { width: 17px; height: 17px; color: var(--ink-3); flex: none; }

.chosen {
  display: flex; align-items: flex-start; gap: var(--s3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s3) var(--s4);
}
.chosen-main { flex: 1; min-width: 0; }
.chosen-name { font-weight: 650; font-size: var(--fs-lg); }
.chosen-line { color: var(--ink-2); font-size: var(--fs-sm); margin-top: 2px; }
.chosen-meta {
  display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3);
  margin-top: 5px; font-size: var(--fs-xs); color: var(--ink-3);
}

/* item lines */
.line {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s3);
  margin-bottom: var(--s3);
  background: var(--surface);
  transition: border-color .14s var(--ease);
}
.line:focus-within { border-color: var(--accent-line); }
.line-head { display: flex; gap: var(--s2); align-items: center; margin-bottom: var(--s3); }
.line-name {
  flex: 1;
  font-weight: 600 !important;
  border-color: transparent !important;
  background: transparent !important;
  padding-left: 6px !important;
}
.line-name:focus { border-color: var(--accent) !important; background: var(--surface) !important; }
.line-del { flex: none; color: var(--ink-3); }
.line-del:hover { color: var(--danger); background: var(--danger-soft); }

.line-grid {
  display: grid;
  grid-template-columns: .8fr .8fr 1fr .8fr 1.1fr;
  gap: var(--s2);
}
.line-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.line-field > span {
  font-size: var(--fs-xs); color: var(--ink-3); font-weight: 550;
  letter-spacing: .03em;
}
.line-field input, .line-field select { min-height: 38px; font-size: var(--fs-sm); padding: 6px 9px; }

.line-foot {
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3);
  margin-top: var(--s3); padding-top: var(--s2);
  border-top: 1px dashed var(--line);
}
.line-amount { font-weight: 650; font-size: var(--fs-lg); font-variant-numeric: tabular-nums; }

/* sticky total bar */
.sticky-total {
  position: sticky; bottom: 0; z-index: 15;
  display: none;
  align-items: center; gap: var(--s4);
  margin: var(--s4) calc(var(--s5) * -1) calc(var(--s5) * -1);
  padding: var(--s3) var(--s5);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.sticky-left { flex: 1; }
.topbar-back { display: none; }
@media (max-width: 860px) {
  body[data-route="/invoices/new"] .topbar-back { display: inline-flex; }
}
.sticky-label { font-size: var(--fs-xs); color: var(--ink-3); text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
.sticky-value { font-family: var(--font-serif); font-size: var(--fs-xl); font-weight: 650; }

@media (max-width: 1000px) {
  .inv-form { grid-template-columns: 1fr; }
  .inv-side { position: static; }
  .sticky-total { display: flex; }
  .line-grid { grid-template-columns: 1fr 1fr 1fr; }
  .line-field-hsn { grid-column: span 3; }
}
@media (max-width: 860px) {
  .sticky-total {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0;
    padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom));
    border-radius: 0;
  }
  .inv-form { padding-bottom: 84px; }

  /* Building an invoice is a focused task: the sticky total takes over the
     bottom of the screen and the tab bar steps aside. Scoped to this one route
     -- unscoped, it hid the bottom navigation on every mobile screen. The Back
     button in the top bar keeps the screen from being a dead end. */
  body[data-route="/invoices/new"] .tabbar { display: none; }
}

/* --- picker sheet ------------------------------------------------------ */

.pick-list { max-height: min(52vh, 420px); overflow-y: auto; margin: 0 calc(var(--s5) * -1) calc(var(--s5) * -1); }
.pick-row {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%;
  padding: var(--s3) var(--s5);
  border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--ink);
  font: inherit; text-align: left;
  cursor: pointer;
  transition: background .12s var(--ease);
}
.pick-row:hover { background: var(--surface-2); }
.pick-row-new { color: var(--accent); font-weight: 600; }
.pick-row-new .icon { width: 18px; height: 18px; }
.pick-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.pick-title { font-weight: 600; }
.pick-sub { font-size: var(--fs-sm); color: var(--ink-3); }

.price-preview:empty { display: none; }
.price-preview-inner {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: var(--s3);
  font-size: var(--fs-sm); color: var(--ink-2);
}
.price-preview-inner .num { color: var(--ink); }

/* --- invoice view ------------------------------------------------------ */

.inv-view { display: grid; grid-template-columns: 1fr 290px; gap: var(--s4); align-items: start; }
.inv-view-side { position: sticky; top: calc(var(--s6) + var(--s5)); }
@media (max-width: 1000px) {
  .inv-view { grid-template-columns: 1fr; }
  .inv-view-side { position: static; order: -1; }
}

.banner {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--radius);
  margin-bottom: var(--s4);
  font-size: var(--fs-sm); font-weight: 550;
}
.banner-danger { background: var(--danger-soft); color: var(--danger); }
.banner .icon { width: 18px; height: 18px; flex: none; }

.side-amount { text-align: left; }
.side-total {
  font-family: var(--font-serif);
  font-size: var(--fs-2xl);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  margin-top: 4px;
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--s3); margin: 0; font-size: var(--fs-sm); }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; text-align: right; }

/* On-screen rendering of the printed document */
.doc-card { padding: 0; overflow: hidden; background: var(--surface-2); }
.doc { padding: var(--s5); overflow-x: auto; }
.doc .sheet-a4 {
  background: #FFFFFF;
  color: #14181F;
  width: 210mm;
  min-height: auto;
  margin: 0 auto;
  padding: 12mm;
  box-shadow: var(--shadow-1);
  transform-origin: top left;
}
@media (max-width: 1200px) { .doc { padding: var(--s3); } .doc .sheet-a4 { zoom: .72; } }
@media (max-width: 860px)  { .doc .sheet-a4 { zoom: .48; padding: 8mm; } }

.pay-summary {
  display: grid; gap: var(--s2);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: var(--s3);
  margin-bottom: var(--s4);
  font-size: var(--fs-sm);
}
.pay-summary > div { display: flex; justify-content: space-between; }

.list-summary {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5);
  padding: var(--s3) var(--s4);
  font-size: var(--fs-sm); color: var(--ink-3);
}
.list-summary strong { color: var(--ink); }

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

.settings-tabs {
  display: flex; gap: var(--s1);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--s5);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.settings-tabs::-webkit-scrollbar { display: none; }
.settings-tab {
  padding: 10px var(--s4);
  border: 0; background: transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--ink-3);
  font: inherit; font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: color .14s var(--ease), border-color .14s var(--ease);
}
.settings-tab:hover { color: var(--ink); }
.settings-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
:root[data-theme="dark"] .settings-tab.active { color: var(--ink); border-bottom-color: var(--ink); }

.save-bar {
  position: sticky; bottom: 0;
  display: flex; justify-content: flex-end;
  padding: var(--s3) 0;
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}
@media (max-width: 860px) {
  .save-bar { padding-bottom: calc(var(--s3) + env(safe-area-inset-bottom)); }
  .save-bar .btn { width: 100%; }
}

.choice-row { display: flex; flex-wrap: wrap; gap: var(--s3); }
.choice {
  display: flex; align-items: center; gap: var(--s2);
  min-height: var(--control-h);
  padding: var(--s2) var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-2);
  font: inherit; font-weight: 550;
  cursor: pointer;
  transition: border-color .14s var(--ease), background .14s var(--ease), color .14s var(--ease);
}
.choice:hover { background: var(--surface-2); }
.choice.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
:root[data-theme="dark"] .choice.is-selected { color: var(--ink); }
.choice .icon { width: 17px; height: 17px; }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--s3); }
.swatch {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: var(--s3) var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .14s var(--ease), transform .1s var(--ease);
}
.swatch:hover { transform: translateY(-1px); }
.swatch span { width: 100%; height: 30px; border-radius: var(--radius-sm); display: block; }
.swatch em { font-style: normal; font-size: var(--fs-xs); color: var(--ink-2); }
.swatch.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.preview-strip { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }

.image-field { display: flex; gap: var(--s3); align-items: flex-start; }
.image-preview {
  width: 96px; height: 66px; flex: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  display: grid; place-items: center;
  overflow: hidden;
  padding: 4px;
}
.image-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

.help-list { margin: 0; padding-left: var(--s5); color: var(--ink-2); font-size: var(--fs-sm); }
.help-list li { margin-bottom: var(--s2); }
code {
  font-family: var(--font-mono); font-size: .92em;
  background: var(--surface-2); padding: 1px 5px; border-radius: 4px;
}

/* --- print sheet ------------------------------------------------------- */

.print-profiles { display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.print-profile {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .14s var(--ease), background .14s var(--ease);
}
.print-profile:hover { background: var(--surface-2); }
.print-profile input { position: absolute; opacity: 0; pointer-events: none; }
.print-profile-body { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.print-profile-label { font-weight: 600; }
.print-profile-sub { font-size: var(--fs-xs); color: var(--ink-3); }
.print-profile-tick { opacity: 0; color: var(--accent); width: 19px; height: 19px; flex: none; }
.print-profile.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.print-profile.is-selected .print-profile-tick { opacity: 1; }

.print-preview-shell {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
}
.print-preview-label {
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--ink-3);
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--line);
}
.print-preview {
  max-height: 300px; overflow: auto;
  padding: var(--s4);
  display: flex; justify-content: center;
}
.print-preview .sheet { background: #FFFFFF; color: #14181F; box-shadow: var(--shadow-1); }
.preview-a4 .sheet-a4 { width: 210mm; padding: 12mm; zoom: .42; }
.preview-p80 .sheet-thermal { width: 80mm; padding: 3mm; zoom: .95; }
.preview-p58 .sheet-thermal { width: 58mm; padding: 2mm; zoom: 1; }
