/* پنل پیامک — shared styles for the Android app and the PWA.
   RTL Persian, light theme, big touch targets (min 48px), no CSS framework (cheap phones). */

@font-face {
    font-family: "Vazirmatn";
    src: url("fonts/Vazirmatn-Regular.woff2") format("woff2");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Vazirmatn";
    src: url("fonts/Vazirmatn-Bold.woff2") format("woff2");
    font-weight: 700;
    font-display: swap;
}

:root {
    --primary: #9333ea;
    --primary-dark: #7e22ce;
    --primary-soft: rgba(147, 51, 234, .2);
    --bg: #120d24;
    --surface: #1c1536;
    --text: #f1ecff;
    --muted: #a79fc2;
    --border: rgba(255, 255, 255, .12);
    --danger: #ff7b7b;
    --danger-soft: rgba(239, 68, 68, .16);
    --success: #34d399;
    --success-soft: rgba(16, 185, 129, .16);
    --warning: #fbbf24;
    --warning-soft: rgba(245, 158, 11, .16);
    --radius: 14px;
    --touch: 48px;
    --shadow: 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Vazirmatn", Tahoma, sans-serif;
    font-size: 16px;
    line-height: 1.7;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

body { overscroll-behavior-y: none; }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.4; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
h1:focus { outline: none; }
p { margin: 0 0 .5rem; }
a { color: var(--primary); }

/* Latin/number islands inside RTL text (phone numbers, codes, lines) */
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- app frame ---------- */

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    max-width: 640px;
    margin: 0 auto;
    background: var(--bg);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: .5rem;
    min-height: 56px;
    padding: .25rem .75rem;
    padding-top: calc(.25rem + env(safe-area-inset-top, 0px));
    background: var(--primary);
    color: #fff;
}

.topbar .title { flex: 1; min-width: 0; font-weight: 700; }
.topbar .title small { display: block; font-weight: 400; opacity: .85; font-size: .85rem; }
.topbar .icon-btn { color: #fff; }

.page { flex: 1; padding: 1rem; }
.page.center { display: flex; flex-direction: column; justify-content: center; }

.brand { text-align: center; margin-bottom: 1.5rem; }
.brand .logo {
    width: 64px; height: 64px; margin: 0 auto .75rem;
    border-radius: 18px; background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 2rem;
}
.brand p { color: var(--muted); }

/* ---------- buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: var(--touch);
    padding: .5rem 1.1rem;
    border: 1px solid transparent;
    border-radius: 12px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    user-select: none;
    transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:not(:disabled):active { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--primary); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-block { display: flex; width: 100%; }
.btn-big { min-height: 56px; font-size: 1.05rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: var(--touch); height: var(--touch);
    border: 0; border-radius: 50%; background: transparent; color: var(--text);
    font-size: 1.3rem; cursor: pointer;
}

.link-btn {
    border: 0; background: none; padding: .5rem; min-height: var(--touch);
    color: var(--primary); font: inherit; font-weight: 700; cursor: pointer;
}
.link-btn:disabled { color: var(--muted); cursor: default; }

/* ---------- forms ---------- */

.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: .3rem; font-weight: 700; font-size: .95rem; }
.field .hint { color: var(--muted); font-size: .85rem; margin-top: .25rem; }

.input, .textarea, .select {
    width: 100%;
    min-height: var(--touch);
    padding: .6rem .8rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 16px; /* 16px stops iPhone Safari from zooming in */
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.8; }
.input:focus, .textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.input.ltr-input { direction: ltr; text-align: left; }

.input-with-btn { position: relative; }
.input-with-btn .input { padding-left: 3.2rem; }
.input-with-btn .icon-btn { position: absolute; left: 0; top: 0; }

.check {
    display: flex; align-items: center; gap: .6rem;
    min-height: var(--touch); cursor: pointer;
}
.check input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }

/* ---------- messages ---------- */

