:root {
  --color-primary: #d97706;
  --color-primary-dark: #b45309;
  --color-danger: #c0392b;
  --border: #e2e2e2;
  --text-muted: #6b7280;
  --bg: #f7f7f5;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: #1f2937; }

/* --- Login / setup --- */
#loginScreen { display: none; position: fixed; inset: 0; background: #1f2937; align-items: center; justify-content: center; z-index: 1000; }
#loginScreen.show { display: flex; }
.auth-box { background: #fff; padding: 32px 36px; border-radius: 10px; width: 320px; }
.auth-box h1 { margin: 0 0 2px; font-size: 22px; }
.auth-subtitle { margin: 0 0 20px; color: var(--text-muted); font-size: 13px; }
.auth-hint { font-size: 12px; color: var(--text-muted); }
.auth-form-hidden { display: none !important; }
.auth-box form { display: flex; flex-direction: column; }
.auth-box label { font-size: 12px; color: var(--text-muted); margin: 8px 0 3px; }
.auth-box input { padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.auth-box button { margin-top: 16px; padding: 10px; border: none; border-radius: 6px; background: var(--color-primary); color: #fff; font-size: 14px; cursor: pointer; }
.auth-box button:hover { background: var(--color-primary-dark); }

/* --- App shell --- */
.app-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--border); }
.app-header h1 { font-size: 18px; margin: 0; }
.header-right { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.role-badge { background: #eee; padding: 2px 8px; border-radius: 10px; text-transform: capitalize; font-size: 11px; }
.btn-secondary, .btn-primary { border: none; border-radius: 6px; padding: 7px 14px; font-size: 13px; cursor: pointer; }
.btn-secondary { background: #eee; color: #333; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }

.tab-bar { display: flex; gap: 4px; padding: 0 20px; background: #fff; border-bottom: 1px solid var(--border); }
.tab-btn { border: none; background: none; padding: 12px 16px; font-size: 13px; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--color-primary-dark); border-bottom-color: var(--color-primary); font-weight: 600; }

.tab-content-area { padding: 18px 20px; }
.tab-content { display: none; }
.tab-content.active { display: block; }
.coming-soon { color: var(--text-muted); padding: 40px; text-align: center; font-size: 14px; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.toolbar label { font-size: 13px; color: var(--text-muted); }
.toolbar input[type="date"] { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }

.settings-box { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 18px 20px; max-width: 420px; margin-bottom: 24px; }
.settings-box label { display: block; font-size: 12px; color: var(--text-muted); margin: 12px 0 4px; }
.settings-box label:first-child { margin-top: 0; }
.settings-box input[type="text"] { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; box-sizing: border-box; }
.settings-box button { margin-top: 16px; }

#entryGridContainer, #reconGridContainer { background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }

/* Let column header text wrap onto 2 lines instead of being clipped, so a
   narrowed column still shows its full title rather than overlapping the
   next one — Tabulator sets fixed pixel heights inline, hence !important. */
.tabulator .tabulator-header,
.tabulator .tabulator-header .tabulator-col,
.tabulator .tabulator-header .tabulator-col-content {
  height: auto !important;
  min-height: 44px;
}
.tabulator .tabulator-header .tabulator-col-title {
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
  line-height: 1.25;
}

.push-status-label { font-size: 12px; color: var(--text-muted); }
.section-heading { font-size: 14px; margin: 22px 0 10px; color: #374151; }

.summary-table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; font-size: 13px; }
.summary-table th, .summary-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.summary-table th { background: #f3f4f6; font-weight: 600; color: #374151; }
.summary-table td.num, .summary-table th:nth-child(n+3) { text-align: right; }

.badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.badge-vouchered { background: #d1fae5; color: #065f46; }
.badge-pending { background: #f3f4f6; color: #6b7280; }

/* --- Add Grain/Variety modal --- */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); align-items: center; justify-content: center; z-index: 1500; }
.modal-overlay.show { display: flex; }
.modal-box { background: #fff; border-radius: 10px; padding: 24px 26px; width: 340px; }
.modal-box h3 { margin: 0 0 14px; font-size: 16px; }
.modal-box label { display: block; font-size: 12px; color: var(--text-muted); margin: 12px 0 4px; }
.modal-box select, .modal-box input[type="text"], .modal-box input[type="number"] { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; box-sizing: border-box; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-box-wide { width: 480px; max-height: 88vh; overflow-y: auto; }
.error-box { background: #fef2f2; color: var(--color-danger); border: 1px solid #fecaca; border-radius: 6px; padding: 8px 10px; font-size: 12px; margin-top: 14px; }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 120px; overflow-y: auto; padding: 8px; background: #f7f7f5; border: 1px solid var(--border); border-radius: 6px; }
.chip { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 3px 10px; font-size: 12px; color: #374151; }
.chip-empty { color: var(--text-muted); font-style: italic; border-style: dashed; }

.hr-list { max-height: 280px; overflow-y: auto; margin-top: 8px; }
.hr-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.hr-grain { font-size: 13px; }
.hr-rate-input { width: 90px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; text-align: right; }

/* --- Vouchers tab --- */
.farmer-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.farmer-card-header { margin-bottom: 8px; font-size: 14px; }
.farmer-lots-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 10px; }
.farmer-lots-table th, .farmer-lots-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.farmer-lots-table td.num, .farmer-lots-table th:nth-child(n+4) { text-align: right; }

.voucher-summary-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.voucher-summary-highlight { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; font-size: 14px; }
.denom-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 6px; }
.denom-cell { text-align: center; font-size: 12px; }
.denom-cell input { width: 100%; margin-top: 3px; padding: 5px; border: 1px solid var(--border); border-radius: 6px; text-align: center; }

/* --- Voucher print page (two copies stacked on one page: firm + farmer) --- */
.print-modal-box { background: #fff; border-radius: 10px; padding: 20px; width: 720px; max-height: 92vh; overflow-y: auto; }
.print-modal-toolbar { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 14px; }
.voucher-copy { font-family: 'Noto Sans Devanagari', system-ui, sans-serif; border: 1px solid #333; padding: 14px; }
.voucher-copy-label { text-align: right; font-size: 10px; color: #666; margin-bottom: 2px; }
.voucher-copy-separator { border-top: 1px dashed #999; margin: 14px 0; }
.voucher-header { display: flex; justify-content: space-between; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.voucher-title { text-align: center; font-weight: 700; font-size: 15px; margin-bottom: 8px; }
.voucher-meta { font-size: 12px; margin-bottom: 8px; line-height: 1.5; }
.voucher-table { width: 100%; border-collapse: collapse; font-size: 11px; margin-bottom: 8px; }
.voucher-table th, .voucher-table td { border: 1px solid #333; padding: 4px 5px; text-align: center; }
.voucher-total-row { font-weight: 700; }
.voucher-settle { font-size: 12px; line-height: 1.6; margin-bottom: 8px; }
.voucher-net-paid { font-size: 13px; font-weight: 700; }
.voucher-denom { margin-bottom: 10px; }
.denom-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.denom-table th, .denom-table td { border: 1px solid #333; padding: 4px; text-align: center; }
.voucher-signatures { display: flex; justify-content: space-between; margin-top: 22px; font-size: 12px; padding-top: 8px; border-top: 1px dashed #999; }

@media print {
  @page { size: A4; margin: 12mm; }
  body * { visibility: hidden; }
  #voucherPrintModal, #voucherPrintModal * { visibility: visible; }
  #voucherPrintModal {
    position: absolute; inset: 0; background: #fff;
    /* .modal-overlay.show normally centers its child via flex, which was
       shrinking the voucher to its natural content size instead of letting
       it fill the page — override to a plain block so it stretches. */
    display: block !important;
  }
  .print-modal-box { width: 100%; max-height: none; overflow: visible; padding: 0; }
  .no-print { display: none !important; }

  /* Fill the page width (fixed above) without bumping sizes so much that
     both copies no longer fit on one A4 page together. */
  .voucher-copy { padding: 16px; }
  .voucher-copy-label { font-size: 11px; }
  .voucher-header { font-size: 14px; }
  .voucher-title { font-size: 17px; margin-bottom: 10px; }
  .voucher-meta { font-size: 13px; margin-bottom: 10px; line-height: 1.6; }
  .voucher-table { font-size: 12px; margin-bottom: 10px; }
  .voucher-table th, .voucher-table td { padding: 6px 7px; }
  .voucher-settle { font-size: 13px; line-height: 1.7; margin-bottom: 10px; }
  .voucher-net-paid { font-size: 15px; }
  .voucher-denom { margin-bottom: 10px; }
  .denom-table { font-size: 12px; }
  .denom-table th, .denom-table td { padding: 5px; }
  .voucher-signatures { font-size: 13px; margin-top: 28px; padding-top: 10px; }
  .voucher-copy-separator { margin: 16px 0; }
}

/* --- Toasts --- */
#toastContainer { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 6px; font-size: 13px; opacity: 0; transform: translateY(8px); transition: all .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--color-danger); }
.toast-info { background: #1f2937; }

[data-min-role="admin"] { }
body[data-role="staff"] [data-min-role="admin"] { display: none !important; }
