:root {
  --brand: #0f3d2e;
  --brand-light: #146c2e;
  --danger: #a12626;
  --bg: #f5f6f5;
  --card-bg: #ffffff;
  --border: #e0e0e0;
  --text: #222;
  --muted: #777;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: Tahoma, "Vazirmatn", sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--brand);
  color: #fff;
  padding: 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top));
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
  flex: 1;
  text-align: center;
}

.icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 22px;
  padding: 2px 10px;
  cursor: pointer;
  visibility: hidden;
}
.icon-btn.show { visibility: visible; }

.badge {
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 12px;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px;
  padding-bottom: 40px;
}

.view { display: none; }
.view.active { display: block; }

.hero { text-align: center; margin-bottom: 16px; }
.hero h2 { margin: 6px 0 2px; color: var(--brand); }

.muted { color: var(--muted); }
.small { font-size: 12px; }

.section-title {
  margin: 18px 0 8px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.menu-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 8px;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.menu-btn:active { background: #eef2ef; }

.page-title {
  color: var(--brand);
  margin-top: 4px;
}

.record-form { display: flex; flex-direction: column; gap: 10px; }
.record-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: #444;
}
.record-form input,
.record-form select,
.record-form textarea {
  font-family: inherit;
  font-size: 15px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  direction: rtl;
  text-align: right;
}
.record-form textarea { resize: vertical; }

.inline-row { display: flex; gap: 8px; align-items: flex-end; }
.inline-row .grow { flex: 1; }

.hint {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  margin-top: -4px;
}

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14px;
  cursor: pointer;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-light); }
.btn-secondary { background: #e9ece9; color: #222; }
.btn-secondary:active { background: #dadfda; }

.form-msg { font-size: 13px; min-height: 18px; }
.form-msg.ok { color: var(--brand-light); }
.form-msg.error { color: var(--danger); }

.warning {
  background: #fff3f0;
  border: 1px solid #f0c8c0;
  color: var(--danger);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  margin-top: 16px;
}
.hidden { display: none !important; }

.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-row input { flex: 1; }

.summary-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.9;
  white-space: pre-line;
}

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; min-width: 560px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: center; white-space: nowrap; }
thead th { background: #eef2ef; position: sticky; top: 0; }
tr.row-debtor td { color: var(--brand-light); }
tr.row-creditor td { color: var(--danger); }
tr.row-settled td { color: #666; }

.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab-btn {
  flex: 1;
  padding: 9px 4px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.tab-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.filter-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}
.filter-box input {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  direction: rtl;
}
.filter-row { display: flex; gap: 6px; }
.filter-row input { flex: 1; margin-bottom: 0; }

.row-actions { display: flex; gap: 4px; justify-content: center; }
.row-actions button {
  border: none;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}
.btn-edit { background: #e3ecff; color: #1a4fb0; }
.btn-delete { background: #ffe3e3; color: var(--danger); }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.card h3 { margin-top: 0; color: var(--brand); font-size: 15px; }
.card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  margin-bottom: 8px;
}
.card select, .card input {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  direction: rtl;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-content {
  background: #fff;
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 16px;
}
.modal-actions { display: flex; gap: 8px; margin-top: 10px; }
.modal-actions button { flex: 1; }
