/* ==========================================================================
   Invoice Generator - application shell
   (The invoice itself is styled in invoice.css)
   ========================================================================== */

:root {
  /* Brand colours sampled from the printed template */
  --navy:        #1c4568;
  --navy-deep:   #14304f;
  --navy-ink:    #0b2545;
  --gold:        #fac314;
  --gold-soft:   #fbf6df;
  --red:         #d42026;

  /* Application neutrals */
  --bg:          #f2f4f7;
  --panel:       #ffffff;
  --line:        #dfe4ea;
  --line-soft:   #eceff3;
  --ink:         #1a2230;
  --ink-soft:    #5b6676;
  --ink-faint:   #8a94a3;
  --focus:       #2f6fb0;

  --radius:      6px;
  --radius-lg:   8px;
  --shadow:      0 1px 2px rgba(16, 30, 54, .06), 0 1px 3px rgba(16, 30, 54, .04);
  --topbar-h:    64px;

  --font: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over a class that sets `display`. */
[hidden] { display: none !important; }

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

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ==========================================================================
   Top bar
   ========================================================================== */

.topbar {
  flex: 0 0 auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(16, 30, 54, .05);
  z-index: 5;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar__logo {
  height: 34px;
  width: auto;
  flex: 0 0 auto;
}

.topbar__titles {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.topbar__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy-ink);
  letter-spacing: .1px;
}

.topbar__sub {
  font-size: 11.5px;
  color: var(--ink-faint);
}

/* Switch between the two documents the office produces. */
.doctabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f4f6f9;
}

.doctabs__tab {
  display: inline-flex;
  align-items: center;
  padding: 7px 15px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .12s ease, color .12s ease;
}

.doctabs__tab:hover { background: #e7ecf2; color: var(--ink); }

.doctabs__tab.is-active {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 1px 2px rgba(16, 30, 54, .18);
}

.doctabs__tab:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.topbar__center {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

.invchip {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
}

.invchip__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--ink-faint);
  font-weight: 600;
}

