/* ============================================================
   Quillbill — invoice studio styles
   ============================================================ */

body.app-body {
  background: #eef0ea;
}

/* ---------- Top bar ---------- */

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.plan-pill {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--border-strong);
  color: var(--ink-soft);
}

.plan-pill.pro {
  background: #f7efdb;
  border-color: #e3cf9d;
  color: #7a5a08;
}

/* ---------- Layout ---------- */

.studio {
  display: grid;
  grid-template-columns: minmax(380px, 500px) 1fr;
  gap: 26px;
  padding: 26px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}

/* Grid items must be allowed to shrink below their content's
   intrinsic width, or wide inputs blow out the column. */
.studio > *,
.panel,
.field input,
.field select,
.item-row input {
  min-width: 0;
}

@media (max-width: 1020px) {
  .studio {
    grid-template-columns: 1fr;
  }
}

/* ---------- Editor panel ---------- */

.editor {
  display: grid;
  gap: 16px;
}

.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 0;
}

.panel-body {
  padding: 16px 18px 18px;
  display: grid;
  gap: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 480px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
}

/* Logo upload */

.logo-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-preview {
  width: 56px;
  height: 56px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--paper);
  flex: none;
}

.logo-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.logo-preview span {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
}

/* Accent swatches */

.swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  position: relative;
}

.swatch.active {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.swatch.locked::after {
  content: "🔒";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
}

/* Line items */

.item-row {
  display: grid;
  grid-template-columns: 1fr 64px 92px 30px;
  gap: 8px;
  align-items: center;
}

.item-row input {
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  width: 100%;
  color: var(--ink);
  background: #fff;
}

.item-row input:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
}

.item-row .num-input {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.item-remove {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  border-radius: 6px;
  height: 30px;
}

.item-remove:hover {
  color: var(--danger);
  background: var(--danger-tint);
}

.items-header {
  display: grid;
  grid-template-columns: 1fr 64px 92px 30px;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* ---------- Preview column ---------- */

.preview-col {
  position: sticky;
  top: 86px;
  display: grid;
  gap: 14px;
}

@media (max-width: 1020px) {
  .preview-col {
    position: static;
  }
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.preview-toolbar .hint {
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- The invoice sheet ---------- */

.sheet-wrap {
  overflow-x: auto;
}

.sheet {
  --accent: #0e6b54;
  background: #fff;
  width: 100%;
  max-width: 800px;
  min-height: 1000px;
  margin: 0 auto;
  padding: 56px 60px;
  box-shadow: var(--shadow);
  border-radius: 4px;
  font-size: 14px;
  color: #1a2420;
  display: flex;
  flex-direction: column;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 40px;
}

.sheet-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.sheet-logo {
  max-height: 64px;
  max-width: 180px;
  object-fit: contain;
}

.sheet-business-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.sheet-title-block {
  text-align: right;
}

.sheet-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
  line-height: 1;
}

.sheet-number {
  font-family: var(--font-mono);
  font-size: 13px;
  color: #6a756f;
  margin-top: 8px;
}

.sheet-meta {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 40px;
}

.sheet-parties {
  display: flex;
  gap: 48px;
}

.sheet-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #8a948e;
  margin-bottom: 6px;
}

.sheet-party {
  white-space: pre-line;
  font-size: 13.5px;
  line-height: 1.55;
}

.sheet-party strong {
  font-size: 14.5px;
}

.sheet-dates {
  text-align: right;
  font-size: 13.5px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.sheet-dates .val {
  font-weight: 600;
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 28px;
}

.sheet-table th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #6a756f;
  border-bottom: 2px solid var(--accent);
  padding: 10px 8px;
}

.sheet-table td {
  padding: 12px 8px;
  border-bottom: 1px solid #eceee9;
  vertical-align: top;
  font-size: 13.5px;
}

.sheet-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sheet-table th.num {
  text-align: right;
}

.sheet-totals {
  margin-left: auto;
  width: 280px;
  display: grid;
  gap: 8px;
  margin-bottom: 40px;
}

.sheet-totals .row {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  color: #4a554f;
}

.sheet-totals .row .num {
  font-variant-numeric: tabular-nums;
}

.sheet-totals .grand {
  border-top: 2px solid var(--accent);
  padding-top: 10px;
  margin-top: 4px;
  font-size: 17px;
  font-weight: 800;
  color: #1a2420;
}

.sheet-totals .grand .num {
  color: var(--accent);
}

.sheet-notes {
  display: grid;
  gap: 22px;
  margin-top: auto;
}

.sheet-notes .block p {
  white-space: pre-line;
  font-size: 13px;
  color: #4a554f;
  margin: 0;
}

.sheet-footer-badge {
  margin-top: 34px;
  padding-top: 16px;
  border-top: 1px solid #eceee9;
  font-size: 11px;
  color: #9aa49e;
  text-align: center;
}

/* ---------- History table ---------- */

.history-table-wrap {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 640px;
}

.history-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.history-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.history-table tr:last-child td {
  border-bottom: none;
}

.history-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.status {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  font-family: inherit;
}

.status-draft {
  background: #f0f0eb;
  color: #6a756f;
}

.status-sent {
  background: #e8effa;
  color: #2456a0;
}

.status-paid {
  background: var(--brand-tint);
  color: var(--brand-ink);
}

.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.row-actions button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand);
  padding: 4px 8px;
  border-radius: 6px;
  font-family: inherit;
}

.row-actions button:hover {
  background: var(--brand-tint);
}

.row-actions button.danger {
  color: var(--danger);
}

.row-actions button.danger:hover {
  background: var(--danger-tint);
}

.empty-note {
  padding: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(22, 36, 31, 0.5);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 460px;
  width: 100%;
  padding: 34px 32px;
  position: relative;
}

.modal h2 {
  font-size: 21px;
  margin-bottom: 8px;
}

.modal > p {
  color: var(--muted);
  font-size: 14.5px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: none;
  background: none;
  font-size: 22px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 6px;
}

.modal ul.perks {
  list-style: none;
  padding: 0;
  margin: 18px 0 22px;
  display: grid;
  gap: 9px;
}

.modal ul.perks li {
  display: flex;
  gap: 10px;
  font-size: 14px;
  color: var(--ink-soft);
}

.modal ul.perks svg {
  flex: none;
  margin-top: 3px;
  color: var(--brand);
}

.modal .divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 20px 0 14px;
}

.modal .divider::before,
.modal .divider::after {
  content: "";
  height: 1px;
  background: var(--border);
  flex: 1;
}

.license-row {
  display: flex;
  gap: 8px;
}

.license-row input {
  flex: 1;
}

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

.modal .error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  margin: 8px 0 0;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 11px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

/* ============================================================
   Print — everything disappears except the invoice sheet.
   Use the browser's "Save as PDF" for a crisp vector export.
   ============================================================ */

@page {
  size: A4;
  margin: 0;
}

@media print {
  body.app-body {
    background: #fff;
  }

  body * {
    visibility: hidden;
  }

  .sheet,
  .sheet * {
    visibility: visible;
  }

  .sheet {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    max-width: none;
    min-height: auto;
    margin: 0;
    padding: 18mm 16mm;
    box-shadow: none;
    border-radius: 0;
  }

  .sheet-notes {
    margin-top: 36px;
  }
}
