@import url("https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800;900&display=swap");
:root {
  font-family: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
  --app-bg: #f6f9ff;
  --surface: #ffffff;
  --surface-soft: #f2f7ff;
  --ink: #10213f;
  --muted: #7b8aa5;
  --line: #e5edf9;
  --blue: #1769ff;
  --blue-dark: #0e54d8;
  --blue-soft: #eaf2ff;
  --blue-soft-2: #f4f8ff;
  --green: #169b67;
  --red: #dc4d57;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body, #app { margin: 0; min-height: 100%; background: var(--app-bg); }
body { overscroll-behavior-y: none; color: var(--ink); font-family: "Vazirmatn", "Segoe UI", Tahoma, sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
input { color: var(--ink); }

.app-screen, .dashboard-page, .login-page { background: var(--app-bg) !important; }
.app-screen { width: 100%; min-height: 100vh; position: relative; }

.app-shell, .login-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  position: relative;
  background: var(--app-bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 20px) 20px 16px;
}
.topbar h1 { margin: 3px 0 0; font-size: 25px; line-height: 1.35; letter-spacing: -.5px; color: var(--ink); }
.eyebrow { font-size: 12px; color: var(--muted); font-weight: 700; }
.avatar-button, .icon-button {
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
  color: inherit;
}
.avatar-button {
  width: 44px;
  height: 44px;
  border-radius: 15px;
  color: var(--blue);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(30, 87, 176, .07);
}

.install-card {
  margin: 0 16px 14px;
  padding: 12px;
  border-radius: 19px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid #dbe8ff;
  display: grid;
  grid-template-columns: 42px 1fr auto auto;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 28px rgba(31, 93, 193, .07);
}
.install-icon { width: 42px; height: 42px; border-radius: 13px; background: var(--blue-soft); display: grid; place-items: center; color: var(--blue); }
.install-copy { display: flex; flex-direction: column; min-width: 0; }
.install-copy strong { font-size: 12.5px; font-weight: 800; }
.install-copy span { font-size: 10.5px; color: var(--muted); margin-top: 2px; line-height: 1.65; }
.install-card > button:not(.dismiss) { border: 0; background: var(--blue); color: white; border-radius: 11px; padding: 8px 12px; font-weight: 800; font-size: 11px; }
.install-card .dismiss { border: 0; background: transparent; color: #9aa7ba; padding: 3px; }

.balance-card {
  margin: 0 16px 22px;
  min-height: 244px;
  background: linear-gradient(145deg, #ffffff 0%, #f5f9ff 100%);
  border: 1px solid #dce9ff;
  border-radius: 28px;
  color: var(--ink);
  padding: 21px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 18px 45px rgba(24, 86, 180, .09);
}
.balance-card__glow { pointer-events: none; position: absolute; width: 210px; height: 210px; border-radius: 50%; left: -95px; top: -105px; background: radial-gradient(circle, rgba(23,105,255,.14), transparent 68%); }
.balance-head { display: flex; align-items: center; justify-content: space-between; position: relative; z-index: 1; }
.balance-head > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.gold-chip { display: flex; align-items: center; gap: 5px; padding: 7px 11px; border-radius: 999px; color: var(--blue); background: var(--blue-soft); font-size: 11px; font-weight: 800; }
.balance-value { display: flex; align-items: baseline; gap: 8px; direction: ltr; justify-content: flex-end; margin: 24px 0 10px; position: relative; z-index: 1; }
.balance-value strong { font-size: 50px; line-height: 1; letter-spacing: -2px; color: #0d2b59; font-variant-numeric: tabular-nums; }
.balance-value span { font-size: 15px; color: var(--muted); font-weight: 700; }
.trend-row { display: flex; justify-content: flex-end; position: relative; z-index: 1; }
.trend-pill { display: inline-flex; align-items: center; gap: 5px; padding: 7px 9px; border-radius: 10px; font-size: 10.5px; font-weight: 700; background: #f5f8fd; }
.trend-pill.up { color: var(--green); }
.trend-pill.down { color: var(--red); }
.balance-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 18px; position: relative; z-index: 1; }
.balance-action { position: relative; z-index: 5; pointer-events: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; min-height: 45px; border-radius: 14px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; font-weight: 800; }
.balance-action.add { border: 0; background: var(--blue); color: white; box-shadow: 0 10px 20px rgba(23,105,255,.18); }
.balance-action.remove { border: 1px solid #cfe0fb; background: white; color: var(--blue); }

.section-block { margin: 0 16px 22px; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 12px; }
.section-title > div:first-child { display: flex; flex-direction: column; }
.section-title span { font-size: 15px; font-weight: 900; color: var(--ink); }
.section-title small { color: var(--muted); margin-top: 3px; font-size: 10.5px; line-height: 1.6; }

.owners-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.owner-card { background: var(--surface); border-radius: 22px; padding: 15px; box-shadow: 0 8px 28px rgba(28, 83, 164, .055); border: 1px solid var(--line); }
.owner-icon { width: 39px; height: 39px; border-radius: 13px; display: grid; place-items: center; margin-bottom: 13px; }
.primary-owner .owner-icon { background: #eef4ff; color: #245fb8; }
.beneficiary-owner .owner-icon { background: #e9f2ff; color: var(--blue); }
.owner-name { font-size: 12px; color: #657692; font-weight: 700; }
.owner-value { font-size: 22px; font-weight: 900; margin: 3px 0 11px; direction: ltr; text-align: right; color: var(--ink); }
.owner-value span { font-size: 10px; color: var(--muted); font-weight: 700; }
.share-bar { height: 6px; background: #edf3fb; border-radius: 10px; overflow: hidden; direction: ltr; }
.share-bar i { display: block; height: 100%; border-radius: inherit; background: #6597e8; }
.beneficiary-owner .share-bar i { background: var(--blue); }
.owner-card small { display: block; margin-top: 7px; color: var(--muted); font-size: 9.5px; }

.chart-card { background: var(--surface); padding: 17px 15px 12px; border-radius: 24px; border: 1px solid var(--line); box-shadow: 0 8px 28px rgba(28, 83, 164, .055); }
.mini-stat { font-size: 11px; font-weight: 800; color: var(--blue); background: var(--blue-soft); padding: 7px 10px; border-radius: 10px; }
.chart-wrap { direction: ltr; }
.chart-wrap svg { width: 100%; display: block; overflow: visible; }
.chart-grid { stroke: #e7eef8; stroke-width: 1; stroke-dasharray: 3 5; }
.chart-line { fill: none; stroke: var(--blue); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { fill: #fff; stroke: var(--blue); stroke-width: 2; }
.chart-labels { display: flex; justify-content: space-between; color: #96a4ba; font-size: 9px; direction: rtl; padding: 0 3px 2px; }

.rule-card { margin: 0 16px 22px; padding: 14px; background: #f2f7ff; border: 1px solid #d9e7ff; border-radius: 20px; display: grid; grid-template-columns: 42px 1fr 20px; gap: 11px; align-items: center; color: var(--ink); }
.rule-icon { width: 42px; height: 42px; border-radius: 13px; background: #dfeaff; color: var(--blue); display: grid; place-items: center; }
.rule-copy { display: flex; flex-direction: column; }
.rule-copy span { color: var(--blue); font-size: 10px; font-weight: 800; }
.rule-copy strong { margin: 2px 0; font-size: 12.5px; line-height: 1.7; }
.rule-copy small { color: var(--muted); font-size: 9.5px; line-height: 1.65; }
.bottom-safe-space { height: calc(18px + env(safe-area-inset-bottom)); }

.login-page { background: #fff !important; }
.login-shell { background: linear-gradient(180deg, #f4f8ff 0%, #ffffff 45%); color: var(--ink); padding: calc(env(safe-area-inset-top) + 58px) 22px 36px; display: flex; flex-direction: column; }
.brand-mark { width: 66px; height: 66px; border-radius: 22px; background: linear-gradient(145deg, #1769ff, #0e56df); color: white; display: grid; place-items: center; box-shadow: 0 18px 40px rgba(23,105,255,.22); }
.login-copy { margin-top: 34px; }
.login-copy .eyebrow { color: var(--blue); }
.login-copy h1 { margin: 7px 0 8px; font-size: 32px; line-height: 1.4; letter-spacing: -.6px; }
.login-copy p { color: var(--muted); margin: 0; line-height: 1.9; font-size: 13px; }
.login-card { margin-top: 34px; }
.password-field { height: 58px; border: 1px solid #d9e4f5; background: #fff; border-radius: 18px; display: grid; grid-template-columns: 24px 1fr 36px; align-items: center; gap: 8px; padding: 0 14px; transition: .2s; color: #7587a4; box-shadow: 0 8px 24px rgba(27,81,163,.05); }
.password-field:focus-within { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(23,105,255,.08); }
.password-field.has-error { border-color: var(--red); }
.password-field input { background: transparent; border: 0; outline: 0; color: var(--ink); min-width: 0; font-size: 16px; direction: ltr; text-align: right; }
.password-field input::placeholder { color: #9ba8bb; direction: rtl; }
.password-field .icon-button { color: #8392a8; }
.field-error { font-size: 11px; color: var(--red); margin: 8px 4px 0; }
.primary-button { width: 100%; border: 0; border-radius: 16px; min-height: 54px; display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 14px; background: var(--blue); color: white; font-weight: 900; box-shadow: 0 13px 28px rgba(23,105,255,.19); }
.primary-button:active, .balance-action:active { transform: scale(.985); }
.security-note { margin-top: auto; padding-top: 48px; display: flex; align-items: center; justify-content: center; gap: 6px; color: #8290a5; font-size: 10.5px; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 9999; background: rgba(20, 44, 80, .22); display: flex; align-items: flex-end; justify-content: center; backdrop-filter: blur(5px); }
.bottom-sheet { width: min(100%, 480px); background: #fff; border-radius: 29px 29px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -20px 60px rgba(15,54,110,.16); animation: sheetUp .22s ease-out; color: var(--ink); }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 38px; height: 5px; background: #d8e1ee; border-radius: 20px; margin: 0 auto 18px; }
.sheet-header { display: flex; justify-content: space-between; align-items: center; }
.sheet-header > div { display: flex; flex-direction: column; }
.sheet-header span { font-size: 16px; font-weight: 900; }
.sheet-header small { font-size: 10px; color: var(--muted); margin-top: 2px; }
.sheet-close { width: 38px; height: 38px; border-radius: 12px; color: #6f819e; background: #f3f6fb; }
.segmented-control { background: #eff4fb; border-radius: 14px; padding: 4px; display: grid; grid-template-columns: 1fr 1fr; margin-top: 18px; }
.segmented-control button { border: 0; background: transparent; border-radius: 11px; padding: 10px; color: #7889a4; font-weight: 800; }
.segmented-control button.active { background: white; color: var(--blue); box-shadow: 0 3px 10px rgba(31,78,148,.09); }
.amount-input { display: block; margin-top: 18px; }
.amount-input > span { display: block; font-size: 11px; color: var(--muted); margin: 0 3px 7px; }
.amount-input > div { height: 61px; border: 1px solid #dbe5f3; border-radius: 16px; display: flex; align-items: center; padding: 0 14px; gap: 8px; background: #fff; transition: .2s; }
.amount-input > div:focus-within { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(23,105,255,.07); }
.amount-input > div.input-error { border-color: var(--red); }
.amount-input input { flex: 1; min-width: 0; border: 0; outline: none; font-size: 24px; font-weight: 900; direction: ltr; text-align: right; background: transparent; color: var(--ink); }
.amount-input b { font-size: 12px; color: var(--muted); }
.quick-values { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 10px; }
.quick-values button { border: 1px solid #dce8fa; background: #f7faff; color: #547198; border-radius: 11px; padding: 8px 3px; font-size: 10px; font-weight: 700; }
.quick-values button:active { background: var(--blue-soft); color: var(--blue); }
.sheet-error { margin-top: 10px; padding: 9px 11px; border-radius: 11px; background: #fff1f2; color: var(--red); font-size: 10.5px; line-height: 1.7; }
.preview-row { display: flex; justify-content: space-between; align-items: center; margin: 14px 3px 4px; font-size: 11px; color: var(--muted); }
.preview-row strong { color: var(--ink); font-size: 12px; }
.preview-final { border-top: 1px dashed #dce5f1; padding-top: 11px; }
.preview-final strong { color: var(--blue); font-size: 15px; }
.invalid-preview { color: var(--red) !important; }
.bottom-sheet .primary-button { margin-top: 18px; }

.save-toast { position: fixed; z-index: 10000; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); width: calc(100% - 36px); max-width: 440px; background: #123e7d; color: white; border-radius: 15px; padding: 12px 14px; display: flex; align-items: center; justify-content: center; gap: 7px; box-shadow: 0 14px 34px rgba(18,62,125,.2); font-size: 11.5px; font-weight: 700; animation: toastIn .2s ease-out; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (min-width: 600px) {
  body { background: #edf3fb; }
  .app-shell, .login-shell { box-shadow: 0 0 60px rgba(22,65,126,.1); }
}

.primary-button:disabled,
.balance-action:disabled {
  opacity: .58;
  cursor: default;
  transform: none !important;
}

.loading-shell {
  display: grid;
  place-items: center;
  padding: 24px;
}

.loading-card {
  width: 100%;
  margin: auto 16px;
  padding: 28px 20px;
  border-radius: 24px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 14px 40px rgba(28, 83, 164, .07);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  text-align: center;
  color: var(--blue);
}

.loading-card strong { color: var(--ink); font-size: 14px; }
.loading-card small { color: var(--muted); font-size: 10.5px; line-height: 1.8; }

/* v5 interaction hardening */
[data-action] { pointer-events: auto !important; touch-action: manipulation; }
.sheet-backdrop[hidden], .save-toast[hidden], .install-card[hidden] { display: none !important; }
body.modal-open { overflow: hidden; }
