/* ==========================================
   YM Bills — Stylesheet
   ========================================== */

:root {
    --primary:       #3b82f6;
    --primary-dark:  #2563eb;
    --primary-glow:  rgba(59,130,246,0.25);
    --purple:        #8b5cf6;
    --dark-bg:       #080d14;
    --card-bg:       #0e1420;
    --elevated:      #162030;
    --border:        #1e2d42;
    --border-light:  #243654;
    --text:          #e2eaf4;
    --text-dim:      #7a92b0;
    --danger:        #ef4444;
    --danger-dark:   #dc2626;
    --success:       #22c55e;
    --warning:       #f59e0b;
    --radius:        10px;
    --radius-lg:     14px;
    --shadow:        0 4px 24px rgba(0,0,0,0.5);
    --shadow-xl:     0 12px 48px rgba(0,0,0,0.7);
    --ease:          0.2s ease;
    --nav-h:         64px;
    --safe-bottom:   env(safe-area-inset-bottom, 0px);
    --safe-top:      env(safe-area-inset-top, 0px);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
    min-height: 100%;
    -webkit-text-size-adjust: 100%;
    overflow-y: scroll; /* يضمن وجود scrollbar دائماً ويمنع القفز */
}
body {
    width: 100%;
    overflow-x: hidden;   /* نخفي الـ horizontal overflow على body فقط */
    font-family: 'Tajawal', sans-serif;
    background: var(--dark-bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.65;
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(59,130,246,0.07) 0%, transparent 55%),
        radial-gradient(ellipse at 80% 100%, rgba(139,92,246,0.06) 0%, transparent 55%);
    background-attachment: fixed;
    -webkit-tap-highlight-color: transparent;
    -webkit-overflow-scrolling: touch;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--dark-bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3a5070; }

/* ==========================================
   HEADER
   ========================================== */
