:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #e4e8ef;
  --green: #16a36a;
  --green-soft: #eafaf2;
  --red: #dc3545;
  --red-soft: #fff0f1;
  --yellow: #f59e0b;
  --yellow-soft: #fff7e6;
  --gray: #8a94a6;
  --shadow: 0 16px 40px rgba(30, 41, 59, .08);
  --radius: 8px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: Vazirmatn, IRANSans, Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
.ltr { direction: ltr; text-align: left; }

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 18px 42px;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(255,255,255,.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 12px;
  z-index: 5;
  backdrop-filter: blur(12px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 900;
  white-space: nowrap;
}
.brand.center { justify-content: center; }
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, #0ea5a4, #16a36a);
  box-shadow: 0 10px 22px rgba(22, 163, 106, .25);
}
.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
}
.nav a {
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  white-space: nowrap;
}
.nav a:hover { background: #f1f5f9; color: var(--text); }
.user-pill {
  background: #eef6f4;
  color: #0f766e;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}
.main { padding-top: 24px; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 8px 0 22px;
}
.page-head h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
}
.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.btn {
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 15px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  transition: transform .15s ease, box-shadow .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--green); color: white; box-shadow: 0 10px 22px rgba(22,163,106,.22); }
.btn.secondary { background: #0f766e; color: white; }
.btn.soft { background: #eef2f7; color: #334155; }
.btn.warning { background: var(--yellow); color: #422006; }
.btn.danger { background: var(--red); color: white; }
.btn.full { width: 100%; }
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 16px;
}
.inline-form { display: inline-flex; margin: 0; }

.alert {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  background: white;
}
.alert.success { background: var(--green-soft); color: #067647; border-color: #b7ebcf; }
.alert.danger { background: var(--red-soft); color: #b42318; border-color: #ffc9ce; }

.card-grid, .list-stack {
  display: grid;
  gap: 14px;
}
.debt-card, .payment-card, .form-card, .summary-card, .mini-card, .stat-card, .empty {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.debt-card { border-right: 5px solid var(--green); overflow: hidden; }
.debt-card.is-closed { border-right-color: var(--red); }
.debt-card.pending { border-right-color: var(--yellow); }
.debt-card.rejected { border-right-color: var(--gray); }
.card-toggle, .payment-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px 16px;
  padding: 16px;
  cursor: pointer;
  text-align: right;
}
.card-title {
  font-size: 17px;
  font-weight: 900;
}
.star { color: var(--yellow); margin-left: 4px; }
.card-meta {
  color: var(--muted);
  font-size: 13px;
  grid-column: 2;
  grid-row: 1;
  white-space: nowrap;
}
.card-amount {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.card-amount strong { color: #0f766e; }
.debt-card.is-closed .card-amount strong { color: var(--red); }
.card-amount small { color: var(--yellow); font-weight: 800; }
.accordion-panel {
  display: none;
  border-top: 1px solid var(--line);
  padding: 16px;
}
.accordion-panel.open { display: block; }

.detail-grid, .summary-card, .stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.detail-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.detail-grid > div, .summary-card > div {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}
.detail-grid span, .summary-card span, .stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}
.amount-main {
  display: block;
  font-weight: 900;
}
.amount-sub {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.note {
  background: #fffbea;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 12px;
}
.account-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.account-box div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fbfdff;
  border: 1px solid var(--line);
}
.account-box span { color: var(--muted); }

.form-card {
  padding: 18px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
label {
  display: grid;
  gap: 7px;
  font-weight: 800;
}
input, textarea, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: white;
  color: var(--text);
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 3px solid rgba(22, 163, 106, .14);
  border-color: var(--green);
}
.span-2 { grid-column: span 2; }
.check-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  align-self: end;
  min-height: 44px;
}
.check-row input { width: auto; min-height: auto; }
.live-amount {
  color: #0f766e;
  font-weight: 700;
  min-height: 24px;
}
.field-hint {
  color: var(--muted);
  font-weight: 700;
  min-height: 22px;
}
.field-hint.ok { color: var(--green); }
.field-hint.bad { color: var(--red); }
.card-image-link {
  display: inline-flex;
  margin-top: 12px;
  color: #0f766e;
  font-weight: 900;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
}

.summary-card {
  padding: 14px;
  margin-bottom: 16px;
}
.payment-toggle {
  grid-template-columns: 1fr auto;
}
.payment-toggle span:first-child {
  display: grid;
}
.payment-toggle small { color: var(--muted); }
.status-tag {
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 900;
  font-size: 12px;
  white-space: nowrap;
}
.status-tag.confirmed, .status-tag.ok { background: var(--green-soft); color: #067647; }
.status-tag.reserved { background: var(--red-soft); color: #b42318; }
.status-tag.cancelled, .status-tag.muted { background: #eef2f7; color: var(--gray); }
.status-tag:disabled { opacity: .65; cursor: not-allowed; }

.stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.stat-card {
  padding: 16px;
}
.stat-card.clickable {
  display: block;
}
.stat-card.clickable:hover {
  transform: translateY(-1px);
  box-shadow: 0 20px 48px rgba(30, 41, 59, .11);
}
.stat-card strong {
  font-size: 28px;
}
.stat-card.danger { border-color: #ffc9ce; }
.stat-card.warning { border-color: #fde68a; }
.mini-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  flex-wrap: wrap;
}
.mini-card small { display: block; color: var(--muted); }
.password-change-form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) auto;
  gap: 8px;
  align-items: center;
  flex: 1 1 460px;
}
.password-change-form input {
  min-height: 40px;
}
.empty {
  padding: 26px;
  text-align: center;
  color: var(--muted);
}
.sub-head {
  margin-top: 28px;
}
.sub-head h2 {
  margin: 0;
  font-size: 22px;
}
.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.image-viewer.open {
  display: flex;
}
.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .72);
}
.image-viewer-dialog {
  position: relative;
  width: min(920px, 100%);
  max-height: min(86vh, 820px);
  background: white;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .28);
  z-index: 1;
}
.image-viewer-dialog img {
  display: block;
  width: 100%;
  max-height: calc(86vh - 24px);
  object-fit: contain;
  border-radius: 6px;
}
.image-viewer-close {
  position: absolute;
  top: -12px;
  left: -12px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: var(--red);
  color: white;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}
.login-card {
  width: min(420px, 100%);
  background: white;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 24px;
}
.login-card h1 {
  text-align: center;
  margin: 18px 0;
}

@media (max-width: 760px) {
  .app-shell { padding: 10px 10px 28px; }
  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    position: static;
  }
  .nav { order: 3; width: 100%; padding-bottom: 2px; }
  .user-pill { justify-self: start; }
  .page-head {
    align-items: stretch;
    flex-direction: column;
  }
  .page-head .btn { width: 100%; }
  .card-toggle {
    grid-template-columns: 1fr;
  }
  .card-meta {
    grid-column: 1;
    grid-row: auto;
    justify-self: start;
  }
  .detail-grid, .summary-card, .stats-grid, .form-grid, .account-box {
    grid-template-columns: 1fr;
  }
  .span-2 { grid-column: span 1; }
  .actions .btn, .actions .inline-form {
    width: 100%;
  }
  .inline-form .btn { width: 100%; }
  .mini-card {
    align-items: stretch;
  }
  .password-change-form {
    grid-template-columns: 1fr;
    flex-basis: 100%;
  }
  .password-change-form .btn {
    width: 100%;
  }
}
