:root{
  --green:#075f24;
  --green-dark:#05451b;
  --paper:#ffffff;
  --bg:#f2f5f2;
  --line:#0b5f28;
  --muted:#68756b;
  --border:#d9e2da;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{
  margin:0;
  font-family:Arial, Helvetica, sans-serif;
  background:var(--bg);
  color:#172019;
  overflow-x:hidden;
}
button,input,textarea{font:inherit}
.app-shell{max-width:1320px;margin:0 auto;padding:22px}
.app-head{
  display:flex;align-items:center;justify-content:space-between;gap:16px;
  margin-bottom:18px;
}
.app-head h1{font-size:24px;margin:0;color:var(--green-dark);line-height:1.2}
.app-head p{margin:4px 0 0;color:var(--muted);font-size:14px}
.mode-badge{
  white-space:nowrap;background:#e7f2e9;border:1px solid #c9decf;color:var(--green-dark);
  border-radius:999px;padding:8px 12px;font-size:13px;font-weight:700
}
.workspace{display:grid;grid-template-columns:minmax(300px,390px) minmax(0,1fr);gap:22px;align-items:start}
.panel{
  min-width:0;background:#fff;border:1px solid var(--border);border-radius:14px;padding:18px;
  box-shadow:0 8px 26px rgba(0,0,0,.05)
}
.panel h2{font-size:17px;margin:0 0 15px;color:var(--green-dark)}
.field{margin-bottom:12px}
.field label{display:block;font-size:13px;font-weight:700;margin-bottom:6px;color:#334138}
.field input,.field textarea{
  width:100%;border:1px solid #cfd9d1;border-radius:9px;padding:11px 12px;font-size:16px;
  outline:none;background:#fff;min-height:44px
}
.field input:focus,.field textarea:focus{border-color:#4d9565;box-shadow:0 0 0 3px rgba(77,149,101,.12)}
.field textarea{min-height:78px;resize:vertical}
.row-2{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.readonly{background:#f4f7f4!important;color:#36483b;font-weight:700}
.actions{display:grid;grid-template-columns:1fr 1fr;gap:9px;margin-top:16px}
.btn{
  min-height:44px;border:0;border-radius:9px;padding:11px 12px;font-size:14px;font-weight:700;
  cursor:pointer;touch-action:manipulation
}
.btn-primary{background:var(--green);color:#fff}
.btn-primary:hover{background:var(--green-dark)}
.btn-outline{background:#fff;border:1px solid #b7c7ba;color:var(--green-dark)}
.btn-soft{background:#eef4ef;color:#23442d}
.status{margin-top:12px;font-size:13px;min-height:18px;color:#4b5a4e}

/* Screen preview keeps the exact A5 receipt proportions but scales to any screen. */
.preview-wrap{
  width:100%;display:flex;justify-content:center;align-items:flex-start;overflow:hidden;padding:4px;
}
.receipt-stage{
  width:148mm;height:210mm;position:relative;flex:0 0 auto;
}
.receipt{
  width:148mm;min-height:210mm;background:var(--paper);border:1.8mm solid var(--green);
  padding:5mm 5.5mm 5mm;color:var(--green-dark);position:absolute;left:0;top:0;
  transform-origin:top left;box-shadow:0 8px 28px rgba(0,0,0,.10)
}
.receipt-header{text-align:center}
.receipt-header img{display:block;width:100%;height:48mm;object-fit:cover;object-position:center top;margin:0 auto 1mm}
.receipt-meta{display:grid;grid-template-columns:1fr 1fr;align-items:end;gap:10mm;margin:1mm 1mm 4mm;font-size:5.1mm}
.meta-item{display:flex;align-items:flex-end;gap:2mm;white-space:nowrap}
.meta-item.right{justify-content:flex-end}
.meta-value{
  display:inline-block;min-width:23mm;border-bottom:.55mm dashed var(--line);text-align:center;
  padding:0 1mm 1mm;font-weight:700;line-height:1.05
}
.title{text-align:center;margin:2mm 0 0;font-weight:800;font-size:6.1mm;line-height:1.26}
.subtitle{text-align:center;font-weight:700;font-size:4.45mm;line-height:1.2;margin:1.7mm 0 7mm}
.receipt-lines{font-size:4.35mm;font-weight:700}
.line-row{display:flex;align-items:flex-end;gap:2mm;margin-bottom:7.2mm;min-height:8mm}
.line-row.compact{gap:1.4mm}
.label{white-space:nowrap}
.fill{
  min-width:0;flex:1;border-bottom:.5mm dashed var(--line);padding:0 1.2mm 1.1mm;
  font-weight:700;overflow-wrap:anywhere;min-height:6mm
}
.fill.short{flex:0 0 24mm}
.fill.xshort{flex:0 0 14mm}
.fill.medium{flex:0 0 31mm}
.address-block{margin:0 0 7.5mm}
.address-first{display:flex;align-items:flex-end;gap:2mm}
.address-second{border-bottom:.5mm dashed var(--line);min-height:11mm;padding:2mm 1mm 1.1mm;overflow-wrap:anywhere}
.bottom-row{display:grid;grid-template-columns:1fr auto;gap:8mm;align-items:end;margin-top:1mm;margin-bottom:8mm}
.bottom-left{display:flex;align-items:flex-end;gap:2mm}
.received{font-size:4.5mm;font-weight:800;padding-bottom:1mm}
.signature-row{display:grid;grid-template-columns:1.55fr .9fr;gap:8mm;align-items:end}
.signature-item{display:flex;align-items:flex-end;gap:2mm}
.preview-caption{text-align:center;color:#708076;font-size:12px;margin-top:10px;line-height:1.45}
.history-modal{display:none;position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:20;padding:22px;overflow:auto}
.history-modal.open{display:block}
.history-card{max-width:980px;margin:40px auto;background:#fff;border-radius:14px;padding:18px}
.history-head{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-bottom:12px}
.history-head h3{margin:0;color:var(--green-dark)}
.history-table-wrap{overflow:auto;-webkit-overflow-scrolling:touch}
table{width:100%;border-collapse:collapse;font-size:13px}
th,td{padding:9px;border-bottom:1px solid #e4e9e4;text-align:left;white-space:nowrap}
th{background:#f4f7f4;color:#2f4133}
.icon-close{min-height:40px;border:0;background:#eef3ef;border-radius:8px;padding:8px 11px;cursor:pointer;font-weight:700}

@media(max-width:1040px){
  .workspace{grid-template-columns:1fr}
  .panel.form-panel{max-width:760px;margin:0 auto;width:100%}
  .panel.preview-panel{max-width:760px;margin:0 auto;width:100%}
}
@media(max-width:700px){
  .app-shell{padding:12px}
  .app-head{align-items:flex-start;flex-direction:column;margin-bottom:12px}
  .app-head h1{font-size:20px}
  .app-head p{font-size:13px}
  .mode-badge{font-size:12px;padding:7px 10px}
  .panel{padding:13px;border-radius:12px}
  .row-2{grid-template-columns:1fr}
  .actions{grid-template-columns:1fr}
  .btn{min-height:48px;font-size:15px}
  .preview-wrap{padding:0}
  .preview-caption{font-size:11px}
  .history-modal{padding:10px}
  .history-card{margin:14px auto;padding:12px;border-radius:12px}
}
@media(max-width:420px){
  .app-shell{padding:8px}
  .panel{padding:11px}
  .app-head h1{font-size:18px}
}

@media print{
  @page{size:A5 portrait;margin:0}
  html,body{width:148mm;height:210mm;background:#fff;overflow:visible}
  .app-head,.form-panel,.preview-caption,.history-modal{display:none!important}
  .app-shell{max-width:none;margin:0;padding:0}
  .workspace{display:block}
  .panel.preview-panel{border:0;box-shadow:none;border-radius:0;padding:0;margin:0;max-width:none}
  .preview-wrap{display:block;padding:0;margin:0;overflow:visible;width:148mm;height:210mm}
  .receipt-stage{width:148mm!important;height:210mm!important}
  .receipt{
    position:relative!important;left:auto;top:auto;transform:none!important;box-shadow:none;margin:0;
    width:148mm;min-height:210mm;page-break-inside:avoid
  }
}

/* Compact form UI. Receipt design below/alongside remains unchanged. */
.compact-ui{padding-top:14px}
.compact-head{margin-bottom:12px}
.compact-head h1{font-size:21px}
.compact-form-panel{padding:14px}
.compact-form-panel .field{margin-bottom:8px}
.compact-form-panel .field label{margin-bottom:4px;font-size:12px}
.compact-form-panel .field input,
.compact-form-panel .field textarea{min-height:40px;padding:8px 10px;font-size:15px}
.compact-form-panel .field textarea{min-height:54px}
.compact-actions{margin-top:10px;gap:7px}
.compact-actions .btn{min-height:42px;padding:8px 10px;font-size:13px}

@media(max-width:700px){
  .compact-head{flex-direction:row;align-items:center}
  .compact-head h1{font-size:18px}
  .compact-head .mode-badge{font-size:10px;padding:5px 8px}
  .compact-form-panel{padding:11px}
  .compact-form-panel .row-2{grid-template-columns:1fr 1fr}
  .compact-actions{grid-template-columns:1fr 1fr}
}
@media(max-width:430px){
  .compact-head{gap:8px}
  .compact-head .mode-badge{max-width:150px;overflow:hidden;text-overflow:ellipsis}
  .compact-form-panel .row-2{grid-template-columns:1fr 1fr;gap:7px}
  .compact-form-panel .field input,
  .compact-form-panel .field textarea{font-size:14px}
}