.alert { padding: .7rem .9rem; border-radius: 12px; margin-bottom: 1rem; font-size: .95rem; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-info { background: var(--primary-soft); color: var(--primary-dark); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center-text { text-align: center; }

/* ---------- loading ---------- */

.spinner {
    display: inline-block; width: 20px; height: 20px;
    border: 3px solid currentColor; border-left-color: transparent;
    border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle;
}
.spinner.big { width: 36px; height: 36px; color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-block { display: flex; flex-direction: column; align-items: center; gap: .75rem; padding: 2rem 1rem; color: var(--muted); }

.progress { height: 8px; border-radius: 4px; background: var(--primary-soft); overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); transition: width .2s; }
.progress.indeterminate > div { width: 40%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(150%); } to { transform: translateX(-250%); } }

/* ---------- chat ---------- */

.chat { flex: 1; display: flex; flex-direction: column; gap: .75rem; padding: 1rem .75rem 9rem; }

.bubble {
    max-width: 88%;
    padding: .6rem .9rem;
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
    word-break: break-word;
}
.bubble.bot { align-self: flex-start; border-top-right-radius: 4px; }
.bubble.user { align-self: flex-end; background: var(--primary); color: #fff; border-top-left-radius: 4px; }
.bubble.success { background: var(--success-soft); color: var(--success); }
.bubble.error { background: var(--danger-soft); color: var(--danger); }

.quick-buttons {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 15;
    max-width: 640px;
    margin: 0 auto;
    padding: .5rem .75rem;
    padding-bottom: calc(.5rem + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.quick-buttons .row { display: flex; gap: .5rem; }
.quick-buttons .row .btn { flex: 1; padding: .4rem .3rem; font-size: .95rem; }
.quick-buttons form { display: flex; gap: .5rem; margin-top: .5rem; }
.quick-buttons form .input { min-height: 44px; }

/* ---------- cards ---------- */

.card {
    align-self: stretch;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
}
.card-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.card-head .step {
    width: 28px; height: 28px; flex: none; border-radius: 50%;
    background: var(--primary-soft); color: var(--primary); font-weight: 700;
    display: flex; align-items: center; justify-content: center; font-size: .9rem;
}
.card-head h3 { flex: 1; margin: 0; }
.card.done { padding: .75rem 1rem; }
.card.done .summary { color: var(--muted); font-size: .9rem; word-break: break-word; }
.pre { white-space: pre-wrap; }
.card.cancelled { opacity: .6; }

.picker-button {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    min-height: var(--touch); padding: .5rem .8rem;
    border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
    font: inherit; color: var(--text); cursor: pointer; text-align: right;
}
.picker-button .placeholder { color: var(--muted); }

.counter { display: flex; justify-content: space-between; gap: .5rem; color: var(--muted); font-size: .85rem; margin-top: .25rem; }

.source-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .75rem; }
.source-grid .btn { flex-direction: column; min-height: 76px; font-size: .95rem; line-height: 1.4; }
.source-grid .btn .ico { font-size: 1.4rem; }
.source-grid .btn.active { background: var(--primary-soft); border-color: var(--primary); }

/* key/value rows: counts and invoice */
.rows { margin: 0 0 .75rem; padding: 0; list-style: none; }
.rows li { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; border-bottom: 1px dashed var(--border); }
.rows li:last-child { border-bottom: 0; }
.rows li .v { font-weight: 700; }
.rows li.total { font-size: 1.05rem; }
.rows li.bad .v { color: var(--danger); }
.rows li.good .v { color: var(--success); }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.chip { padding: .15rem .6rem; border-radius: 999px; background: var(--bg); font-size: .85rem; }

.notes { margin: 0 0 .75rem; padding-right: 1.1rem; color: var(--muted); font-size: .9rem; }

/* ---------- sheets (sender picker, contacts) ---------- */

.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(15, 17, 30, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
    display: flex; flex-direction: column;
    width: 100%; max-width: 640px; height: 85vh; height: 85dvh;
    background: var(--surface);
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet.full { height: 100vh; height: 100dvh; border-radius: 0; }
.sheet-head { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
.sheet-head h2 { flex: 1; margin: 0; font-size: 1.05rem; }
.sheet-search { padding: .5rem .75rem; }
.sheet-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: .5rem .75rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; align-items: center; }

.list-row {
    display: flex; align-items: center; gap: .75rem;
    width: 100%; min-height: 60px; padding: .5rem 1rem;
    border: 0; border-bottom: 1px solid var(--border); background: var(--surface);
    font: inherit; color: var(--text); text-align: right; cursor: pointer;
}
.list-row:active { background: var(--bg); }
.list-row .main { flex: 1; min-width: 0; }
.list-row .main .sub { color: var(--muted); font-size: .85rem; }
.list-row .ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row.selected { background: var(--primary-soft); }

.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .8rem; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--primary-soft); color: var(--primary); }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty .ico { font-size: 2.5rem; }

/* ---------- OTP ---------- */

.otp { position: relative; display: flex; gap: .5rem; justify-content: center; direction: ltr; margin: 1rem 0; }
.otp .cell {
    width: 48px; height: 56px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface);
    display: flex; align-items: center; justify-content: center; font-size: 1.5rem; font-weight: 700;
}
.otp .cell.active { border-color: var(--primary); }
.otp input {
    position: absolute; inset: 0; width: 100%; height: 100%;
    opacity: 0; border: 0; font-size: 16px; caret-color: transparent; color: transparent; background: transparent;
}

/* ---------- menu ---------- */

.menu { position: absolute; top: 56px; left: .5rem; z-index: 30; min-width: 200px; background: var(--surface); color: var(--text); border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.18); overflow: hidden; }
.menu button, .menu a { display: block; width: 100%; min-height: var(--touch); padding: .6rem 1rem; border: 0; background: none; font: inherit; color: var(--text); text-align: right; text-decoration: none; cursor: pointer; }
.menu button:active, .menu a:active { background: var(--bg); }
.menu-backdrop { position: fixed; inset: 0; z-index: 25; }

