/* =========================================================
   Mobile-first UI overlay — صندوق خيري الدفعة 50
   يُحمَّل بعد style.css ويُحسِّن كل الصفحات دون كسر الإعدادات
   ========================================================= */

:root {
    --touch-min: 44px;
    --app-radius: 16px;
    --app-radius-sm: 12px;
    --app-gap: 0.85rem;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-drawer-bg: #0b1220;
    --bottom-nav-h: 64px;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    overflow-x: hidden;
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 0.5rem);
}

body.nav-open {
    overflow: hidden;
}

*,
*::before,
*::after {
    -webkit-tap-highlight-color: transparent;
}

a,
button,
input,
select,
textarea,
label,
.nav-item {
    touch-action: manipulation;
}

img,
svg,
video {
    max-width: 100%;
    height: auto;
}

/* منع تكبير iOS عند التركيز على الحقول */
input,
select,
textarea,
button {
    font-size: 16px;
    max-width: 100%;
}

/* ---------- الهيدر ---------- */
header {
    position: sticky !important;
    top: 0;
    z-index: 1200;
    padding-top: max(0.55rem, var(--safe-top));
}

nav {
    flex-direction: row !important;
    align-items: center !important;
    gap: 0.5rem !important;
    width: 100%;
}

.logo {
    min-width: 0;
    flex: 1;
    font-size: clamp(0.82rem, 3.6vw, 1.05rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logo img {
    height: 28px !important;
    width: auto;
    flex-shrink: 0;
}

/* زر الهامبرغر */
.nav-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-left: 0;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(250, 204, 21, 0.65);
    border-radius: 12px;
    color: #facc15;
    cursor: pointer;
    padding: 0;
    gap: 5px;
    flex-direction: column;
}

.nav-toggle-bar {
    display: block;
    width: 18px;
    height: 2px;
    background: #facc15;
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

body.nav-open .nav-toggle-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
body.nav-open .nav-toggle-bar:nth-child(2) {
    opacity: 0;
}
body.nav-open .nav-toggle-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.nav-toggle-dots {
    display: none;
}

.nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.55);
    z-index: 1190;
    backdrop-filter: blur(2px);
}

.nav-backdrop.show {
    display: block;
}

header .nav-menu,
.nav-menu {
    position: fixed;
    top: 0;
    right: 0;
    width: min(86vw, 360px);
    height: 100dvh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    padding: calc(4.4rem + var(--safe-top)) 1rem calc(1.25rem + var(--safe-bottom));
    background: var(--nav-drawer-bg);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.35);
    transform: translateX(110%);
    transition: transform 0.28s ease;
    overflow-y: auto;
    z-index: 1210;
}

header .nav-menu.active,
.nav-menu.active {
    display: flex;
    transform: translateX(0);
}

.nav-group {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    width: 100%;
}

.nav-item,
.nav-links a,
#theme-toggle {
    width: 100%;
    min-height: var(--touch-min);
    justify-content: flex-start;
    padding: 0.75rem 0.9rem;
    margin: 0;
    border-radius: 12px;
    font-size: 0.95rem;
    background: rgba(255, 255, 255, 0.04);
}

.nav-item form,
form.nav-item {
    display: flex;
    width: 100%;
    gap: 0.4rem;
    align-items: center;
    padding: 0.45rem;
}

form.nav-item input[type="text"] {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    border-radius: 10px;
    padding: 0.45rem 0.7rem;
}

form.nav-item .btn {
    min-height: 40px;
    padding: 0.4rem 0.75rem;
}

.dropdown {
    width: 100%;
}

.dropdown-toggle {
    width: 100%;
    padding-inline: 0.9rem;
}

.nav-admin {
    width: 100%;
}

.dropdown-menu {
    position: static;
    display: none;
    min-width: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.06);
    box-shadow: none;
    border-radius: 12px;
    margin-top: 0.25rem;
    overflow: hidden;
}

.dropdown:hover .dropdown-menu {
    display: none;
}

.dropdown.open .dropdown-menu {
    display: block;
}

.dropdown-menu a {
    color: #f8fafc;
    padding: 0.85rem 1rem;
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.news-ticker {
    max-width: none;
    margin: 0.45rem 0.75rem 0.15rem;
    border-radius: 10px;
}

/* ---------- شريط سفلي ---------- */
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: #0b1220;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.28rem 0.2rem calc(0.28rem + var(--safe-bottom));
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.28);
}

.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: 52px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 700;
    border-radius: 10px;
}

.bottom-nav a i {
    font-size: 1.05rem;
}

.bottom-nav a.active,
.bottom-nav a:hover {
    color: #facc15;
    background: rgba(250, 204, 21, 0.08);
}

