:root {
  --navy: #173f70;
  --navy-deep: #102f55;
  --gold: #efb61f;
  --ink: #17202c;
  --muted: #6f7884;
  --line: #d9dee5;
  --paper: #ffffff;
  --panel: #f3f5f8;
  --green: #2f8b67;
  --shadow: 0 28px 70px rgba(21, 35, 52, 0.15);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: #e9edf2;
  font-family: Inter, Aptos, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(380px, 450px) minmax(680px, 1fr);
  min-height: 100vh;
}

.editor-panel {
  position: relative;
  z-index: 2;
  min-width: 0;
  padding: 26px 30px 142px;
  background: #fff;
  box-shadow: 10px 0 34px rgba(23, 42, 66, 0.07);
}

.app-brand, .section-heading, .brand-lockup, .preview-toolbar, .toggle-row, .action-dock, .actions {
  display: flex;
  align-items: center;
}

.app-brand {
  justify-content: space-between;
  padding-bottom: 23px;
  border-bottom: 1px solid #e7eaf0;
}

.brand-lockup { gap: 10px; }
.brand-actions { display: flex; align-items: center; gap: 7px; }
.back-link { padding: 6px 9px; border: 1px solid #d8dee6; border-radius: 999px; color: #4d5b6b; background: #fff; font-size: 10px; font-weight: 800; text-decoration: none; }
.back-link:hover { border-color: #9cb0c7; color: var(--navy); }
.brand-house { width: 38px; height: 38px; fill: none; stroke: var(--gold); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.brand-name { font-size: 22px; font-weight: 850; line-height: 1; letter-spacing: -0.03em; }
.brand-subtitle { margin-top: 4px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: 0.16em; text-transform: uppercase; }
.local-badge { padding: 6px 9px; border: 1px solid #d8e4f1; border-radius: 999px; color: var(--navy); background: #f3f8fd; font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.library-button { display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 9px; border: 1px solid #d8dee6; border-radius: 999px; color: #485667; background: #fff; font-size: 10px; font-weight: 800; }
.library-button:hover { border-color: #9cb0c7; color: var(--navy); }
.library-button span { display: inline-grid; min-width: 21px; height: 21px; padding: 0 5px; place-items: center; border-radius: 999px; color: #fff; background: var(--navy); font-size: 9px; }

.editor-section { padding: 23px 0 21px; border-bottom: 1px solid #e7eaf0; }
.section-heading { justify-content: space-between; margin-bottom: 16px; }
.section-heading > div { display: flex; align-items: center; gap: 9px; }
.section-heading h2 { margin: 0; font-size: 14px; letter-spacing: -0.01em; }
.step { display: inline-grid; width: 27px; height: 27px; place-items: center; border-radius: 8px; color: var(--navy); background: #edf3fa; font-size: 10px; font-weight: 850; }
.text-button { padding: 4px 0; border: 0; color: var(--muted); background: transparent; font-size: 11px; font-weight: 700; }
.text-button:hover { color: var(--navy); }

label { display: block; margin-top: 13px; color: #536071; font-size: 11px; font-weight: 750; letter-spacing: .015em; }
.optional { margin-left: 5px; color: #9aa2ac; font-size: 9px; font-weight: 600; text-transform: uppercase; }
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 11px;
  border: 1px solid #d9dee5;
  border-radius: 8px;
  outline: none;
  color: var(--ink);
  background: #fff;
  font-size: 13px;
  font-weight: 520;
  transition: border-color .18s, box-shadow .18s;
}
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { border-color: #7393b7; box-shadow: 0 0 0 3px rgba(23, 63, 112, .09); }
.field-grid { display: grid; gap: 12px; }
.field-grid.two { grid-template-columns: 1fr 1.15fr; }
.amount-grid { grid-template-columns: 1.12fr .88fr; }
.currency-input { position: relative; }
.currency-input span { position: absolute; left: 11px; bottom: 10px; z-index: 1; color: var(--navy); font-size: 14px; font-weight: 800; }
.currency-input input { padding-left: 27px; }

.toggle-row { align-items: flex-start; gap: 10px; padding: 11px; border: 1px solid #e1e6ec; border-radius: 9px; background: #fafbfc; }
.toggle-row input { flex: 0 0 auto; width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--navy); }
.toggle-row span { display: grid; gap: 2px; }
.toggle-row strong { color: #384555; font-size: 11px; }
.toggle-row small { color: #87919d; font-size: 10px; font-weight: 500; line-height: 1.35; }

.action-dock {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 5;
  width: min(450px, 100vw);
  display: grid;
  gap: 10px;
  padding: 14px 30px 18px;
  border-top: 1px solid #dde3ea;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 -14px 30px rgba(27, 43, 63, .06);
  backdrop-filter: blur(14px);
}
.save-status { display: flex; align-items: center; gap: 7px; color: #7b8490; font-size: 10px; font-weight: 650; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(47,139,103,.12); }
.save-status.saving .status-dot { background: var(--gold); }
.actions { gap: 9px; }
.actions button { min-height: 42px; border-radius: 9px; font-size: 12px; font-weight: 800; }
.secondary-button { flex: .82; border: 1px solid #d7dde5; color: #455263; background: #fff; }
.primary-button { display: inline-flex; flex: 1.15; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--navy); color: #fff; background: var(--navy); box-shadow: 0 8px 18px rgba(23, 63, 112, .17); }
.primary-button:hover { background: var(--navy-deep); }
.print-button { display: inline-flex; flex: 0 0 58px; align-items: center; justify-content: center; gap: 5px; border: 1px solid #d7dde5; color: var(--navy); background: #fff; }
.print-button:hover, .secondary-button:hover { border-color: #9cb0c7; background: #f7f9fb; }
.print-button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.print-button span { font-size: 10px; }

.preview-panel { min-width: 0; padding: 27px clamp(30px, 4vw, 64px) 42px; overflow: auto; background: radial-gradient(circle at 80% 0%, rgba(255,255,255,.65), transparent 37%), #edf0f4; }
.preview-toolbar { justify-content: space-between; max-width: 980px; margin: 0 auto 22px; }
.eyebrow { color: var(--navy); font-size: 9px; font-weight: 850; letter-spacing: .2em; text-transform: uppercase; }
.preview-toolbar h1 { margin: 5px 0 0; color: #273341; font-size: 17px; letter-spacing: -.02em; }
.preview-meta { display: flex; align-items: center; gap: 7px; color: #75808c; font-size: 10px; font-weight: 700; }
.preview-meta span { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.canvas-wrap { display: grid; min-height: calc(100vh - 130px); place-items: center; }

.receipt-paper {
  position: relative;
  width: min(100%, 940px);
  aspect-ratio: 1.257 / 1;
  overflow: hidden;
  color: #151a20;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.receipt-accent { position: absolute; top: 0; left: 28px; width: 210px; height: 3px; background: var(--gold); }
.receipt-header { display: grid; grid-template-columns: 1fr 1.5fr 1fr; align-items: center; height: 22%; min-height: 0; padding: 0 5.5%; color: #fff; background: var(--navy); }
.receipt-brand { display: flex; align-items: center; gap: 10px; font-size: clamp(16px, 2vw, 26px); font-weight: 850; letter-spacing: -.03em; }
.receipt-brand svg { width: clamp(25px, 3vw, 39px); height: clamp(25px, 3vw, 39px); fill: none; stroke: var(--gold); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.receipt-title { text-align: center; }
.receipt-title span { color: #b8cbe2; font-size: clamp(7px, .72vw, 10px); font-weight: 750; letter-spacing: .18em; text-transform: uppercase; }
.receipt-title h2 { margin: 5px 0 0; font-size: clamp(18px, 2.15vw, 29px); letter-spacing: -.025em; }
.receipt-number-pill { justify-self: end; padding: 7px 10px; border: 1px solid rgba(255,255,255,.22); border-radius: 999px; color: #dbe7f4; font-size: clamp(9px, 1vw, 13px); font-weight: 750; }
.receipt-body { display: flex; height: 78%; min-height: 0; flex-direction: column; padding: 3.4% 5.5% 2.2%; }
.receipt-meta-grid { display: grid; grid-template-columns: 1.8fr 1fr .8fr; gap: 3%; padding-bottom: 2.2%; border-bottom: 1px solid #e0e4e9; }
.meta-item { display: grid; gap: 5px; min-width: 0; }
.meta-item span, .payment-label { color: #8a929c; font-size: clamp(7px, .78vw, 10px); font-weight: 780; letter-spacing: .11em; text-transform: uppercase; }
.meta-item strong { overflow: hidden; font-size: clamp(9px, 1.14vw, 15px); text-overflow: ellipsis; white-space: nowrap; }
.payment-card { margin-top: 2.4%; border: 1px solid #bfc5cc; }
.payment-row { display: grid; grid-template-columns: 35% 1fr; align-items: center; min-height: clamp(39px, 5vw, 56px); border-bottom: 1px solid #cbd0d6; }
.payment-row:last-child { border-bottom: 0; }
.payment-row > * { padding: 0 4%; }
.payment-label { display: flex; align-self: stretch; align-items: center; border-right: 1px solid #cbd0d6; background: #f8f9fa; }
.payment-row strong { font-size: clamp(11px, 1.45vw, 20px); font-weight: 650; line-height: 1.25; }
.payment-detail { display: grid; gap: 3px; }
.payment-detail small { color: #727c88; font-size: clamp(7px, .76vw, 10px); }
.amount-row { min-height: clamp(47px, 6vw, 68px); }
.amount-row > div { display: grid; gap: 3px; }
.amount-value { color: var(--navy); font-size: clamp(16px, 2vw, 28px) !important; font-weight: 800 !important; letter-spacing: -.025em; }
.amount-row small { color: #727c88; font-size: clamp(7px, .76vw, 10px); line-height: 1.3; }
.payment-detail small[hidden] { display: none; }
.receipt-footer { display: grid; place-items: center; margin-top: auto; padding-top: 1.5%; text-align: center; }
.verified-mark { display: grid; width: clamp(19px, 2vw, 24px); height: clamp(19px, 2vw, 24px); place-items: center; border-radius: 50%; color: #fff; background: var(--green); }
.verified-mark svg { width: 58%; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.receipt-footer p { margin: 6px 0 3px; color: #65707c; font-size: clamp(7px, .78vw, 10px); }
.receipt-footer > strong { color: var(--navy); font-size: clamp(8px, .95vw, 12px); }
.receipt-bottom-line { position: absolute; right: 5.5%; bottom: 0; left: 5.5%; height: 4px; background: linear-gradient(90deg, var(--gold) 0 23%, var(--navy) 23%); }
.preview-hint { margin: 18px 0 0; color: #87909b; text-align: center; font-size: 10px; }

.toast { position: fixed; right: 28px; bottom: 28px; z-index: 20; max-width: 320px; padding: 11px 14px; border-radius: 9px; color: #fff; background: #263547; box-shadow: 0 12px 30px rgba(20,31,43,.24); font-size: 12px; font-weight: 650; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

.library-dialog { width: min(960px, calc(100vw - 34px)); max-height: min(820px, calc(100vh - 34px)); padding: 0; border: 0; border-radius: 18px; color: var(--ink); background: #f5f7fa; box-shadow: 0 34px 90px rgba(17, 29, 44, .32); overflow: hidden; }
.library-dialog::backdrop { background: rgba(12, 25, 41, .58); backdrop-filter: blur(4px); }
.library-shell { display: grid; max-height: min(820px, calc(100vh - 34px)); grid-template-rows: auto auto auto minmax(180px, 1fr); overflow: hidden; }
.library-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 25px 28px 20px; color: #fff; background: var(--navy); }
.library-header .eyebrow { color: #b8cbe2; }
.library-header h2 { margin: 5px 0 4px; font-size: 25px; letter-spacing: -.03em; }
.library-header p { margin: 0; color: #c9d7e7; font-size: 11px; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid rgba(255,255,255,.25); border-radius: 50%; color: #fff; background: rgba(255,255,255,.08); font-size: 22px; line-height: 1; }
.library-tools { display: flex; align-items: center; gap: 13px; padding: 16px 22px; border-bottom: 1px solid #e0e5eb; background: #fff; }
.search-box { position: relative; flex: 1; margin: 0; }
.search-box svg { position: absolute; top: 50%; left: 12px; z-index: 1; width: 16px; height: 16px; fill: none; stroke: #7c8793; stroke-width: 1.8; transform: translateY(-50%); }
.search-box input { margin: 0; padding-left: 38px; background: #f8fafc; }
.backup-actions { display: flex; gap: 7px; }
.backup-actions button { min-height: 36px; padding: 0 11px; border: 1px solid #d8dee6; border-radius: 8px; color: #4c5969; background: #fff; font-size: 10px; font-weight: 800; }
.backup-actions button:hover { border-color: #98aac0; color: var(--navy); }
.library-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; border-bottom: 1px solid #e1e6eb; background: #e1e6eb; }
.library-summary div { display: grid; gap: 3px; padding: 12px 22px; background: #f8fafc; }
.library-summary span { color: #84909d; font-size: 8px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.library-summary strong { color: #29384a; font-size: 15px; }
.receipt-list { display: grid; align-content: start; gap: 9px; padding: 16px 18px 24px; overflow: auto; }
.saved-receipt-card { display: grid; grid-template-columns: 80px minmax(150px, 1.7fr) minmax(105px, 1fr) minmax(95px, .8fr) auto; align-items: center; gap: 14px; padding: 13px 14px; border: 1px solid #e0e5ea; border-radius: 11px; background: #fff; box-shadow: 0 5px 16px rgba(23,42,66,.035); }
.saved-receipt-card:hover { border-color: #bfcbd8; box-shadow: 0 8px 22px rgba(23,42,66,.07); }
.saved-number span, .saved-detail span { display: block; margin-bottom: 3px; color: #929ba6; font-size: 8px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.saved-number strong { color: var(--navy); font-size: 16px; }
.saved-detail { min-width: 0; }
.saved-detail strong { display: block; overflow: hidden; color: #263344; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.saved-detail small { display: block; margin-top: 3px; overflow: hidden; color: #7c8793; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.saved-amount { color: var(--navy) !important; font-size: 13px !important; }
.card-actions { display: flex; gap: 5px; }
.card-actions button { min-height: 31px; padding: 0 9px; border: 1px solid #dde2e8; border-radius: 7px; color: #5d6875; background: #fff; font-size: 9px; font-weight: 800; }
.card-actions button:hover { border-color: #aab9c9; color: var(--navy); background: #f7f9fb; }
.card-actions .open-action { color: #fff; border-color: var(--navy); background: var(--navy); }
.card-actions .delete-action:hover { border-color: #e4b5b5; color: #a63737; background: #fff7f7; }
.empty-library { display: grid; place-items: center; align-content: center; min-height: 260px; padding: 34px; text-align: center; }
.empty-icon { display: grid; width: 48px; height: 48px; place-items: center; border-radius: 14px; color: var(--navy); background: #e5edf6; font-weight: 900; }
.empty-library h3 { margin: 12px 0 4px; font-size: 15px; }
.empty-library p { margin: 0; color: #84909d; font-size: 11px; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 390px minmax(600px, 1fr); }
  .editor-panel { padding-inline: 24px; }
  .action-dock { width: 390px; padding-inline: 24px; }
  .preview-panel { padding-inline: 28px; }
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .editor-panel { padding-bottom: 24px; }
  .action-dock { position: sticky; width: auto; margin: 22px -24px -24px; }
  .preview-panel { min-height: 720px; }
  .canvas-wrap { min-height: auto; }
  .library-tools { align-items: stretch; flex-direction: column; }
  .backup-actions button { flex: 1; }
  .saved-receipt-card { grid-template-columns: 70px 1fr 1fr; }
  .saved-receipt-card .saved-method { display: none; }
  .card-actions { grid-column: 1 / -1; }
}

@media print {
  @page { size: 131mm 104mm; margin: 0; }
  html, body { width: 131mm; height: 104mm; background: #fff; }
  .editor-panel, .preview-toolbar, .preview-hint, .toast, .library-dialog { display: none !important; }
  .app-shell, .preview-panel, .canvas-wrap { display: block; width: 131mm; min-height: 0; height: 104mm; margin: 0; padding: 0; overflow: hidden; background: #fff; }
  .receipt-paper { width: 131mm; height: 104mm; aspect-ratio: auto; box-shadow: none; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