.app-header {
    background: rgba(8,13,20,0.96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: sticky; top: 0; z-index: 100;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 30px rgba(0,0,0,0.6);
    padding: 0.7rem 0;
    padding-top: calc(0.7rem + var(--safe-top));
}

.header-brand {
    display: flex; align-items: center; gap: 10px;
}

.header-logo {
    width: 38px; height: 38px;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid rgba(59,130,246,0.4);
    box-shadow: 0 0 16px rgba(59,130,246,0.25);
    flex-shrink: 0;
}
.header-logo img { width: 100%; height: 100%; object-fit: cover; }

.header-title {
    font-size: 1.15rem; font-weight: 800;
    background: linear-gradient(90deg, var(--primary), var(--purple));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ==========================================
   LOGIN
   ========================================== */
.login-wrap {
    min-height: calc(100vh - 60px);
    display: flex; align-items: center; justify-content: center;
    padding: 2rem 1rem;
}

.login-card {
    width: 100%; max-width: 430px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: 2.5rem;
    animation: fadeUp 0.4s ease;
}

.login-logo-wrap {
    display: flex; flex-direction: column;
    align-items: center; gap: 0.75rem;
    margin-bottom: 2.25rem;
}

.login-logo-img {
    width: 90px; height: 90px;
    border-radius: 22px;
    overflow: hidden;
    border: 3px solid rgba(59,130,246,0.4);
    box-shadow: 0 0 40px rgba(59,130,246,0.3), 0 0 80px rgba(139,92,246,0.15);
}
.login-logo-img img { width: 100%; height: 100%; object-fit: cover; }

.login-title { font-size: 1.6rem; font-weight: 800; color: var(--primary); }
.login-sub   { font-size: 0.85rem; color: var(--text-dim); margin-top: -4px; }

/* ==========================================
   STATS
   ========================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    display: flex; align-items: center; gap: 0.85rem;
    transition: transform var(--ease), box-shadow var(--ease), border-color var(--ease);
    position: relative; overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(135deg, transparent 60%, rgba(255,255,255,0.02));
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
    border-color: var(--border-light);
}

.stat-icon {
    width: 46px; height: 46px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}
.stat-icon.blue   { background: rgba(59,130,246,0.15);  }
.stat-icon.green  { background: rgba(34,197,94,0.15);   }
.stat-icon.red    { background: rgba(239,68,68,0.15);   }
.stat-icon.purple { background: rgba(139,92,246,0.15);  }
.stat-icon.yellow { background: rgba(245,158,11,0.15);  }

.stat-value { font-size: 1.45rem; font-weight: 800; line-height: 1.1; }
.stat-label { font-size: 0.77rem; color: var(--text-dim); font-weight: 500; margin-top: 3px; }

/* ==========================================
   PROFIT BAR
   ========================================== */
.profit-bar {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.4rem;
    margin-bottom: 1.25rem;
    display: flex; flex-wrap: wrap;
    align-items: center; gap: 1rem;
    justify-content: space-between;
}

.profit-filters { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.profit-filters label { font-weight: 700; color: var(--text); white-space: nowrap; font-size: 0.9rem; }

.profit-totals { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.profit-item   { text-align: center; }
.profit-label  { font-size: 0.75rem; color: var(--text-dim); display: block; margin-bottom: 2px; }
.profit-value  { font-size: 1rem; font-weight: 800; }
.profit-divider { width: 1px; height: 30px; background: var(--border); flex-shrink: 0; }

/* ==========================================
   INVOICE → SUBSCRIPTION SECTION
   ========================================== */
.sub-toggle-wrap {
    margin-top: 1.1rem;
    padding: 0.75rem 1rem;
    background: rgba(59,130,246,0.06);
    border: 1px dashed rgba(59,130,246,0.35);
    border-radius: var(--radius);
}
.sub-toggle-label {
    display: flex; align-items: center; gap: 0.6rem;
    cursor: pointer; font-weight: 700; color: var(--text); font-size: 0.9rem;
}
.inv-sub-section {
    margin-top: 0.85rem;
    padding: 1rem 1.1rem;
    background: rgba(59,130,246,0.05);
    border: 1px solid rgba(59,130,246,0.2);
    border-radius: var(--radius);
}
.sub-note {
    margin-top: 0.75rem;
    font-size: 0.78rem;
    color: var(--success);
    font-weight: 600;
}

/* ==========================================
   GLOBAL SEARCH
   ========================================== */
.search-group-title {
    padding: 0.45rem 1rem;
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--elevated);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.search-result-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background var(--ease);
}
.search-result-item:hover { background: var(--elevated); }
.search-result-main {
    display: flex; align-items: center; gap: 0.6rem;
    margin-bottom: 0.25rem;
}
.search-result-id {
    font-size: 0.75rem; font-weight: 800;
    color: var(--primary); background: rgba(59,130,246,0.12);
    padding: 0.1rem 0.5rem; border-radius: 6px;
    font-family: monospace;
}
.search-result-name { font-size: 0.9rem; font-weight: 700; color: var(--text); }
.search-result-sub {
    display: flex; gap: 1rem; flex-wrap: wrap;
    font-size: 0.75rem; color: var(--text-dim);
}

/* تمييز صف بعد البحث */
@keyframes highlightPulse {
    0%,100% { background: transparent; }
    30%      { background: rgba(59,130,246,0.18); }
}
tr.highlight-row { animation: highlightPulse 2s ease; }

/* ==========================================
   STATISTICS SECTION
   ========================================== */
.stats-compare-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}
@media (max-width: 768px) { .stats-compare-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .stats-compare-grid { grid-template-columns: 1fr 1fr; } }

.compare-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    text-align: center;
}
.compare-label { font-size: 0.78rem; color: var(--text-dim); margin-bottom: 0.4rem; font-weight: 600; }
.compare-value { font-size: 1.3rem; font-weight: 800; margin-bottom: 0.3rem; }
.compare-value.green { color: #4ade80; }
.compare-value.blue  { color: #60a5fa; }
.compare-value.red   { color: #f87171; }
.compare-sub { font-size: 0.75rem; color: var(--text-dim); }

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.25rem;
    margin-bottom: 0;
}
@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }

.chart-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem 1.4rem;
}
.chart-title { font-size: 0.9rem; font-weight: 700; color: var(--text); margin-bottom: 1rem; }
.chart-wrap    { position: relative; height: 260px; }
.chart-wrap-sm { position: relative; height: 240px; }

/* ==========================================
   INVOICE STATUS BADGES
   ========================================== */
.inv-status {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
}
.inv-status.paid      { background: rgba(34,197,94,0.15);  color: #4ade80; border: 1px solid rgba(74,222,128,0.3); }
.inv-status.pending   { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(251,191,36,0.3); }
.inv-status.cancelled { background: rgba(239,68,68,0.15);  color: #f87171; border: 1px solid rgba(248,113,113,0.3); }
.inv-status.refunded  { background: rgba(139,92,246,0.15); color: #c084fc; border: 1px solid rgba(192,132,252,0.3); }

/* صف ملغي/مرتجع — خافت */
tr.row-inactive td { opacity: 0.55; }
tr.row-inactive td:last-child { opacity: 1; }

/* ==========================================
   BACKUP BAR
   ========================================== */
.backup-bar {
    background: rgba(14,20,32,0.6);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.55rem 1.2rem;
    margin-bottom: 1.1rem;
    display: flex; flex-wrap: wrap;
    align-items: center; gap: 0.75rem;
    justify-content: space-between;
}
.backup-bar-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-dim);
}
.backup-bar-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.btn-discord {
    background: #5865F2;
    color: #fff;
    border: none;
}
.btn-discord:hover { background: #4752c4; }

.btn-wa {
    background: #25d366;
    color: #fff;
    border: none;
}
.btn-wa:hover { background: #1ebe5a; }

/* ==========================================
   NAV TABS — Desktop top bar
   ========================================== */
.nav-tabs-wrapper {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 5px;
    display: flex; gap: 4px;
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.admin-tab {
    padding: 0.55rem 1.15rem;
    font-size: 0.88rem; font-weight: 700;
    font-family: 'Tajawal', sans-serif;
    cursor: pointer; border-radius: 7px;
    border: none; background: transparent;
    color: var(--text-dim);
    white-space: nowrap; flex-shrink: 0;
    transition: all var(--ease);
    -webkit-tap-highlight-color: transparent;
}
.admin-tab:hover  { background: var(--elevated); color: var(--text); }
.admin-tab.active {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
    box-shadow: 0 2px 14px var(--primary-glow);
}

/* ==========================================
   SECTION HEADER
   ========================================== */
.section-header {
    display: flex; justify-content: space-between;
    align-items: center; flex-wrap: wrap;
    gap: 0.75rem; margin-bottom: 1rem;
}

.invoice-search-wrap {
    display: flex; align-items: center; gap: 0.5rem; flex: 1;
}
.invoice-search-wrap .search-box { flex: 1; max-width: 320px; }

@media (max-width: 767px) {
    .section-header { flex-direction: column; align-items: stretch; }
    .invoice-search-wrap { width: 100%; }
    .invoice-search-wrap .search-box { max-width: 100%; }
}

/* ==========================================
   TABLE
   ========================================== */
.table-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.responsive-table { width: 100%; border-collapse: collapse; }

/* Mobile card view */
.responsive-table th { display: none; }
.responsive-table td {
    display: flex; justify-content: space-between;
    align-items: center; padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem; gap: 0.5rem;
}
.responsive-table tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.7rem;
    background: var(--card-bg);
    overflow: hidden;
    transition: border-color var(--ease);
}
.responsive-table tr:active { border-color: var(--primary); }
.responsive-table td::before {
    content: attr(data-label);
    font-weight: 700; color: var(--text-dim);
    font-size: 0.75rem; flex-shrink: 0;
}
.responsive-table tr td:last-child { border-bottom: none; }

/* Desktop table */
@media (min-width: 768px) {
    .responsive-table { border-collapse: separate; border-spacing: 0; }
    .responsive-table tr { display: table-row; border: none; margin-bottom: 0; }
    .responsive-table th,
    .responsive-table td {
        display: table-cell; padding: 0.82rem 1rem;
        text-align: right; border-bottom: 1px solid var(--border);
    }
    .responsive-table tr:last-child td { border-bottom: none; }
    .responsive-table th {
        display: table-cell;
        background: var(--elevated);
        font-weight: 700; font-size: 0.8rem;
        color: var(--text-dim); letter-spacing: 0.3px;
    }
    .responsive-table td::before { content: ""; }
    .responsive-table tbody tr { transition: background-color var(--ease); }
    .responsive-table tbody tr:hover td { background: rgba(22,32,48,0.8); }
}

/* ==========================================
   LOADER
   ========================================== */
.loader-wrap { text-align: center; padding: 3rem 0; }
.loader {
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    width: 36px; height: 36px;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================
   MODALS
   ========================================== */
.modal {
    display: none; position: fixed;
    z-index: 1000; inset: 0;
    background: rgba(4,8,16,0.88);
    align-items: flex-end; justify-content: center;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.modal-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%; max-width: 100%;
    border: 1px solid var(--border-light);
    border-bottom: none;
    box-shadow: var(--shadow-xl);
    max-height: 92vh; overflow-y: auto;
    animation: slideUp 0.28s cubic-bezier(0.34,1.1,0.64,1);
    padding-bottom: calc(2rem + var(--safe-bottom));
}
.modal-content::-webkit-scrollbar { width: 4px; }

/* Modal drag handle */
.modal-content::before {
    content: '';
    display: block;
    width: 40px; height: 5px;
    background: var(--border-light);
    border-radius: 3px;
    margin: -0.75rem auto 1.25rem;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.modal-title {
    font-size: 1.25rem; font-weight: 800;
    color: var(--primary);
    padding-bottom: 1rem; margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

/* Desktop modal: centered */
@media (min-width: 640px) {
    .modal { align-items: center; }
    .modal-content {
        border-radius: var(--radius-lg);
        border-bottom: 1px solid var(--border-light);
        max-width: 600px;
        padding-bottom: 2rem;
        animation: modalIn 0.22s ease;
    }
    .modal-content::before { display: none; }
    @keyframes modalIn {
        from { transform: translateY(-14px) scale(0.97); opacity: 0; }
        to   { transform: translateY(0) scale(1); opacity: 1; }
    }
}

/* ==========================================
   INPUTS
   ========================================== */
.input-field {
    background: var(--elevated);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: 0.7rem 0.9rem;
    font-family: 'Tajawal', sans-serif;
    font-size: 1rem;
    width: 100%;
    transition: border-color var(--ease), box-shadow var(--ease);
    -webkit-appearance: none;
}
.input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.18);
}
.input-field::placeholder { color: var(--text-dim); }

label {
    display: block;
    font-size: 0.85rem; font-weight: 600;
    color: var(--text-dim); margin-bottom: 6px;
}

/* ==========================================
   BUTTONS
   ========================================== */
.btn {
    padding: 0.7rem 1.3rem;
    border-radius: var(--radius);
    font-weight: 700; font-size: 0.95rem;
    font-family: 'Tajawal', sans-serif;
    border: none; cursor: pointer;
    display: inline-flex; align-items: center;
    justify-content: center; gap: 6px;
    white-space: nowrap; line-height: 1.4;
    transition: all var(--ease);
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}
.btn:active  { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: white;
    box-shadow: 0 2px 14px var(--primary-glow);
}
.btn-primary:hover {
    box-shadow: 0 4px 22px rgba(59,130,246,0.4);
    filter: brightness(1.1);
}

.btn-secondary {
    background: var(--elevated);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); border-color: var(--border-light); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-dark); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; min-height: 34px; }

/* أزرار الإجراءات في الجداول — أيقونة فقط */
.btn-icon { padding: 0.35rem 0.6rem; font-size: 1rem; min-height: 34px; min-width: 34px; }

/* ==========================================
   BADGES
   ========================================== */
.subscription-badge {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white; padding: 0.22rem 0.7rem;
    border-radius: 20px; font-size: 0.8rem; font-weight: 700;
    display: inline-block;
}
.expired-badge {
    background: linear-gradient(135deg, #b91c1c, var(--danger));
    color: white; padding: 0.22rem 0.7rem;
    border-radius: 20px; font-size: 0.8rem; font-weight: 700;
    display: inline-block;
}
.active-badge {
    background: linear-gradient(135deg, #15803d, var(--success));
    color: white; padding: 0.22rem 0.7rem;
    border-radius: 20px; font-size: 0.8rem; font-weight: 700;
    display: inline-block;
}

/* ==========================================
   SUB NAVIGATION
   ========================================== */
.sub-navigation {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem;
    margin-bottom: 1.25rem;
}
.sub-tab {
    padding: 0.45rem 0.95rem; margin: 0.2rem;
    border-radius: 7px; cursor: pointer;
    background: transparent; color: var(--text-dim);
    border: 1px solid transparent;
    font-family: 'Tajawal', sans-serif; font-weight: 600; font-size: 0.87rem;
    transition: all var(--ease);
    -webkit-tap-highlight-color: transparent;
    min-height: 36px;
}
.sub-tab:hover  { background: var(--elevated); color: var(--text); border-color: var(--border); }
.sub-tab.active { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 2px 10px var(--primary-glow); }

/* ==========================================
   SEARCH / SORT
   ========================================== */
.search-box {
    background: var(--elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.55rem 0.85rem;
    color: var(--text); font-family: 'Tajawal', sans-serif; font-size: 0.9rem;
    min-width: 190px;
    transition: border-color var(--ease), box-shadow var(--ease);
    -webkit-appearance: none;
    min-height: 44px;
}
.search-box:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }

.sort-btn {
    display: inline-flex; align-items: center; gap: 0.45rem;
    padding: 0.55rem 0.85rem;
    background: var(--elevated); border: 1px solid var(--border);
    border-radius: var(--radius); cursor: pointer;
    color: var(--text); font-size: 0.85rem; font-family: 'Tajawal', sans-serif; font-weight: 600;
    transition: all var(--ease);
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}
.sort-btn:hover  { background: var(--border); }
.sort-btn.active { background: var(--primary); border-color: var(--primary); color: white; box-shadow: 0 2px 10px var(--primary-glow); }
.sort-icon { width: 14px; height: 14px; transition: transform var(--ease); }
.sort-btn.active .sort-icon { transform: rotate(180deg); }

/* ==========================================
   TOOLS BAR
   ========================================== */
.tools-bar {
    display: flex; justify-content: space-between;
    align-items: center; flex-wrap: wrap;
    gap: 0.75rem; margin-bottom: 1.25rem;
}
.tools-bar-left  { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem; }

/* ==========================================
   PAGE HEADER (back button row)
   ========================================== */
.page-header {
    display: flex; align-items: center;
    gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.page-header-title { font-size: 1.4rem; font-weight: 800; color: var(--primary); }

/* ==========================================
   EMPTY STATE
   ========================================== */
.empty-state {
    text-align: center; padding: 3.5rem 1rem;
    color: var(--text-dim);
}
.empty-state-icon { font-size: 2.8rem; opacity: 0.35; margin-bottom: 0.6rem; display: block; }

/* ==========================================
   PDF hidden template
   ========================================== */
.pdf-container { position: absolute !important; left: -9999px !important; top: auto !important; width: 210mm; }

/* ==========================================
   ANIMATIONS
   ========================================== */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeUp 0.32s ease; }

/* ==========================================
   MOBILE — iOS App Experience
   ========================================== */
@media (max-width: 767px) {

    /* Header */
    .app-header { padding: 0.5rem 0; }
    .header-title { font-size: 0.95rem; }
    .header-logo { width: 32px; height: 32px; }

    /* Main content: pad bottom for fixed nav */
    main.container {
        padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 0.5rem) !important;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    /* Stats: 3 cols compact */
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }
    .stat-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 0.3rem;
        padding: 0.7rem 0.4rem;
    }
    .stat-icon { width: 32px; height: 32px; font-size: 14px; }
    .stat-value { font-size: 0.95rem; }
    .stat-label { font-size: 0.62rem; }

    /* Profit bar */
    .profit-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 0.75rem;
        gap: 0.6rem;
        margin-bottom: 0.75rem;
    }
    .profit-filters { justify-content: space-between; }
    .profit-filters label { font-size: 0.82rem; }
    .profit-totals { justify-content: space-around; }
    .profit-divider { display: none; }
    .profit-value { font-size: 0.88rem; }
    .profit-label { font-size: 0.65rem; }
    #dateFilter { font-size: 0.85rem; padding: 0.4rem 0.6rem; }

    /* Nav tabs wrapper hidden on mobile */
    .nav-tabs-wrapper { display: none; }

    /* ── BOTTOM NAV BAR (iOS style) ── */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        z-index: 200;
        background: rgba(8,13,20,0.98);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        border-top: 1px solid var(--border);
        height: calc(var(--nav-h) + var(--safe-bottom));
        padding-bottom: var(--safe-bottom);
        box-shadow: 0 -4px 30px rgba(0,0,0,0.6);
    }
    .mobile-tab {
        flex: 1;
        display: flex; flex-direction: column;
        align-items: center; justify-content: center;
        gap: 3px;
        cursor: pointer; border: none;
        background: transparent;
        color: var(--text-dim);
        font-family: 'Tajawal', sans-serif;
        font-size: 0.65rem; font-weight: 600;
        padding: 8px 4px;
        transition: color var(--ease);
        -webkit-tap-highlight-color: transparent;
        position: relative;
    }
    .mobile-tab-icon { font-size: 20px; line-height: 1; transition: transform 0.15s ease; }
    .mobile-tab.active { color: var(--primary); }
    .mobile-tab.active .mobile-tab-icon { transform: scale(1.15); }
    .mobile-tab.active::after {
        content: '';
        position: absolute; top: 5px;
        width: 4px; height: 4px;
        background: var(--primary); border-radius: 50%;
        box-shadow: 0 0 8px var(--primary);
    }

    /* Section header */
    .section-header { flex-direction: column; align-items: stretch; gap: 0.5rem; margin-bottom: 0.75rem; }
    .invoice-search-wrap { width: 100%; }
    .invoice-search-wrap .search-box { max-width: 100%; }
    .section-header .btn { width: 100%; font-size: 0.95rem; padding: 0.8rem; }

    /* ── MODAL — Full Bottom Sheet ── */
    .modal { align-items: flex-end; }
    .modal-content {
        width: 100%; max-width: 100%;
        max-height: 88vh;
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        padding: 0 1rem 1rem;
        padding-bottom: calc(1rem + var(--safe-bottom));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* Drag handle */
    .modal-content::before {
        content: '';
        display: block;
        width: 36px; height: 4px;
        background: var(--border-light);
        border-radius: 2px;
        margin: 0.75rem auto 1rem;
    }
    .modal-title { font-size: 1rem; padding-bottom: 0.75rem; margin-bottom: 1rem; }

    /* Form fields in modal */
    .modal-content label { font-size: 0.8rem; margin-bottom: 4px; }
    .modal-content .input-field { font-size: 0.95rem; padding: 0.65rem 0.8rem; }
    .modal-content textarea.input-field { rows: 2; }
    .modal-content .grid { gap: 0.6rem !important; }
    .modal-content .btn { min-height: 48px; font-size: 0.95rem; }

    /* Confirm modal — دائماً في المنتصف */
    #confirmModal { align-items: center !important; padding: 1rem; }
    #confirmModal .modal-content {
        border-radius: 16px !important;
        border-bottom: 1px solid var(--border-light) !important;
        padding: 1.5rem !important;
        padding-bottom: 1.5rem !important;
        max-height: 80vh;
    }
    #confirmModal .modal-content::before { display: none !important; }
    #confirmModal .flex { flex-direction: row !important; }
    #confirmModal .btn { flex: 1; }

    /* Login card */
    .login-card { padding: 1.75rem 1.1rem; border-radius: 20px; }
    .login-logo-img { width: 75px; height: 75px; }
    .login-title { font-size: 1.35rem; }

    /* Subscriber tools */
    .tools-bar { flex-direction: column; align-items: stretch; gap: 0.5rem; margin-bottom: 0.75rem; }
    .tools-bar-left { width: 100%; flex-wrap: nowrap; }
    .search-box { flex: 1; min-width: 0; font-size: 0.9rem; min-height: 42px; }
    .tools-bar > .btn { width: 100%; }

    /* Table rows */
    .responsive-table td { padding: 0.7rem 0.85rem; font-size: 0.85rem; }
    .responsive-table td::before { font-size: 0.7rem; }

    /* Page header */
    .page-header { margin-bottom: 0.75rem; gap: 0.6rem; }
    .page-header-title { font-size: 1.1rem; }

    /* Sub navigation */
    .sub-navigation { padding: 0.4rem; margin-bottom: 0.75rem; }
    .sub-tab { padding: 0.4rem 0.7rem; font-size: 0.8rem; }

    /* Empty state */
    .empty-state { padding: 2rem 1rem; }
    .empty-state-icon { font-size: 2.2rem; }

    /* Dashboard title */
    #dashboardSection > div:first-child h2 { font-size: 1.3rem; }
    #dashboardSection { padding-top: 0.75rem !important; padding-bottom: 0 !important; }

    /* ── Stats section mobile fixes ── */
    .stats-compare-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.6rem;
        margin-bottom: 0.75rem;
    }
    .compare-card { padding: 0.85rem 0.75rem; }
    .compare-value { font-size: 1rem; }
    .compare-label { font-size: 0.7rem; }
    .compare-sub   { font-size: 0.7rem; }

    .charts-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    .chart-wrap    { height: 200px; }
    .chart-wrap-sm { height: 200px; }
    .chart-card    { padding: 0.85rem 0.9rem; }
    .chart-title   { font-size: 0.82rem; margin-bottom: 0.65rem; }

    .backup-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }
    .backup-bar-actions { width: 100%; }
    .backup-bar-actions .btn { flex: 1; text-align: center; }
}

/* Very small screens */
@media (max-width: 360px) {
    .stats-grid { gap: 0.3rem; }
    .stat-value { font-size: 0.85rem; }
    .stat-label { font-size: 0.58rem; }
    .stat-icon { width: 28px; height: 28px; font-size: 12px; }
    .mobile-tab { font-size: 0.6rem; }
    .mobile-tab-icon { font-size: 18px; }
}

/* ==========================================
   DESKTOP — Better layout (768px+)
   ========================================== */
@media (min-width: 768px) {
    /* Hide mobile bottom nav */
    .mobile-bottom-nav { display: none !important; }

    /* Wider container */
    .container { max-width: 1280px !important; }

    /* Stats 3 columns fixed */
    .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }

    /* Profit bar inline */
    .profit-bar { padding: 1rem 1.6rem; }

    /* Better table padding */
    .responsive-table th,
    .responsive-table td { padding: 0.9rem 1.2rem; }

    /* Section header with title space */
    .section-header { margin-bottom: 1.25rem; }
}

@media (min-width: 1024px) {
    .stats-grid { gap: 1.5rem; }
    .stat-card { padding: 1.3rem 1.5rem; }
    .stat-value { font-size: 1.6rem; }
}