/* ---------- الصفحة الرئيسية ---------- */
main,
main.container,
.container {
    width: 100%;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 0.85rem;
    padding-right: 0.85rem;
}

.home-hero,
.hero {
    padding: 1.35rem 1rem 1.5rem !important;
    border-radius: 18px !important;
    margin-top: 0.85rem;
    margin-bottom: 1rem;
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.28);
}

.hero h1,
.home-hero h1 {
    font-size: clamp(1.15rem, 5.4vw, 1.55rem);
    line-height: 1.45;
    margin-bottom: 0.55rem;
}

.hero p,
.home-hero p {
    font-size: 0.92rem;
    line-height: 1.7;
    margin-bottom: 0.85rem;
}

.home-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
}

.stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
}

.stat-card {
    padding: 0.95rem 0.7rem !important;
    border-radius: 14px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.stat-card:hover {
    transform: none;
}

.stat-card i {
    font-size: 1.25rem;
    margin-bottom: 0.4rem;
}

.stat-card h3 {
    font-size: 0.78rem;
    margin-bottom: 0.35rem;
    color: var(--ink, #17211c);
}

.stat-card .amount,
.stat-card p.amount {
    font-size: 0.92rem !important;
    font-weight: 800;
    word-break: break-word;
}

.stat-card .sub-amount {
    font-size: 0.72rem;
}

.home-main-column .stats-grid {
    margin-top: 0.4rem;
}

.home-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
    margin-top: 1rem;
}

.home-actions .btn,
.home-actions a.btn {
    flex: none !important;
    max-width: none !important;
    width: 100%;
    min-height: 76px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    border-radius: 16px;
    padding: 0.85rem 0.55rem;
    font-size: 0.86rem;
    line-height: 1.35;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.16);
}

.home-actions .btn i {
    font-size: 1.15rem;
}

.home-vodafone {
    padding: 1.15rem !important;
    border-radius: 18px;
}

.home-vodafone h2 {
    font-size: 1rem;
    margin-bottom: 0.7rem;
}

.home-vodafone-number {
    font-size: clamp(1.05rem, 5.5vw, 1.55rem) !important;
    letter-spacing: 0.04em !important;
    display: block !important;
    width: 100%;
    padding: 0.7rem 0.6rem !important;
    border-radius: 14px !important;
    overflow-wrap: anywhere;
}

.home-vodafone-qr {
    width: min(220px, 70vw) !important;
    height: auto !important;
}

/* ---------- البطاقات والنماذج ---------- */
.card,
.lookup-form,
.result-card,
.form-container,
.user-form,
.edit-form,
.profile-section,
.logs-section,
.bulk-analyze,
.add-transaction,
.analyze-sms {
    width: 100%;
    margin: 0.85rem auto;
    padding: 1.15rem;
    border-radius: var(--app-radius);
}

.card h1,
.card h2,
.lookup-wrap h1 {
    font-size: 1.15rem;
    line-height: 1.45;
    margin-bottom: 0.7rem;
}

.card p.description {
    font-size: 0.92rem;
    line-height: 1.75;
    margin-bottom: 1rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    font-size: 0.92rem;
    margin-bottom: 0.4rem;
}

.form-group input,
.form-group select,
.form-group textarea,
.form-control,
.transaction-form input,
.transaction-form select,
.transaction-form textarea,
.login-form input,
.lookup-form input,
.lookup-form select {
    width: 100%;
    min-height: 48px;
    padding: 0.75rem 0.9rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--input-bg, #fff);
    color: var(--text-color);
}

.form-group textarea,
.transaction-form textarea {
    min-height: 120px;
    resize: vertical;
}

.btn,
.btn-primary,
.btn-secondary,
.btn-danger,
button.btn-primary,
.transaction-form button,
.lookup-form button,
.login-form button {
    min-height: var(--touch-min);
    border-radius: 12px;
    font-weight: 700;
}

.page-form .btn-primary,
.page-form button.btn-primary,
.page-auth .btn-primary,
.lookup-form .btn-primary,
.transaction-form .btn-primary,
.transaction-form button[type="submit"] {
    width: 100%;
    justify-content: center;
}

.btn-group {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.55rem;
}

.btn-group .btn,
.btn-group a {
    width: 100%;
    justify-content: center;
}

.success-banner {
    flex-wrap: wrap;
}

.detail-list {
    background: rgba(15, 23, 42, 0.04);
    border-radius: 12px;
    padding: 0.85rem 1rem;
}

.code-box {
    word-break: break-all;
}

