@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #0b0f1a;
    --surface: #131a2b;
    --surface-2: #1a2338;
    --border: #232d47;
    --text: #eef1f8;
    --text-muted: #93a0bd;
    --primary: #5b8bff;
    --primary-dark: #7ba0ff;
    --primary-tint: #16223f;
    --success: #34d576;
    --success-tint: #10281c;
    --danger: #ff5a63;
    --danger-tint: #33161a;
    --warning: #f2b13d;
    --warning-tint: #332411;
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
    --nav-h: 68px;
    --header-h: 56px;
}

/* Dark is the default look for this app; explicit opt-in to light stays available
   (e.g. if Telegram reports colorScheme === 'light', miniapp.js sets this attribute). */
[data-theme="light"] {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f0f2f8;
    --border: #e4e8f1;
    --text: #171f36;
    --text-muted: #6b7280;
    --primary: #2f6fed;
    --primary-dark: #1e4fc4;
    --primary-tint: #eaf1ff;
    --success: #16a34a;
    --success-tint: #e9fbef;
    --danger: #e0313e;
    --danger-tint: #fdeced;
    --warning: #d97706;
    --warning-tint: #fff6e6;
    --shadow: 0 8px 24px rgba(23, 31, 54, 0.06);
    --shadow-lg: 0 16px 40px rgba(23, 31, 54, 0.14);
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Vazirmatn', Tahoma, 'Segoe UI', sans-serif;
    -webkit-tap-highlight-color: transparent;
}
body { direction: rtl; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

.app-shell { max-width: 560px; margin: 0 auto; min-height: 100vh; position: relative; padding-bottom: calc(var(--nav-h) + 12px); }

/* ---------- Top header ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    height: var(--header-h);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 800; font-size: 16px; }
.topbar .icon-btn {
    width: 38px; height: 38px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface); border: 1px solid var(--border); cursor: pointer; position: relative;
}
.badge-dot {
    position: absolute; top: -2px; left: -2px; min-width: 16px; height: 16px; border-radius: 8px;
    background: var(--danger); color: #fff; font-size: 10px; display: flex; align-items: center; justify-content: center;
    padding: 0 4px; font-weight: 700;
}

/* ---------- Sections & Cards ---------- */
.view { display: none; padding: 16px; animation: fadeIn .2s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 14px;
}
.card-title { font-weight: 700; font-size: 15px; margin: 0 0 4px; }
.card-sub { color: var(--text-muted); font-size: 13px; margin: 0; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 14px; box-shadow: var(--shadow);
}
.stat-card .value { font-size: 20px; font-weight: 800; }
.stat-card .label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.banner {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff; border-radius: var(--radius-lg); padding: 16px; margin-bottom: 14px;
    box-shadow: var(--shadow-lg);
}
.banner p { margin: 0 0 12px; font-size: 13.5px; line-height: 1.9; }
.banner-actions { display: flex; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: none; border-radius: var(--radius-md); padding: 11px 16px;
    font-weight: 700; font-size: 13.5px; cursor: pointer; transition: transform .1s ease, opacity .15s ease;
    width: 100%;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid rgba(255,255,255,0.7); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 12.5px; width: auto; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.field input, .field select, .field textarea {
    width: 100%; padding: 12px 14px; border-radius: var(--radius-md); border: 1.5px solid var(--border);
    background: var(--surface); color: var(--text); font-size: 14px; outline: none; transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
.field-error { font-size: 11.5px; color: var(--danger); margin-top: 5px; }
.field.has-error input { border-color: var(--danger); }

/* ---------- Lists / rows ---------- */
.list-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 0; border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.row-title { font-weight: 700; font-size: 14px; }
.row-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.chip-success { background: var(--success-tint); color: var(--success); }
.chip-danger { background: var(--danger-tint); color: var(--danger); }
.chip-warning { background: var(--warning-tint); color: var(--warning); }
.chip-muted { background: var(--surface-2); color: var(--text-muted); }

.progress-track { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width .3s; }
.progress-fill.full { background: var(--danger); }
.progress-fill.near { background: var(--warning); }

/* ---------- Bottom nav ---------- */
.bottom-nav {
    position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
    width: 100%; max-width: 560px; height: var(--nav-h);
    background: var(--surface); border-top: 1px solid var(--border);
    display: flex; z-index: 30;
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
    flex: 1; background: none; border: none; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 4px; color: var(--text-muted); font-size: 10.5px; cursor: pointer; font-weight: 600;
}
.bottom-nav button svg { width: 22px; height: 22px; }
.bottom-nav button.active { color: var(--primary); }
.fab {
    position: absolute; top: -22px; left: 50%; transform: translateX(-50%);
    width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-lg); border: 4px solid var(--bg);
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(10, 14, 25, 0.55); display: none; align-items: flex-end;
    justify-content: center; z-index: 100;
}
.modal-overlay.active { display: flex; }
.modal-sheet {
    background: var(--surface); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0;
    padding: 20px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg);
    animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-handle { width: 42px; height: 4px; background: var(--border); border-radius: 4px; margin: 0 auto 14px; }
.modal-title { font-weight: 800; font-size: 16px; margin-bottom: 14px; }
.summary-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; }
.summary-row span:first-child { color: var(--text-muted); }
.summary-row strong { font-weight: 700; }

/* ---------- Toast ---------- */
#toast-container { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; width: calc(100% - 32px); max-width: 520px; }
.toast {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 12px 16px; box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 600;
    display: flex; align-items: center; gap: 8px; animation: toastIn .2s ease;
}
.toast.success { border-inline-start: 4px solid var(--success); }
.toast.error { border-inline-start: 4px solid var(--danger); }
.toast.info { border-inline-start: 4px solid var(--primary); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px);} to { opacity: 1; transform: translateY(0);} }

/* ---------- Skeleton ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-line { height: 14px; margin-bottom: 8px; border-radius: 6px; }
.skeleton-card { height: 76px; border-radius: var(--radius-lg); margin-bottom: 12px; }

/* ---------- Empty states ---------- */
.empty-state { text-align: center; padding: 40px 16px; color: var(--text-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 10px; }
.empty-state p { margin: 0; font-size: 13.5px; }

/* ---------- Search ---------- */
.search-box { position: relative; margin-bottom: 12px; }
.search-box input { padding-inline-start: 40px; }
.search-box .search-icon { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); opacity: .5; }

.section-title { font-size: 13px; font-weight: 700; color: var(--text-muted); margin: 18px 0 10px; text-transform: uppercase; letter-spacing: .04em; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.hidden { display: none !important; }

.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; }
.auth-logo { text-align: center; font-size: 22px; font-weight: 800; margin-bottom: 24px; color: var(--primary); }
.tg-user-preview { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: var(--radius-md); padding: 10px 12px; margin-bottom: 16px; }
.tg-user-preview img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.tg-user-preview .avatar-fallback { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }

.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
.spinner.dark { border: 2.5px solid var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
