/*
 * Form Engineering Layer — v6.20
 * Final layout pass for consistent field rhythm, Jalali controls and barcode blocks.
 */

:root{
  --field-control-height:38px;
  --field-label-height:17px;
  --field-help-height:14px;
}

/* One predictable box model across every module. */
.form-grid,.filter-bar,.export-filter-grid,.report-period-filter{align-items:start}
.form-grid>.field,.filter-bar>*,.export-filter-grid>*,.report-period-filter>*{min-width:0}
.field{display:flex;flex-direction:column;min-width:0}
.field>label,.export-filter-grid label>span,.report-period-filter label{
  min-height:var(--field-label-height);
  display:flex;
  align-items:flex-end;
  line-height:1.25;
}
.field input:not([type="checkbox"]):not([type="radio"]),
.field select,
.filter-bar input:not([type="checkbox"]):not([type="radio"]),
.filter-bar select,
.export-filter-grid input:not([type="checkbox"]):not([type="radio"]),
.export-filter-grid select,
.report-period-filter input:not([type="checkbox"]):not([type="radio"]),
.report-period-filter select{
  min-height:var(--field-control-height);
  height:var(--field-control-height);
  line-height:1.25;
}
.field textarea{line-height:1.65}
.field small,.field .date-help,.field [data-date-help]{display:block;min-height:var(--field-help-height);line-height:1.4}
.field input,.field select,.field textarea,.filter-bar input,.filter-bar select{min-width:0}

