:root {
  --primary: #5B1FA8;
  --primary-dark: #4a1888;
  --success: #2E7D32;
  --danger: #C0392B;
  --warning: #EF6C00;
  --bg: #F7F7F8;
  --card: #FFFFFF;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: rgba(0, 0, 0, 0.1);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Tahoma, "Vazirmatn", "Iran Sans", sans-serif;
  direction: rtl;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
#app { min-height: 100vh; display: flex; flex-direction: column; }
@media (min-width: 881px) {
  html, body { background: #E7E3F0; }
  #app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 46px rgba(36, 20, 66, 0.18);
  }
  .drawer-overlay, .app-drawer, .bottom-sheet-card, .chat-input-bar,
  .map-picker-overlay, .fab-stack, .map-page {
    position: absolute !important;
  }
}
.appbar {
  background: var(--primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: bold;
  font-size: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.appbar .appbar-icon-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.appbar .appbar-title { flex: 1; }
.page-body { flex: 1; padding: 16px; padding-bottom: 32px; }
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 13px 16px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  color: #fff;
  background: var(--primary);
  transition: opacity .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.btn-success { background: var(--success); }
.btn.btn-danger { background: var(--danger); }
.btn.btn-warning { background: var(--warning); }
.btn.btn-outline {
  background: transparent;
  border: 1.4px solid var(--primary);
  color: var(--primary);
}
.btn.btn-outline.btn-danger-outline { border-color: var(--danger); color: var(--danger); }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
input[type=text], input[type=tel], input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  direction: rtl;
}
textarea { resize: vertical; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: bold; color: var(--text-muted); }
.ltr-input { direction: ltr; text-align: right; }
.error-text { color: var(--danger); font-size: 12.5px; margin: 8px 0; }
.hint-box {
  background: #FFF3E0;
  border-radius: 10px;
  padding: 12px;
  font-size: 12px;
  color: #444;
  margin-bottom: 14px;
}
.muted { color: var(--text-muted); font-size: 12.5px; }
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.spinner.dark { border-color: rgba(91,31,168,.25); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
.center-loading { display: flex; justify-content: center; padding: 40px 0; }
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: bold;
}
.badge.pending { background: #fff3cd; color: #8a6d00; }
.badge.approved { background: #d9f2d9; color: #1b5e20; }
.badge.rejected { background: #f8d7da; color: #842029; }
.selectable-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 10px;
  cursor: pointer;
  background: #fff;
}
.selectable-card.selected { background: #F1EBFA; border-color: var(--primary); border-width: 1.6px; }
.selectable-card .radio-dot {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid #bbb; flex-shrink: 0; margin-top: 2px;
}
.selectable-card.selected .radio-dot { border-color: var(--primary); background: radial-gradient(circle, var(--primary) 0 40%, transparent 42%); }
.bottom-sheet-card {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 16px;
  box-shadow: 0 -2px 10px rgba(0,0,0,.15);
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.fab-stack { position: fixed; left: 16px; display: flex; flex-direction: column; gap: 12px; z-index: 40; }
.fab {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px; border: none; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.empty-state { text-align: center; color: #999; padding: 30px 10px; font-size: 13px; }
.switch { position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #ccc; border-radius: 26px; transition: .2s;
}
.switch-slider:before {
  position: absolute; content: ""; height: 20px; width: 20px;
  right: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .switch-slider { background: var(--success); }
.switch input:checked + .switch-slider:before { transform: translateX(-22px); }
.switch input:disabled + .switch-slider { opacity: .6; cursor: not-allowed; }
#map-container { width: 100%; height: 100%; }
.map-page { position: fixed; inset: 0; }
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 90; display: none;
}
.drawer-overlay.open { display: block; }
.app-drawer {
  position: fixed; top: 0; bottom: 0; right: -300px;
  width: 280px; max-width: 86vw; background: #fff; z-index: 91;
  transition: right .22s ease; overflow-y: auto;
  box-shadow: -2px 0 12px rgba(0,0,0,.2);
}
.app-drawer.open { right: 0; }
.drawer-header {
  padding: 20px 16px 16px; background: var(--primary); color: #fff;
  display: flex; align-items: center; gap: 12px;
}
.drawer-header .drawer-avatar {
  width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,.15);
  display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0;
}
.drawer-header .drawer-avatar { position: relative; overflow: visible; }
.drawer-header .drawer-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,.85); box-sizing: border-box; }
.drawer-header .drawer-avatar.has-photo-edit { cursor: pointer; }
.drawer-header .drawer-avatar-cam {
  position: absolute; bottom: -4px; left: -4px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; color: #333; font-size: 12px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.drawer-header .drawer-name { font-weight: bold; font-size: 15px; }
.drawer-header .drawer-mobile { font-size: 12px; color: rgba(255,255,255,.75); margin-top: 2px; }
.drawer-item {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  cursor: pointer; font-size: 13.5px; color: var(--text); border-bottom: 1px solid #f3f3f3;
  text-decoration: none;
}
.drawer-item:hover { background: #fafafa; }
.drawer-item.active { background: #F1EBFA; color: var(--primary); font-weight: bold; }
.drawer-item .icon { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }
.drawer-item.danger { color: var(--danger); }
.drawer-item .subtitle { font-size: 10.5px; color: var(--text-muted); display: block; margin-top: 1px; }
.drawer-divider { height: 1px; background: #eee; margin: 6px 0; }
.appbar-icon-btn.menu-btn { font-size: 22px; }
.map-picker-overlay { position: fixed; inset: 0; background: #fff; z-index: 5000; display: flex; flex-direction: column; }
.map-picker-header { padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #eee; font-weight: bold; font-size: 14px; }
.map-picker-map { flex: 1; position: relative; }
.map-picker-locate-btn { position: absolute; bottom: 90px; left: 10px; z-index: 10; background: #fff; border: none; border-radius: 50%; width: 42px; height: 42px; box-shadow: 0 1px 6px rgba(0,0,0,.3); font-size: 18px; cursor: pointer; }
.map-picker-footer { padding: 12px 14px; border-top: 1px solid #eee; display: flex; gap: 10px; }
.map-picker-hint { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.65); color: #fff; padding: 6px 12px; border-radius: 20px; font-size: 11.5px; z-index: 10; }
.list-row {
  background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06); cursor: pointer;
}
.list-row:active { opacity: .85; }
.list-row-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list-row-title { font-weight: bold; font-size: 13.5px; }
.list-row-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.list-row-amount { font-weight: bold; font-size: 14px; }
.list-row-amount.positive { color: var(--success); }
.list-row-amount.negative { color: var(--danger); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.tab-btn {
  flex-shrink: 0; padding: 9px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: #fff; font-size: 12.5px; font-weight: bold; color: var(--text-muted); cursor: pointer;
}
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chat-bubble { max-width: 82%; padding: 9px 13px; border-radius: 14px; margin-bottom: 8px; font-size: 13px; line-height: 1.6; }
.chat-bubble.mine { background: var(--primary); color: #fff; margin-right: 0; margin-left: auto; border-radius: 14px 14px 4px 14px; }
.chat-bubble.theirs { background: #fff; color: var(--text); margin-left: 0; margin-right: auto; border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; }
.chat-bubble .chat-meta { font-size: 10px; opacity: .7; margin-top: 4px; }
.chat-compose { display: flex; gap: 8px; align-items: flex-end; }
.chat-compose textarea { flex: 1; min-height: 42px; max-height: 110px; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat-tile { background: var(--card); border-radius: 12px; padding: 14px; text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.stat-tile .stat-value { font-size: 18px; font-weight: bold; color: var(--primary); }
.stat-tile .stat-label { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.home-menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.home-menu-grid .tile {
  background: var(--card); border-radius: 12px; padding: 14px 6px; text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.06); cursor: pointer; text-decoration: none; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.home-menu-grid .tile .icon { font-size: 22px; }
.home-menu-grid .tile .label { font-size: 11px; font-weight: bold; }
.appbar .appbar-logout-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.16); color: #fff; font-family: inherit; font-size: 12.5px; font-weight: bold;
  border: 1.5px solid rgba(255,255,255,.7); border-radius: 18px; padding: 5px 12px 5px 10px; cursor: pointer;
  box-shadow: 0 2px 0 rgba(0,0,0,.25); transition: transform .08s, box-shadow .08s, background .15s;
}
.appbar .appbar-logout-btn:hover { background: rgba(255,255,255,.28); }
.appbar .appbar-logout-btn:active { transform: translateY(2px); box-shadow: none; }
.appbar .appbar-logout-btn svg { flex: none; }