/* ---------- detail ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border-radius: 12px; padding: .75rem .5rem; text-align: center; box-shadow: var(--shadow); }
.stat .n { font-size: 1.25rem; font-weight: 700; }
.stat.ok .n { color: var(--success); }
.stat.bad .n { color: var(--danger); }
.stat.wait .n { color: var(--warning); }

.message-text { white-space: pre-wrap; word-break: break-word; background: var(--bg); border-radius: 12px; padding: .75rem; }

/* ---------- Blazor ---------- */

#blazor-error-ui {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    padding: .75rem 1rem; background: var(--warning-soft); color: var(--warning);
    box-shadow: 0 -1px 4px rgba(0,0,0,.15);
}
#blazor-error-ui .reload { font-weight: 700; margin-right: .5rem; }
#blazor-error-ui .dismiss { float: left; cursor: pointer; padding: 0 .5rem; }

.blazor-error-boundary { background: var(--danger-soft); color: var(--danger); padding: 1rem; border-radius: 12px; }
.blazor-error-boundary::after { content: "خطایی رخ داد. لطفاً صفحه را دوباره باز کنید."; }

/* ---------- Dark liquid-glass theme (deep violet, purple buttons, emerald accents) ----------
   Frosted panels use backdrop-filter. Without support (old WebView) they fall back to solid dark. */

:root {
    --glass: rgba(255, 255, 255, .07);
    --glass-strong: rgba(255, 255, 255, .11);
    --glass-border: rgba(255, 255, 255, .14);
    --glass-shadow: 0 8px 24px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .1);
    --user-bubble: rgba(147, 51, 234, .38);
    --user-text: #f6f2ff;
    --accent: #34d399;
    --link: #d8b4fe;
}

