/* PortBot — RTL Telegram Mini App styles */
:root {
    --bg: var(--tg-theme-bg-color, #f2f3f7);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #ffffff);
    --section-bg: var(--tg-theme-section-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #17181c);
    --hint: var(--tg-theme-hint-color, #8b909a);
    --button: var(--tg-theme-button-color, #2b7fff);
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --link: var(--tg-theme-link-color, #2b7fff);
    --accent: var(--tg-theme-accent-text-color, #2b7fff);
    --destructive: var(--tg-theme-destructive-text-color, #e5484d);
    --success: #16a34a;
    --warning: #d97706;
    --border: rgba(0, 0, 0, .09);
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 18, 27, .06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --border: rgba(255, 255, 255, .1);
        --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    }
}

@font-face {
    font-family: 'Vazirmatn';
    src: local('Vazirmatn'), local('Vazir');
    font-display: swap;
}

* { box-sizing: border-box; }

/* The layout rules below set `display` on .modal / .bottom-nav / .toast, which
   would otherwise override the `hidden` attribute and leave invisible
   overlays intercepting every tap. Keep this guard. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Vazirmatn', 'Segoe UI', Tahoma, 'Iranian Sans', sans-serif;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    max-width: 640px;
    margin: 0 auto;
    padding: 12px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.app-header__title { font-weight: 700; font-size: 16px; }
.app-header__user { font-size: 12px; color: var(--hint); }

.app-main {
    max-width: 640px;
    margin: 0 auto;
    padding: 12px 12px 96px;
}

h2 { font-size: 17px; margin: 6px 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }

.card {
    background: var(--section-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    margin-bottom: 12px;
}

.card--balance { text-align: center; padding: 20px 14px; }
.card--balance .balance-value { font-size: 28px; font-weight: 800; margin: 6px 0; }
.card--balance .balance-label { color: var(--hint); font-size: 13px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row--wrap { flex-wrap: wrap; }
.muted { color: var(--hint); font-size: 12.5px; }
.small { font-size: 12px; }
.mt { margin-top: 10px; }
.mb { margin-bottom: 10px; }
.grow { flex: 1; }
.center { text-align: center; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid transparent;
    font-size: 14.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    background: var(--secondary-bg);
    color: var(--text);
    transition: opacity .15s ease;
}
.btn:active { opacity: .8; }
.btn:disabled { opacity: .5; cursor: default; }
.btn--primary { background: var(--button); color: var(--button-text); }
.btn--ghost { background: transparent; border-color: var(--border); }
.btn--danger { background: transparent; border-color: var(--destructive); color: var(--destructive); }
.btn--success { background: var(--success); color: #fff; }
.btn--small { width: auto; padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-grid--3 { grid-template-columns: repeat(3, 1fr); }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: var(--secondary-bg);
    border: 1px solid var(--border);
}
.badge--active { color: var(--success); border-color: var(--success); }
.badge--suspended { color: var(--warning); border-color: var(--warning); }
.badge--deleted { color: var(--destructive); border-color: var(--destructive); }
.badge--pending { color: var(--warning); border-color: var(--warning); }
.badge--confirmed { color: var(--success); border-color: var(--success); }
.badge--review { color: var(--destructive); border-color: var(--destructive); }

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: 0; }
.list-item__main { flex: 1; min-width: 0; }
.list-item__title { font-weight: 600; font-size: 14px; }
.list-item__sub { color: var(--hint); font-size: 12px; margin-top: 3px; }

.input, select, textarea {
    width: 100%;
    padding: 11px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--secondary-bg);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
}
.input:focus, select:focus, textarea:focus { outline: 2px solid var(--button); outline-offset: 1px; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12.5px; color: var(--hint); margin-bottom: 5px; }

.copy-value {
    direction: ltr;
    text-align: left;
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 13px;
    background: var(--secondary-bg);
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 10px;
    word-break: break-all;
    user-select: all;
    cursor: copy;
}

.warning-box {
    background: rgba(217, 119, 6, .12);
    border: 1px solid rgba(217, 119, 6, .4);
    color: var(--text);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 12.5px;
    line-height: 1.8;
}
.info-box {
    background: rgba(43, 127, 255, .1);
    border: 1px solid rgba(43, 127, 255, .35);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 12.5px;
    line-height: 1.8;
}

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
    background: var(--section-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}
.stat__label { color: var(--hint); font-size: 12px; }
.stat__value { font-size: 18px; font-weight: 800; margin-top: 4px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; }
.tab {
    white-space: nowrap;
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--secondary-bg);
    font-size: 13px;
    cursor: pointer;
}
.tab--active { border-color: var(--button); color: var(--button); font-weight: 700; }

.bottom-nav {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    z-index: 30;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    background: var(--section-bg);
    border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.bottom-nav button {
    background: none;
    border: 0;
    color: var(--hint);
    font-family: inherit;
    font-size: 11.5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 4px;
    cursor: pointer;
}
.bottom-nav button.active { color: var(--button); font-weight: 700; }
.bottom-nav .nav-icon { font-size: 19px; line-height: 1; }

.toast {
    position: fixed;
    top: 14px;
    right: 50%;
    transform: translateX(50%);
    z-index: 100;
    max-width: 90vw;
    padding: 11px 16px;
    border-radius: 12px;
    background: #222;
    color: #fff;
    font-size: 13px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.toast--error { background: var(--destructive); }
.toast--success { background: var(--success); }

.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.modal__panel {
    position: relative;
    width: 100%;
    max-width: 640px;
    max-height: 86vh;
    overflow-y: auto;
    background: var(--bg);
    border-radius: 18px 18px 0 0;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
}

.skeleton { color: var(--hint); text-align: center; padding: 40px 0; }
.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--border);
    border-top-color: var(--button);
    border-radius: 50%;
    margin: 24px auto;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.timeline { border-right: 2px solid var(--border); margin-right: 6px; padding-right: 12px; }
.timeline__item { position: relative; padding-bottom: 12px; font-size: 12.5px; }
.timeline__item::before {
    content: '';
    position: absolute;
    right: -17px;
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--button);
}

.empty { text-align: center; color: var(--hint); padding: 28px 10px; font-size: 13px; }