/* Jalali widgets now behave exactly like a standard input everywhere. */
.jalali-field{width:100%;min-width:0;height:var(--field-control-height)}
.jalali-field>input[data-jalali-input]{height:100%;min-height:100%;width:100%;font-variant-numeric:tabular-nums}
.jalali-field>button{height:auto;min-height:0}
.jalali-field .input-invalid{border-color:#ef4444!important;box-shadow:0 0 0 3px rgba(239,68,68,.1)!important}
.error-text{color:#b91c1c!important}

/* Receipt editor: equal-height rows and stable field baselines. */
.receipt-editor-grid{align-items:stretch!important}
.receipt-editor-grid>.receipt-compact-panel{height:100%;margin-bottom:0!important;display:flex;flex-direction:column}
.receipt-editor-grid>.receipt-compact-panel>.form-grid,
.receipt-editor-grid>.receipt-compact-panel>.checkbox-field,
.receipt-editor-grid>.receipt-compact-panel>.modern-details{width:100%}
.compact-three-cols>.field:not(.full){display:grid;grid-template-rows:var(--field-label-height) var(--field-control-height) var(--field-help-height);align-content:start}
.compact-three-cols>.field:not(.full)>label{margin:0 0 3px}
.compact-three-cols>.field:not(.full)>input,
.compact-three-cols>.field:not(.full)>select,
.compact-three-cols>.field:not(.full)>.jalali-field{align-self:start}
.compact-three-cols>.field:not(.full)>small,
.compact-three-cols>.field:not(.full)>[data-date-help]{margin:2px 0 0!important;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.receipt-compact-panel .jalali-field{height:35px}
.receipt-compact-panel .compact-three-cols>.field:not(.full){grid-template-rows:15px 35px 13px}
.receipt-compact-panel .compact-three-cols>.field:not(.full)>input,
.receipt-compact-panel .compact-three-cols>.field:not(.full)>select{height:35px;min-height:35px}
.receipt-compact-panel .model-field small{display:block}

/* Automatic barcode identity block. */
.receipt-control-identity{display:grid!important;grid-template-columns:minmax(118px,.72fr) minmax(180px,1.28fr);align-items:center;gap:10px;min-width:0}
.receipt-identity-copy{min-width:0}
.receipt-identity-copy b{display:block;font-size:21px;line-height:1.1;color:#0b4f82;font-variant-numeric:tabular-nums}
.receipt-identity-copy small{display:block;margin-top:4px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.receipt-auto-barcode{min-width:0;padding:6px 8px;border:1px solid #d6e4f1;border-radius:11px;background:#fff;text-align:center;overflow:hidden}
.receipt-auto-barcode span{display:block;margin-top:2px;font-size:8px;font-weight:800;color:#64809a;letter-spacing:.1px}
.barcode-svg{display:block;width:100%;height:auto;max-height:42px;shape-rendering:crispEdges}
.receipt-print-barcode{width:190px;max-width:100%;margin:7px 0 0 auto;padding:5px 7px;border:1px solid #d7dde5;border-radius:8px;background:#fff}
.receipt-print-barcode .barcode-svg{max-height:48px}

/* Filters made from date widgets need a useful width and label alignment. */
.accounting-filter-wide .jalali-filter-field{min-width:150px}
.jalali-filter-field{display:flex;flex-direction:column;gap:4px;min-width:140px}
.jalali-filter-field>label{font-size:10px;font-weight:800;color:#64748b;min-height:14px}
.report-period-filter .jalali-filter-field,.export-filter-grid .jalali-filter-field{width:100%}
.report-period-filter .jalali-field,.export-filter-grid .jalali-field{height:40px}

/* Inventory barcode presentation. */
.inventory-code-cell{display:flex;flex-direction:column;gap:3px}
.inventory-code-cell small{direction:ltr;text-align:right;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;color:#60748a}
.inventory-barcode-preview{margin-top:6px;padding:8px;border:1px dashed #c8d9e8;border-radius:10px;background:#f8fbfe}
.inventory-barcode-preview .barcode-svg{max-height:38px}

/* Manager control panel — warnings without visual noise. */
.accounting-control-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
.accounting-control-card{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:10px;border:1px solid #e0e9f2;border-radius:12px;background:#fbfdff;color:inherit}
.accounting-control-card:hover{border-color:#a9c8e2;background:#f4f9fd}
.accounting-control-card div{min-width:0}
.accounting-control-card b{display:block;font-size:11px}
.accounting-control-card small{display:block;margin-top:2px;font-size:9px;color:#7a8da0}
.accounting-control-card strong{font-size:16px;color:#164f7a;white-space:nowrap}
.accounting-control-card.warn{border-color:#f5d0a9;background:#fffaf4}
.accounting-control-card.danger{border-color:#fecaca;background:#fff7f7}
.accounting-control-card.ok{border-color:#bbecd8;background:#f6fffb}
.accounting-control-card.warn strong{color:#a65d0a}.accounting-control-card.danger strong{color:#b42318}.accounting-control-card.ok strong{color:#087a59}

@media(max-width:1200px){
  .receipt-control-identity{grid-template-columns:minmax(135px,.75fr) minmax(210px,1.25fr)}
}
@media(max-width:700px){
  :root{--field-control-height:42px}
  .receipt-control-identity{grid-template-columns:1fr!important;text-align:center}
  .receipt-identity-copy small{white-space:normal}
  .receipt-auto-barcode{width:100%;max-width:300px;margin:auto}
  .compact-three-cols>.field:not(.full),
  .receipt-compact-panel .compact-three-cols>.field:not(.full){display:flex;grid-template-rows:none}
  .compact-three-cols>.field:not(.full)>small,
  .compact-three-cols>.field:not(.full)>[data-date-help]{white-space:normal;overflow:visible}
  .accounting-control-grid{grid-template-columns:1fr}
  .accounting-filter-wide .jalali-filter-field{min-width:0;width:100%}
}

@media print{
  .receipt-print-barcode{border:0;padding:0;width:190px}
  .receipt-print-barcode .barcode-svg{max-height:42px}
  .receipt-auto-barcode{border:0}
}

.export-filter-actions{display:flex;align-items:end;gap:7px;grid-column:1/-1;justify-content:flex-end}
.export-filter-actions .btn{min-width:110px}
@media(max-width:480px){.export-filter-actions{display:grid;grid-template-columns:1fr 1fr}.export-filter-actions .btn{width:100%;min-width:0}}

.accounting-alert-panel .accounting-control-card{display:flex;grid-template-columns:none;padding:10px;border:1px solid #e0e9f2}
.accounting-alert-panel .accounting-control-card small{grid-column:auto}