html, body {
    background:
        radial-gradient(circle at 10% 6%, #3a1c70 0, transparent 46%),
        radial-gradient(circle at 95% 45%, #123f3a 0, transparent 40%),
        radial-gradient(circle at 12% 92%, #2a1458 0, transparent 46%),
        #0f0a1f;
    background-attachment: fixed;
}
.app { background: transparent; }

a, .link-btn, .btn-ghost { color: var(--link); }
.btn-secondary { color: var(--link); background: var(--glass); border-color: rgba(192, 132, 252, .5); }
.btn-danger { background: var(--danger-soft); }
.card-head .step { color: var(--link); }
.spinner.big { color: var(--link); }
.badge.info { color: var(--link); }
.alert-info { color: var(--link); }

.topbar {
    background: var(--glass-strong);
    color: var(--text);
    border-bottom: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}
.topbar .icon-btn { color: var(--text); }

.bubble.bot, .card, .stat, .quick-buttons, .menu, .sheet {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    color: var(--text);
}
.bubble.user {
    background: var(--user-bubble);
    color: var(--user-text);
    border: 1px solid rgba(192, 132, 252, .45);
    box-shadow: var(--glass-shadow);
}
.bubble.success { background: var(--success-soft); }
.bubble.error { background: var(--danger-soft); }

.quick-buttons { border-width: 1px 0 0; border-radius: 22px 22px 0 0; background: rgba(24, 16, 48, .78); }
.input, .textarea, .select, .picker-button { background: rgba(255, 255, 255, .07); color: var(--text); }
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.btn-primary { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 4px 14px rgba(147, 51, 234, .4); }
.list-row { background: transparent; }
.list-row:active { background: var(--glass); }
.menu button, .menu a { color: var(--text); }
.otp .cell { background: rgba(255, 255, 255, .07); color: var(--text); }
.stat.ok .n, .rows li.good .v { color: var(--accent); }
.overlay { background: rgba(5, 3, 14, .6); }
.sheet { background: #1a1333; }

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
    .topbar, .bubble.bot, .bubble.user, .card, .stat, .quick-buttons, .menu {
        -webkit-backdrop-filter: blur(16px) saturate(1.4);
        backdrop-filter: blur(16px) saturate(1.4);
    }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .topbar, .bubble.bot, .card, .stat, .quick-buttons, .menu { background: #1c1536; }
}

/* ---------- "back to home" button on every page opened from the menu ---------- */
.home-btn {
    display: inline-flex; align-items: center; gap: .3rem;
    min-height: 40px; padding: .2rem .8rem;
    border: 1px solid var(--glass-border); border-radius: 999px;
    background: var(--glass-strong); color: var(--text);
    font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.home-btn:active { background: var(--primary-soft); }

/* ---------- Confirm / continue / submit buttons: emerald green ---------- */
.btn-ok { background: #10b981; color: #fff; }
.btn-ok:not(:disabled):active { background: #059669; }
.btn-ok { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), 0 4px 14px rgba(16, 185, 129, .4); }
.btn-ok:disabled { box-shadow: none; }

/* ---------- on-screen keyboard (keyboard.js adds .kb while a field has focus) ----------
   Extra room below the page lets the focused box scroll above the keyboard even when the
   WebView does not shrink. The login/OTP pages stop centering so the form can scroll. */
body.kb .page { padding-bottom: 55vh; }
body.kb .page.center { justify-content: flex-start; }

/* ---------- home header: user + balance in one box, logout as a red square button ---------- */
.topbar.home-top {
    gap: .6rem; padding: .6rem .75rem; padding-top: calc(.6rem + env(safe-area-inset-top, 0px));
    background: transparent; border-bottom: 0; box-shadow: none;
    -webkit-backdrop-filter: none; backdrop-filter: none;
}
.user-box {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: .7rem;
    padding: .55rem .7rem; border-radius: 18px;
    background: var(--glass); border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow);
    -webkit-backdrop-filter: blur(16px) saturate(1.4); backdrop-filter: blur(16px) saturate(1.4);
}
.avatar {
    flex: none; width: 46px; height: 46px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    background: #10b981; color: #fff; font-size: 1.3rem; font-weight: 700;
    box-shadow: 0 4px 14px rgba(16, 185, 129, .4);
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-balance { font-size: .9rem; display: flex; flex-wrap: wrap; gap: .1rem .6rem; align-items: baseline; }
.user-balance .amount { color: #34d399; font-weight: 700; }
.user-balance .gift { color: var(--muted); font-size: .8rem; }
.refresh-btn {
    flex: none; width: 36px; height: 36px; border: 0; border-radius: 10px;
    background: rgba(255, 255, 255, .08); color: var(--text); font-size: 1.1rem; cursor: pointer;
}
.logout-btn {
    flex: none; width: 56px; height: 56px; border-radius: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    background: rgba(239, 68, 68, .14); border: 1px solid rgba(239, 68, 68, .5); color: #ff7b7b;
}
.logout-btn:active { background: rgba(239, 68, 68, .28); }
