:root {
  --bg: #eef2f6;
  --card: #fff;
  --text: #1a2332;
  --muted: #5c6b7a;
  --border: #d8dee6;
  --primary: #3f7047;
  --primary-dark: #24482e;
  --primary-soft: #f1f7f0;
  --danger: #c62828;
  --success: #2e7d32;
  --warn: #ef6c00;
  --radius: 14px;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.07);
  --section-gap: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

body {
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  margin: 0;
  font-size: 1.15rem;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.banner-warn {
  background: #fff3cd;
  color: #664d03;
  border-bottom: 1px solid #ffc107;
  padding: 10px 16px;
  text-align: center;
  font-size: 0.9rem;
}

.nav-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-links a {
  padding: 6px 12px;
  border-radius: 8px;
  background: #eef3fa;
  font-size: 0.9rem;
}

.nav-links a.active {
  background: var(--primary);
  color: #fff;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 14px 88px;
}

/* ── Form flow ── */
.form-flow {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
}

.form-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.section-primary {
  border-color: #a9c1ae;
  background: linear-gradient(180deg, #f8fbff 0%, #fff 100%);
}

.section-optional {
  background: #fafbfc;
  border-style: dashed;
}

.section-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 1rem;
}

.section-desc {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.step-badge {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-badge.step-optional {
  background: #90a4ae;
  font-size: 0.75rem;
}

.field-label {
  font-size: 0.86rem;
  color: var(--muted);
  font-weight: 600;
}

.field-hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.field-hint.warn { color: var(--warn); }
.field-hint.ok { color: var(--success); }

.input-ltr { text-align: left; direction: ltr; }

/* chips */
.chip-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 6px;
}

.chip {
  position: relative;
  display: block;
  cursor: pointer;
}

.chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chip span {
  display: block;
  text-align: center;
  padding: 12px 6px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.9rem;
  background: #fff;
  transition: border-color 0.15s, background 0.15s;
}

.chip input:checked + span {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.chip-debtor input:checked + span { border-color: #c62828; background: #ffebee; color: #b71c1c; }
.chip-creditor input:checked + span { border-color: #2e7d32; background: #e8f5e9; color: #1b5e20; }

/* date segments */
.segment-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.segment {
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.segment.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.date-field-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.date-field-wrap input {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  text-align: center;
  background: #fff;
}

/* jalali picker */
.pdp-popup {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 8px 28px rgba(0,0,0,0.12);
}

.pdp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pdp-title-row { display: flex; flex: 1; gap: 8px; }
.pdp-select {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
}
.pdp-nav {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}
.pdp-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.pdp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.pdp-empty { aspect-ratio: 1; }
.pdp-day {
  aspect-ratio: 1;
  border: none;
  border-radius: 8px;
  background: #f5f7fa;
  font: inherit;
  cursor: pointer;
}
.pdp-day.is-active { background: var(--primary); color: #fff; font-weight: 700; }
.pdp-foot { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }

.form-footer {
  position: static;
  padding: 12px 0 8px;
  background: transparent;
  margin-top: 8px;
}

.btn-submit {
  font-size: 1.05rem;
  padding: 14px;
  box-shadow: 0 4px 14px rgba(21, 101, 192, 0.35);
}

.btn-photo {
  flex: 1;
  padding: 14px 10px;
  font-size: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field span,
.field .field-label {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 600;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.field textarea { min-height: 88px; resize: vertical; }

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.radio-option {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.radio-option:has(input:checked) {
  border-color: var(--primary);
  background: #f1f7f0;
}

.radio-option input { margin-top: 4px; }

.radio-option strong { display: block; }
.radio-option small { color: var(--muted); }

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-lite {
  background: #eef3fa;
  color: var(--text);
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.preview-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1;
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-item button {
  position: absolute;
  top: 4px;
  left: 4px;
  border: none;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
}

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}

.toast.show { opacity: 1; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.hint { font-size: 0.85rem; color: var(--muted); margin: 0 0 12px; }

.suggest-wrap { position: relative; }

.suggest-box {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 180px;
  overflow: auto;
}

.suggest-box button {
  display: block;
  width: 100%;
  text-align: right;
  border: none;
  background: transparent;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  border-bottom: 1px solid #eef2f6;
}

.suggest-box button:hover,
.suggest-box button:focus {
  background: #f1f7f0;
}

.photo-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.photo-actions .btn { width: auto; flex: 1; }
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

@media (max-width: 520px) {
  .filters { grid-template-columns: 1fr; }
}

.doc-grid {
  display: grid;
  gap: 12px;
}

.doc-card {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 12px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.doc-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }

.doc-thumb {
  width: 88px;
  height: 88px;
  border-radius: 8px;
  object-fit: cover;
  background: #e8edf2;
}

.doc-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--muted);
}

.doc-meta { font-size: 0.85rem; color: var(--muted); }
.doc-title { font-weight: 700; margin-bottom: 4px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-debtor { background: #ffebee; color: #b71c1c; }
.badge-creditor { background: #e8f5e9; color: #1b5e20; }
.badge-neutral { background: #eceff1; color: #455a64; }
.badge-void { background: #fff3e0; color: #e65100; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
}

/* detail modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal[hidden] { display: none; }

.modal-box {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow: auto;
  padding: 16px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.detail-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.detail-images img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* database admin */
.db-app { background: #0f1419; color: #e6edf3; min-height: 100vh; }
.db-banner {
  padding: 8px 12px;
  font-size: 0.85rem;
  text-align: center;
}
.db-banner-warn { background: #5c4b00; }
.db-banner-danger { background: #5c1a1a; }
.db-layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 40px); }
@media (max-width: 768px) { .db-layout { grid-template-columns: 1fr; } }
.db-sidebar { background: #161b22; border-left: 1px solid #30363d; padding: 12px; }
.db-main { padding: 12px; overflow: auto; }
.db-table-list button {
  display: block; width: 100%; text-align: right; margin-bottom: 4px;
  background: transparent; border: 1px solid #30363d; color: inherit;
  padding: 8px; border-radius: 6px; cursor: pointer;
}
.db-table-list button.active { background: #3f7047; border-color: #3f7047; }
.db-btn { border: 1px solid #30363d; background: #21262d; color: inherit; padding: 6px 10px; border-radius: 6px; cursor: pointer; margin-left: 4px; }
.db-btn-primary { background: #238636; border-color: #238636; }
.db-grid-wrap { overflow: auto; margin-top: 12px; }
.db-grid { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.db-grid th, .db-grid td { border: 1px solid #30363d; padding: 6px 8px; text-align: right; }
.db-grid th { background: #21262d; position: sticky; top: 0; }
.db-muted { color: #8b949e; font-size: 0.85rem; }
.db-audit-list { max-height: 240px; overflow: auto; font-size: 0.78rem; }
.db-audit-item { border-bottom: 1px solid #30363d; padding: 8px 0; }

/* ============ حسابداری پرسنل ============ */
.nav-links { display: flex; gap: 14px; }
.nav-links a { color: #fff; text-decoration: none; opacity: 0.85; font-size: 0.95rem; }
.nav-links a.active, .nav-links a:hover { opacity: 1; text-decoration: underline; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .search { flex: 1; min-width: 180px; }

.chips { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; box-shadow: var(--shadow); min-width: 120px; }
.chip .chip-label { color: var(--muted); font-size: 0.78rem; }
.chip .chip-value { font-size: 1.15rem; font-weight: 700; margin-top: 2px; }

.data-table { width: 100%; border-collapse: collapse; background: var(--card);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.data-table th, .data-table td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--border);
  font-size: 0.9rem; white-space: nowrap; }
.data-table th { background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #f7faf7; }
.data-table td.num { font-variant-numeric: tabular-nums; }
.data-table tr.voided td { text-decoration: line-through; color: var(--muted); opacity: 0.7; cursor: default; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
.badge.debtor { background: #fdecea; color: var(--danger); }
.badge.creditor { background: #e7f4e8; color: var(--success); }
.badge.settled { background: #eceff1; color: var(--muted); }

.amount.debtor { color: var(--danger); }
.amount.creditor { color: var(--success); }

.statement-head { display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 10px; border-bottom: 2px solid var(--primary); padding-bottom: 10px; margin-bottom: 14px; }
.statement-head .farm { font-size: 1.2rem; font-weight: 800; color: var(--primary-dark); }
.statement-head .subtitle { color: var(--muted); font-size: 0.9rem; }
.statement-head .person { text-align: left; font-size: 0.95rem; line-height: 1.9; }
.statement-head .person b { font-size: 1.05rem; }

.txform { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.txform .field { margin: 0; }

.rowvoid { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1rem; padding: 0 4px; }

@media print {
  .app-header, .toolbar, .txform, .card.no-print, .rowvoid, #toast, .nav-links, .print-hide { display: none !important; }
  body { background: #fff; }
  .container { max-width: 100%; padding: 0; }
  .data-table { box-shadow: none; }
  .data-table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .statement-head { page-break-after: avoid; }
}

/* ============ هم‌زبان با havele-standalone — پالت سبز ارگانیک ============ */
:root {
  --bg: #f5f5f0;
  --card: #ffffff;
  --text: #1a1f1a;
  --muted: #6b7a68;
  --border: #e0e6dc;
  --primary: #2e6a4f;
  --primary-dark: #1c3f30;
  --primary-soft: #eaf4ef;
  --danger: #b91c1c;
  --success: #166534;
  --warn: #92400e;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(28, 63, 48, 0.06);
}

html, body { font-family: "Vazirmatn", "Segoe UI", Tahoma, sans-serif; }
body { background: var(--bg); color: var(--text); }

/* هدر سفید مسطح با عنوان سبز — مثل هدر havele */
.app-header {
  background: rgba(255, 255, 255, 0.97);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  box-shadow: none;
  padding: 0 24px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-header h1 { color: var(--primary-dark); font-size: 17px; font-weight: 700; }
.nav-links a { color: var(--muted); }
.nav-links a.active, .nav-links a:hover { color: var(--primary-dark); }

/* دکمه‌ها — radius 6، مسطح، سبز */
.btn { border-radius: 6px; box-shadow: none; }
.btn-primary { background: var(--primary-dark); border: 1px solid var(--primary-dark); color: #fff; }
.btn-primary:hover { background: var(--primary); }
.btn-lite {
  background: #fff; border: 1px solid var(--border); color: var(--muted);
}
.btn-lite:hover { border-color: var(--primary); color: var(--primary-dark); }

/* کارت‌های آمار — سفید تمیز با حاشیه سبز کم‌رنگ */
.chip {
  background: #f9faf7; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: none; padding: 10px 14px;
}
.chip .chip-label { color: var(--muted); font-size: 0.76rem; }
.chip .chip-value { font-weight: 700; }

/* ورودی جستجو با فوکوس سبز */
.toolbar .search, .field input, .field textarea, .field select {
  border-radius: 6px;
}
.field input:focus, .field textarea:focus, .field select:focus,
.toolbar .search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(46, 106, 79, 0.14);
  outline: 0;
}

/* جدول — سربرگ سبز کم‌رنگ، هاور سبز روشن */
.data-table { box-shadow: var(--shadow); border: 1px solid var(--border); }
.data-table th { background: var(--primary-soft); color: var(--primary-dark); }
.data-table tbody tr:hover { background: #f7f8f5; }

/* نشان تشخیص — بدهکار کهربایی، طلبکار سبز، تسویه خاکستری (هم‌رنگ pill های havele) */
.badge.debtor { background: #fef3e2; color: var(--warn); }
.badge.creditor { background: var(--primary-soft); color: var(--primary-dark); }
.badge.settled { background: #eef0ec; color: var(--muted); }
.amount.debtor { color: var(--warn); }
.amount.creditor { color: var(--primary-dark); }

/* سربرگ صورت حساب با خط سبز */
.statement-head { border-bottom: 2px solid var(--primary); }
.statement-head .farm { color: var(--primary-dark); }

.toast.success { background: var(--primary-dark); }

/* مرجع مشتریان */
.customer-container { max-width: 1120px; }
.table-scroll { width: 100%; overflow-x: auto; border-radius: var(--radius); }
.customer-table { min-width: 820px; }
.customer-table th,.customer-table td { max-width: 260px; }
.customer-table td { overflow: hidden; }
.cell-ellipsis { display: block; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customer-modal-box { max-width: 820px; border-radius: 12px; }
.customer-form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.customer-form-grid .field { margin: 0; }
.customer-form-grid .field-wide { grid-column: 1 / -1; }
.customer-active { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; padding: 10px; background: var(--primary-soft); border-radius: 6px; }
.muted { color: var(--muted); font-size: .82rem; }
@media (max-width: 640px) {
  .customer-form-grid { grid-template-columns: 1fr; }
  .customer-form-grid .field-wide,.customer-active { grid-column: auto; }
  .customer-modal-box { border-radius: 12px 12px 0 0; }
}