/* ---------- الجداول ---------- */
.table-container,
.table-responsive,
.users-table,
.transactions-tables,
.loans-table,
.cases-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.table-container .btn,
table .btn,
.tr-bulk-toolbar-btns .btn,
.tr-bulk-toolbar-btns button {
    min-height: 40px;
}

table {
    min-width: 640px;
}

.pagination {
    flex-wrap: wrap;
}

.pagination a {
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
}

/* ---------- صفحات الإدارة ---------- */
.dashboard {
    margin: 0.85rem auto;
}

.dashboard-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
}

.dashboard-header-balance {
    text-align: right;
    width: 100%;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 0.8rem 1rem;
}

.actions-list {
    grid-template-columns: 1fr 1fr;
}

.actions-list .btn {
    min-height: 52px;
    font-size: 0.82rem;
}

.settings-row,
.settings-grid,
.permissions-list,
.icon-picker,
.icon-tab-panel.active {
    grid-template-columns: 1fr;
}

.chat-container {
    grid-template-columns: 1fr;
    height: auto;
    margin: 0.75rem auto;
}

.modal-content {
    width: 94%;
    margin: 12% auto;
    padding: 1.15rem;
    max-height: 85dvh;
    overflow: auto;
}

/* ---------- الفوتر ---------- */
footer {
    padding-bottom: 0.75rem;
    font-size: 0.8rem;
}

/* ---------- الوضع الداكن ---------- */
body.dark-mode,
html.dark-mode body.dark-mode,
body[data-theme="dark"] {
    --card-bg: #1e2430;
    --input-bg: #151b26;
    --border-color: #334155;
    --text-color: #f1f5f9;
}

body.dark-mode .card,
body.dark-mode .lookup-form,
body.dark-mode .result-card,
body.dark-mode .form-container,
body.dark-mode .profile-section,
body.dark-mode .logs-section,
body.dark-mode .user-form,
body.dark-mode .edit-form,
body.dark-mode .stat-card,
body.dark-mode .dashboard-header-balance {
    background: #1e2430;
    color: #f1f5f9;
}

body.dark-mode .card h1,
body.dark-mode .card h2 {
    color: #93c5fd;
}

body.dark-mode .card p.description,
body.dark-mode .home-vodafone .description {
    color: #cbd5e1;
}

.dark-mode .bottom-nav,
[data-theme="dark"] .bottom-nav {
    background: #020617;
}

/* ---------- شاشات أوسع من الهاتف ---------- */
@media (min-width: 768px) {
    body {
        padding-bottom: 0;
    }

    .bottom-nav {
        display: none;
    }

    .nav-toggle,
    .nav-backdrop {
        display: none !important;
    }

    header .nav-menu,
    .nav-menu {
        position: static;
        width: auto;
        height: auto;
        max-height: none;
        flex-direction: row;
        align-items: center;
        padding: 0;
        background: transparent;
        box-shadow: none;
        transform: none;
        overflow: visible;
    }

    .nav-group {
        flex-direction: row;
        align-items: center;
        width: auto;
    }

    .nav-item,
    .nav-links a,
    #theme-toggle {
        width: auto;
        min-height: 0;
        background: none;
        font-size: 0.85rem;
        padding: 0.4rem 0.8rem;
    }

    form.nav-item {
        width: auto;
    }

    .dropdown,
    .nav-admin {
        width: auto;
    }

    .dropdown-menu {
        position: absolute;
        display: none;
        min-width: 220px;
        background: #fff;
        box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
    }

    .dropdown:hover .dropdown-menu,
    .dropdown.open .dropdown-menu {
        display: block;
    }

    .dropdown-menu a {
        color: var(--text-color);
        min-height: 0;
    }

    .home-grid {
        grid-template-columns: 1.4fr 0.8fr 0.8fr;
    }

    .home-actions {
        display: flex !important;
        flex-wrap: wrap;
        justify-content: center;
    }

    .home-actions .btn,
    .home-actions a.btn {
        width: auto;
        min-height: 44px;
        flex-direction: row;
        max-width: 260px !important;
        flex: 1 1 220px !important;
    }

    .btn-group {
        display: flex;
        grid-template-columns: none;
    }

    .btn-group .btn,
    .btn-group a {
        width: auto;
    }

    .page-form .btn-primary,
    .transaction-form button[type="submit"] {
        width: auto;
        min-width: 200px;
    }

    .card,
    .lookup-form,
    .result-card {
        padding: 1.75rem;
    }
}

@media (min-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 380px) {
    .home-grid,
    .stats-grid,
    .home-actions,
    .actions-list {
        grid-template-columns: 1fr;
    }

    .bottom-nav a span {
        font-size: 0.62rem;
    }
}