.invchip__value {
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

/* Once the invoice has been exported the number is final, not a preview. */
.invchip.is-issued {
  border-color: #b9dcc7;
  background: #f2fbf6;
}
.invchip.is-issued .invchip__label { color: #1d7a4d; }

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex: 0 0 auto;
}

.status[data-state="ok"]      .status__dot { background: #22a06b; }
.status[data-state="error"]   .status__dot { background: #d9403a; }
.status[data-state="loading"] .status__dot { background: #e0a03a; }
.status[data-state="error"]   .status__text { color: #b3312c; font-weight: 600; }

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  padding: 11px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
  white-space: nowrap;
}

.btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.btn--primary:hover:not(:disabled) { background: #17395a; border-color: #17395a; }

.btn--secondary {
  background: var(--gold);
  color: var(--navy-ink);
  border-color: #e6b210;
}
.btn--secondary:hover:not(:disabled) { background: #f0b90c; }

.btn--ghost {
  background: #fff;
  color: var(--ink-soft);
  border-color: var(--line);
}
.btn--ghost:hover:not(:disabled) { background: #f6f8fa; color: var(--ink); }

.btn--danger {
  background: #b3312c;
  color: #fff;
  border-color: #a12b26;
}
.btn--danger:hover:not(:disabled) { background: #9c2a25; }

.cleanup__file {
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  color: var(--ink);
  background: #f4f6f9;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  overflow-wrap: anywhere;
}

.btn--add {
  background: #fff;
  color: var(--navy);
  border: 1px dashed #b9c6d4;
  font-size: 13px;
  padding: 9px 16px;
  width: 100%;
  justify-content: center;
}
.btn--add:hover { background: #f4f8fc; border-color: var(--navy); }

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ==========================================================================
   Workspace: editor | preview
   ========================================================================== */

.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(430px, 46fr) minmax(420px, 54fr);
  min-height: 0;
}

.editor {
  overflow-y: auto;
  padding: 18px 18px 40px;
  border-right: 1px solid var(--line);
  background: var(--bg);
}

.preview {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #e6e9ee;
}

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto auto; }
  .editor { border-right: 0; border-bottom: 1px solid var(--line); }
  .preview { min-height: 80vh; }
}

/* ==========================================================================
   Editor cards & fields
   ========================================================================== */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: #fbfcfd;
}

.card__head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--navy);
}

.card__note {
  font-size: 12px;
  color: var(--ink-faint);
}

.card__body { padding: 16px; }
.card__body--flush { padding: 0; }

.grid {
  display: grid;
  gap: 14px 14px;
}
.grid--2    { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3    { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--city    { grid-template-columns: 1.6fr .8fr 1fr 1.4fr; gap: 14px; margin-top: 14px; }
.grid--stacked { margin-top: 14px; }

.field       { display: flex; flex-direction: column; min-width: 0; }
.field--wide { grid-column: 1 / -1; }

.field label,
.field__title {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

/* Checkbox styled to match the height and framing of a text field. */
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid #cfd6df;
  border-radius: var(--radius);
  background: #fff;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--ink);
  margin-bottom: 0;
  cursor: pointer;
}
.check:hover { background: #f8fafc; }
.check:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(47, 111, 176, .16);
}
.check input {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  accent-color: var(--navy);
  cursor: pointer;
}
.check strong { font-weight: 700; color: var(--navy); }
.check--tight { margin-top: 8px; padding: 8px 12px; min-height: 38px; font-size: 13px; }
.check.is-disabled { opacity: .55; }

/* $ / % switch living inside the money field frame. */
.unit-select {
  border: 0;
  border-left: 1px solid #e2e8ef;
  background: #f4f7fa;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  padding: 0 8px;
  cursor: pointer;
  outline: none;
}
.unit-select:disabled { cursor: not-allowed; }

.input-money.is-disabled { background: #f1f4f7; opacity: .6; }
.input-money.is-disabled .input { background: transparent; }

.req { color: var(--red); }

.input {
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  padding: 10px 12px;
  border: 1px solid #cfd6df;
  border-radius: var(--radius);
  background: #fff;
  width: 100%;
  min-width: 0;
  transition: border-color .12s ease, box-shadow .12s ease;
}

.input::placeholder { color: #a9b2be; }

.input:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(47, 111, 176, .16);
}

.input--locked {
  background: #f1f4f7;
  color: var(--navy);
  font-weight: 700;
  letter-spacing: .5px;
  cursor: default;
}

.input.is-invalid {
  border-color: #d9403a;
  background: #fff7f7;
}

textarea.input {
  resize: vertical;
  line-height: 1.45;
  min-height: 62px;
}

.hint {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.input-money {
  display: flex;
  align-items: stretch;
  border: 1px solid #cfd6df;
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.input-money:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(47, 111, 176, .16);
}

.input-money > span {
  display: flex;
  align-items: center;
  padding: 0 11px;
  background: #f4f7fa;
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 600;
  border-right: 1px solid #e2e8ef;
}

.input-money--suffix > span {
  border-right: 0;
  border-left: 1px solid #e2e8ef;
}

.input-money .input {
  border: 0;
  border-radius: 0;
}
.input-money .input:focus { box-shadow: none; }

/* ==========================================================================
   Line items editor
   ========================================================================== */

.items { border-bottom: 1px solid var(--line-soft); }

.items__head,
.item-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 118px 118px 36px;
  gap: 10px;
  align-items: center;
  padding: 0 16px;
}

.items__head {
  height: 36px;
  background: #f6f8fa;
  border-bottom: 1px solid var(--line-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.items__head > span:nth-child(3),
.items__head > span:nth-child(4) { text-align: right; }

.item-row {
  padding-top: 9px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line-soft);
}
.item-row:last-child { border-bottom: 0; }
.item-row:hover { background: #fbfcfe; }

.item-row .input { padding: 8px 10px; font-size: 13.5px; }

/* The description is a textarea so Enter adds a line inside the same item.
   It grows with its content - see autoGrow() in app.js. */
.item-row textarea.input--desc {
  resize: none;
  overflow: hidden;
  line-height: 1.35;
  min-height: 36px;
  font-family: inherit;
}
.item-row .input--num { text-align: right; font-variant-numeric: tabular-nums; }

.item-row__amount {
  text-align: right;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  padding-right: 2px;
}

.item-row__del {
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.item-row__del svg {
  width: 15px; height: 15px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
}
.item-row__del:hover { background: #fdeded; color: #c5342e; border-color: #f3c9c7; }
.item-row__del:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.items__empty {
  padding: 22px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-faint);
}

.items__foot { padding: 12px 16px; }

.hint--center { text-align: center; margin-top: 9px; }

/* ==========================================================================
   Totals summary
   ========================================================================== */

.summary {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.summary__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  font-size: 13.5px;
  color: var(--ink-soft);
  background: #fbfcfd;
  border-bottom: 1px solid var(--line-soft);
}

.summary__row span:last-child {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--ink);
}

.summary__row--grand {
  border-bottom: 0;
  background: var(--navy);
  color: #fff;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 700;
}
.summary__row--grand span:last-child { color: var(--gold); font-size: 17px; font-weight: 700; }

/* "EXPORT" instead of a tax amount, and the recorded payment. */
#sumTax  { letter-spacing: .6px; color: var(--navy) !important; }
#sumPaid { color: #8f2c28 !important; }

/* ==========================================================================
   Alerts, toast, modal
   ========================================================================== */

/* Shown while an already-exported invoice is open for changes. */
.editbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 14px;
  margin-bottom: 14px;
  border: 1px solid #e3c98f;
  border-radius: var(--radius-lg);
  background: #fdf7e7;
  font-size: 13px;
  color: #6b5417;
}

.editbar__text { flex: 1 1 auto; line-height: 1.45; }
.editbar strong { color: #4d3c0c; font-variant-numeric: tabular-nums; }

.btn--small { padding: 7px 12px; font-size: 12.5px; }

/* The invoice-number chip while editing an existing invoice. */
.invchip.is-editing {
  border-color: #e3c98f;
  background: #fdf7e7;
}
.invchip.is-editing .invchip__label { color: #8a6d16; }

/* ---- saved-invoice picker ---- */
.modal__box--wide { max-width: 600px; }

.dropzone {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  margin-bottom: 14px;
  border: 1px dashed #b9c6d4;
  border-radius: var(--radius);
  background: #f8fafc;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.dropzone.is-over {
  border-color: var(--navy);
  background: #eef4fa;
}

.dropzone svg {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  fill: none;
  stroke: var(--navy);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dropzone strong { color: var(--ink); }

.dropzone__hint {
  display: block;
  font-size: 11.5px;
  color: var(--ink-faint);
  margin-top: 2px;
}

.linkbtn {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--focus);
  text-decoration: underline;
  cursor: pointer;
}
.linkbtn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.picker {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: 340px;
  overflow-y: auto;
  background: #fff;
}

.picker__row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  font-family: inherit;
  font-size: 13.5px;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}
.picker__row:last-child { border-bottom: 0; }
.picker__row:hover { background: #f4f8fc; }
.picker__row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

.picker__no {
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.picker__who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker__meta {
  font-size: 12.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.picker__empty {
  padding: 26px 14px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 13px;
}

.picker__note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--ink-faint);
}

.picker__manual {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.picker__manual > label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.picker__manualRow {
  display: flex;
  gap: 8px;
}
.picker__manualRow .input { flex: 1 1 auto; }
.picker__manualRow .btn  { flex: 0 0 auto; }

.alert {
  border-radius: var(--radius-lg);
  padding: 13px 16px;
  margin-bottom: 14px;
  font-size: 13px;
  border: 1px solid;
}

.alert--error {
  background: #fdf3f3;
  border-color: #f0c9c7;
  color: #8f2c28;
}

.alert__title { font-weight: 700; margin-bottom: 6px; }
.alert__list  { margin: 0; padding-left: 20px; line-height: 1.6; }

.editor__foot {
  margin: 4px 2px 0;
  font-size: 12px;
  color: var(--ink-faint);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--navy-ink);
  color: #fff;
  font-size: 13.5px;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(11, 37, 69, .28);
  z-index: 60;
  max-width: 70vw;
}
.toast[data-kind="error"] { background: #a52d28; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(16, 30, 54, .42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
  padding: 20px;
}

.modal__box {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(16, 30, 54, .25);
}

.modal__box h3 { margin: 0 0 10px; font-size: 17px; color: var(--navy-ink); }
.modal__box p  { margin: 0 0 12px; font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; }
.modal__box ul { margin: 0 0 16px; padding-left: 20px; font-size: 13.5px; line-height: 1.9; color: var(--ink); }

.modal__check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 18px;
  cursor: pointer;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ==========================================================================
   Preview panel
   ========================================================================== */

.preview__bar {
  flex: 0 0 auto;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: #dde2e9;
  border-bottom: 1px solid #ccd3dc;
  font-size: 11.5px;
  color: #59636f;
}

.preview__label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
}

.preview__scroll {
  flex: 1 1 auto;
  overflow: auto;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* The pages are rendered at true Letter size and the whole stack is scaled
   down to fit the panel. .sheet-scaler reserves the scaled-down footprint. */
.sheet-scaler {
  transform-origin: top left;
  flex: 0 0 auto;
}

.pages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  transform-origin: top left;
  width: 816px;
}

/* ==========================================================================
   PRINT / PDF EXPORT
   Everything except the invoice sheet is removed, and the sheet is restored
   to its true 8.5 x 11 in size.
   ========================================================================== */

@page {
  size: Letter portrait;
  margin: 0;
}

@media print {
  html, body {
    height: auto;
    background: #fff;
  }

  .topbar,
  .doctabs,
  .editbar,
  .editor,
  .preview__bar,
  .modal,
  .toast { display: none !important; }

  .app,
  .workspace,
  .preview,
  .preview__scroll {
    display: block !important;
    position: static !important;
    overflow: visible !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: #fff !important;
    box-shadow: none !important;
  }

  .sheet-scaler {
    transform: none !important;
    width: auto !important;
    height: auto !important;
  }

  /* No gap between pages on paper, and no scaling. */
  .pages {
    display: block !important;
    transform: none !important;
    width: auto !important;
    gap: 0 !important;
  }
}
