:root {
  --ink: #162538;
  --ink-soft: #33455b;
  --muted: #6b7a8e;
  --muted-strong: #526277;
  --line: #dce4ed;
  --line-strong: #c9d5e2;
  --canvas: #f3f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-blue: #eef5fb;
  --blue: #215c8b;
  --blue-dark: #17466e;
  --blue-pale: #dcebf7;
  --green: #2f775a;
  --green-pale: #eaf6ef;
  --danger: #a23b3b;
  --shadow-sm: 0 2px 8px rgba(22, 37, 56, 0.05);
  --shadow-md: 0 16px 36px rgba(22, 37, 56, 0.10);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }
html { background: var(--canvas); }
body {
  margin: 0;
  min-width: 320px;
  background: radial-gradient(circle at 92% 0%, rgba(210, 228, 242, 0.45), transparent 26rem), var(--canvas);
  color: var(--ink);
  font: 14px/1.45 Inter, "Segoe UI", Arial, sans-serif;
}
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-header {
  max-width: 1360px;
  margin: 0 auto;
  padding: 42px 44px 30px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
}
.eyebrow { margin: 0 0 7px; color: var(--blue); font-size: 10px; font-weight: 800; letter-spacing: .16em; line-height: 1.2; text-transform: uppercase; }
.app-header h1, .panel h2, .panel h3 { margin: 0; }
.app-header h1 { color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: clamp(30px, 3.4vw, 43px); font-weight: 700; letter-spacing: -.025em; line-height: 1.05; }
.subtitle { max-width: 680px; margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.header-actions, .quick-actions, .modal-actions { display: flex; align-items: center; gap: 9px; }
.header-actions { flex-shrink: 0; }

.ghost, .secondary, .print-button, .small-button { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink-soft); cursor: pointer; font-weight: 700; transition: border-color 160ms ease, background 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease; }
.ghost, .secondary, .print-button { min-height: 42px; padding: 10px 14px; }
.small-button { min-height: 38px; padding: 8px 12px; }
.ghost:hover, .secondary:hover, .small-button:hover { border-color: #9bb5ca; background: var(--surface-blue); color: var(--blue-dark); }
.ghost:active, .secondary:active, .small-button:active, .primary:active, .print-button:active { transform: translateY(1px); }
.file-button { display: inline-flex; align-items: center; }
.file-button input { display: none; }

.layout { max-width: 1360px; margin: 0 auto; padding: 0 44px 48px; display: grid; grid-template-columns: minmax(390px, 430px) minmax(0, 1fr); align-items: start; gap: 28px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius-lg); background: rgba(255, 255, 255, .96); box-shadow: var(--shadow-sm); }
.controls { position: sticky; top: 22px; padding: 25px; }
.panel-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 23px; }
.panel h2 { font-family: Georgia, "Times New Roman", serif; font-size: 24px; line-height: 1.1; }
.panel h3 { color: var(--ink); font-size: 16px; line-height: 1.2; }
.save-status { flex-shrink: 0; padding: 6px 10px; border: 1px solid #cfe8d7; border-radius: 999px; background: var(--green-pale); color: var(--green); font-size: 11px; font-weight: 750; white-space: nowrap; }

.controls > label, .modal form > label { display: flex; flex-direction: column; gap: 7px; margin-bottom: 15px; color: var(--muted-strong); font-size: 12px; font-weight: 750; letter-spacing: .01em; }
.controls input, .controls select, .modal input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); outline: none; background: var(--surface); color: var(--ink); transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease; }
.controls input:hover, .controls select:hover, .modal input:hover { border-color: #afc1d2; }
.controls input:focus, .controls select:focus, .modal input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(33, 92, 139, .13); background: #fff; }
.select-with-action { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.select-with-action select { min-width: 0; }
.two-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 13px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 26px 0 11px; padding-top: 19px; border-top: 1px solid var(--line); }
.section-heading .eyebrow { margin-bottom: 5px; }
.hint { margin: 3px 0 14px; color: var(--muted); font-size: 11px; line-height: 1.5; }

.charges { display: flex; flex-direction: column; gap: 9px; }
.empty-row { padding: 14px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-soft); color: var(--muted); font-size: 12px; }
.charge-row { display: grid; grid-template-columns: minmax(0, 1fr) 94px 115px 28px; gap: 7px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-soft); }
.charge-row .charge-desc { grid-column: 1 / -1; }
.charge-row input, .charge-row select { min-width: 0; min-height: 38px; padding: 8px 9px; border: 1px solid var(--line-strong); border-radius: 7px; outline: none; background: #fff; color: var(--ink-soft); font-size: 12px; }
.charge-row input:focus, .charge-row select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(33, 92, 139, .11); }
.charge-row .remove, .rate-row button { display: inline-grid; width: 28px; height: 34px; place-items: center; border: 0; background: transparent; color: var(--danger); cursor: pointer; font-size: 20px; line-height: 1; }
.charge-row .remove:hover, .rate-row button:hover { color: #7c2020; }
.quick-actions { align-items: stretch; margin-top: 13px; }
.quick-actions button { flex: 1; min-width: 0; font-size: 11px; }
.check-row { display: flex !important; flex-direction: row !important; align-items: center; gap: 9px !important; margin-bottom: 6px !important; color: var(--ink-soft) !important; font-weight: 600 !important; letter-spacing: 0 !important; }
.check-row input { width: 16px; min-height: 16px; accent-color: var(--blue); }
.full { width: 100%; margin-top: 9px; }
.primary { min-height: 44px; padding: 10px 14px; border: 1px solid var(--blue); border-radius: var(--radius-sm); background: var(--blue); color: #fff; cursor: pointer; font-weight: 750; transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease; }
.primary:hover { background: var(--blue-dark); box-shadow: 0 6px 16px rgba(33, 92, 139, .22); }
.print-button { border-color: #b8cfe1; background: var(--surface-blue); color: var(--blue-dark); }
.print-button:hover { border-color: #8fb0c8; background: var(--blue-pale); }

.preview-wrap { min-width: 0; }
.preview-toolbar { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 5px 13px; color: var(--muted); font-size: 12px; font-weight: 700; }
.preview-toolbar span:last-child { color: var(--blue); font-weight: 750; }
.receipt { min-height: 1120px; padding: 25mm 18mm 20mm; border: 1px solid #e5e9ee; border-radius: 4px; background: var(--surface); box-shadow: var(--shadow-md); color: #171717; font: 12.5pt/1.38 "Times New Roman", Times, serif; }
.receipt .date { margin: 0 0 19px; text-align: right; }
.receipt .to { margin: 0 0 15px; }
.receipt .intro { margin: 0 0 15px; text-align: justify; }
.receipt h4 { margin: 17px 0 6px; color: #151515; font-size: 14pt; letter-spacing: .035em; text-align: center; text-transform: uppercase; }
.receipt .evolution { margin: 0 0 15px; }
.receipt .line { display: flex; justify-content: space-between; gap: 16px; margin: 4px 0; }
.receipt .line .label { flex: 1; }
.receipt .line .value { white-space: nowrap; }
.receipt .total-line { margin-top: 7px; padding-top: 6px; border-top: 1px solid #989898; font-weight: 700; }
.receipt .payer { margin: 19px 0; }
.receipt .payer-title { margin-bottom: 5px; font-weight: 700; }
.receipt .attention { margin: 22px 0 9px; font-weight: 700; }
.receipt .payments { margin: 0 0 16px; }
.receipt .contact { margin-top: 21px; }
.receipt .signature { margin-top: 24px; text-align: center; }
.page-break { break-before: page; page-break-before: always; }
.empty-preview { display: grid; min-height: 420px; place-items: center; border: 1px dashed var(--line-strong); border-radius: var(--radius-md); background: var(--surface); color: var(--muted); font-size: 14px; }

.modal { width: min(680px, calc(100% - 30px)); padding: 0; border: 0; border-radius: var(--radius-lg); box-shadow: 0 28px 80px rgba(10, 24, 40, .28); }
.modal::backdrop { background: rgba(13, 29, 45, .48); }
.modal form { padding: 26px; }
.close { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 27px; line-height: 1; }
.close:hover { color: var(--ink); }
.rate-history { display: flex; flex-direction: column; gap: 8px; }
.rate-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 28px; gap: 8px; align-items: center; }
.rate-row input { min-height: 40px; padding: 8px 10px; }
.modal-actions { justify-content: flex-end; margin-top: 22px; padding-top: 17px; border-top: 1px solid var(--line); }

footer { max-width: 1360px; margin: 0 auto; padding: 0 44px 30px; color: var(--muted); font-size: 11px; }

@media (max-width: 1050px) {
  .app-header { padding-inline: 28px; }
  .layout { grid-template-columns: minmax(350px, 400px) minmax(0, 1fr); padding-inline: 28px; gap: 20px; }
  .controls { padding: 21px; }
  .charge-row { grid-template-columns: minmax(0, 1fr) 86px 105px 26px; gap: 5px; padding: 8px; }
  footer { padding-inline: 28px; }
}

@media (max-width: 820px) {
  .app-header { display: block; padding: 28px 20px 22px; }
  .header-actions { margin-top: 18px; }
  .layout { display: block; padding: 0 20px 34px; }
  .controls { position: static; margin-bottom: 25px; }
  .receipt { min-height: auto; box-shadow: var(--shadow-sm); }
  footer { padding: 0 20px 24px; }
}

@media (max-width: 560px) {
  .header-actions, .quick-actions { flex-direction: column; align-items: stretch; }
  .header-actions > *, .quick-actions > * { width: 100%; }
  .two-cols { grid-template-columns: 1fr; gap: 0; }
  .charge-row { grid-template-columns: minmax(0, 1fr) 28px; gap: 7px; }
  .charge-row .charge-desc { grid-column: 1 / -1; }
  .charge-row .charge-amount, .charge-row .charge-allocation, .charge-row .charge-sign { grid-column: 1; }
  .charge-row .remove { grid-column: 2; grid-row: 2 / span 3; align-self: center; }
  .receipt { padding: 16mm 11mm; font-size: 11.5pt; }
  .modal form { padding: 20px; }
}

@media print {
  html, body { background: #fff; }
  .no-print, .preview-toolbar { display: none !important; }
  .layout { display: block; margin: 0; padding: 0; }
  .preview-wrap { width: 100%; }
  .receipt { min-height: 0; width: 100%; padding: 15mm; border: 0; border-radius: 0; box-shadow: none; }
  footer { display: none; }
}
