/* ==========================================================================
   أرباحي - Professional Responsive Enhancement Layer
   --------------------------------------------------------------------------
   Loaded AFTER style-desktop.css / style-mobile.css / landing-*.css so it
   can override and refine the existing responsive behaviour with a more
   modern, mobile-first, touch-friendly experience.

   Goals:
     • Fluid typography (clamp) so headings scale smoothly across screens
     • Better touch targets (min 44x44) for buttons and nav items
     • Robust grids that reflow on any screen size without overflow
     • Improved sidebar / drawer behaviour on mobile
     • Tables that turn into cards on narrow screens
     • Forms that are usable on phones (16px+ font, generous spacing)
     • Print-friendly tweaks for invoices / receipts
     • Better safe-area handling for notched phones (iOS)
   ========================================================================== */

/* ----- 1. Fluid typography & global tweaks ----- */
:root {
    --header-height: 64px;
    --sidebar-width: 260px;
}

html {
    /* Smooth font scaling — prevents iOS zoom-on-focus by ensuring ≥16px on inputs */
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    /* Respect iOS safe areas (notch / home indicator) */
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    /* Prevent horizontal scroll caused by overflowing children */
    overflow-x: hidden;
    text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Headings use clamp() so they scale fluidly with viewport */
h1 { font-size: clamp(1.5rem, 2.2vw + 1rem, 2.4rem); line-height: 1.3; }
h2 { font-size: clamp(1.3rem, 1.6vw + 0.9rem, 2rem);    line-height: 1.35; }
h3 { font-size: clamp(1.1rem, 1.2vw + 0.8rem, 1.6rem);  line-height: 1.4; }
h4 { font-size: clamp(1rem,    0.8vw + 0.8rem, 1.25rem); line-height: 1.45; }
p  { font-size: clamp(0.92rem, 0.3vw + 0.85rem, 1rem); }

/* ----- 2. Touch targets & buttons ----- */
.btn,
button,
input[type="submit"],
input[type="button"],
.btn-sm {
    /* 44x44 is the Apple HIG / Material minimum touch target */
    min-height: 44px;
    min-width: 44px;
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-sm {
    min-height: 36px;
    min-width: 36px;
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn:hover,
button:hover {
    transform: translateY(-1px);
}

.btn:active,
button:active {
    transform: translateY(0) scale(0.98);
}

/* Make sure icon-only buttons keep a square shape */
.btn-danger.btn-sm:only-child,
.header-actions .btn-sm {
    padding: 6px 10px;
}

/* ----- 3. Forms (mobile-friendly) ----- */
.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"],
input[type="search"],
input[type="tel"],
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    font-size: 16px; /* ≥16px prevents iOS Safari auto-zoom */
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.25);
    background: rgba(255, 255, 255, 0.06);
}

textarea {
    min-height: 100px;
    resize: vertical;
    line-height: 1.6;
}

select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a29bfe' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: left 14px center;
    background-size: 12px;
    padding-left: 36px;
}

[dir="ltr"] select {
    background-position: right 14px center;
    padding-left: 14px;
    padding-right: 36px;
}

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

.form-group {
    margin-bottom: 16px;
}

.form-hint {
    margin-top: 6px;
    font-size: 0.82rem;
    color: var(--text-3);
    line-height: 1.5;
}

/* form-row: 2-col grid that collapses on mobile */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

/* ----- 4. Cards & layout grids ----- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.card-header {
    padding: 16px 20px;
    font-size: 1rem;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-body {
    padding: 20px;
}

.stats-grid,
.dashboard-quick-actions,
.features-3d-grid,
.steps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

/* On wide screens, cap stats grid at 4 columns */
@media (min-width: 1200px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
    .dashboard-quick-actions { grid-template-columns: repeat(4, 1fr); }
}

/* ----- 5. Tables: card-on-mobile pattern ----- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

table thead {
    background: rgba(255, 255, 255, 0.03);
}

table th,
table td {
    padding: 12px 14px;
    text-align: start;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    word-break: break-word;
}

table th {
    font-weight: 700;
    color: var(--text);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* ----- 6. Header / Navigation ----- */
.header {
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 20px;
    background: var(--dark-2);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    min-width: 0;
}

.header-logo img {
    height: 32px;
    width: auto;
    border-radius: 8px;
    flex-shrink: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Hamburger visibility */
.hamburger {
    display: none;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.hamburger:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ----- 7. Sidebar (admin/user dashboard) ----- */
.layout {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - var(--header-height));
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--dark-2);
    border-inline-end: 1px solid var(--border);
    height: calc(100vh - var(--header-height));
    position: sticky;              /* ← must stay sticky so it doesn't disappear when scrolling */
    top: var(--header-height);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    min-width: 0; /* allows children to shrink */
    padding: 24px;
    overflow-x: hidden;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    color: var(--text-2);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    transition: background 0.2s ease, color 0.2s ease;
    border-inline-start: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: rgba(108, 92, 231, 0.08);
    color: var(--text);
}

.sidebar-nav a.active {
    background: rgba(108, 92, 231, 0.15);
    color: var(--primary-light);
    border-inline-start-color: var(--primary);
    font-weight: 600;
}

.sidebar-nav a i {
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-section {
    padding: 14px 18px 6px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    font-weight: 700;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ----- 8. Landing page hero ----- */
.landing-hero {
    min-height: clamp(420px, 70vh, 720px);
    padding: clamp(80px, 10vh, 140px) clamp(16px, 4vw, 32px) clamp(60px, 8vh, 100px);
}

.hero-main-title {
    font-size: clamp(1.8rem, 5.5vw, 3.6rem);
    line-height: 1.2;
    margin-bottom: 16px;
}

.hero-stats-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: clamp(8px, 2vw, 20px);
}

.glass-stat-card {
    flex: 1 1 200px;
    max-width: 280px;
    min-width: 0;
}

/* ----- 9. Page title & breadcrumbs ----- */
.page-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: clamp(1.2rem, 1.4vw + 0.8rem, 1.6rem);
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text);
}

.page-title i {
    color: var(--primary-light);
}

/* ----- 10. Notification panel & dropdowns ----- */
.notification-panel {
    position: absolute;
    top: calc(100% + 8px);
    inset-inline-end: 0;
    width: min(360px, calc(100vw - 32px));
    background: var(--dark-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    z-index: 2000;
    max-height: 60vh;
    overflow-y: auto;
    display: none;
}

.notification-panel.show,
.notification-panel[style*="display: block"] {
    display: block;
}

/* ----- 11. Modal / dialog overlays -----
   IMPORTANT: .modal-overlay must default to display:none and only
   reveal when the .show class is added (matching the existing
   behaviour defined in style-desktop.css). The previous version
   forced display:flex unconditionally and broke every admin/user
   page by showing an empty confirm dialog on load.
*/
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9999;
    display: none;                 /* hidden by default */
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.show,
.modal-overlay[style*="display: block"],
.modal-overlay[style*="display:block"] {
    display: flex;                 /* shown only when .show OR inline block */
}

.modal-overlay > * {
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

/* ----- 12. Tablet (≤1024px) ----- */
@media (max-width: 1024px) {
    .main-content {
        padding: 20px;
    }

    .sidebar {
        width: 220px;
    }

    .stats-grid,
    .dashboard-quick-actions {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }

    .features-3d-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .steps-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ----- 13. Mobile (≤768px) — activate drawer, hide header text ----- */
@media (max-width: 768px) {
    :root {
        --header-height: 56px;
    }

    .header {
        padding: 0 12px;
        gap: 8px;
    }

    .header-logo img {
        height: 28px;
    }

    /* Header becomes logo + actions only */
    .header-username,
    .header-actions > span {
        display: none;
    }

    /* Show hamburger, hide inline nav */
    .hamburger {
        display: inline-flex;
    }

    .header-nav {
        display: none;
    }

    /* Sidebar becomes a slide-in drawer */
    .sidebar {
        position: fixed;
        top: var(--header-height);
        bottom: 0;
        width: min(280px, 85vw);
        height: calc(100vh - var(--header-height));
        z-index: 1000;
        background: rgba(17, 17, 39, 0.98);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        transform: translateX(0);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* RTL: drawer slides from right */
    [dir="rtl"] .sidebar {
        right: 0;
        left: auto;
        transform: translateX(100%);
    }
    [dir="rtl"] .sidebar.sidebar-open {
        transform: translateX(0);
    }

    /* LTR: drawer slides from left */
    [dir="ltr"] .sidebar {
        right: auto;
        left: 0;
        transform: translateX(-100%);
    }
    [dir="ltr"] .sidebar.sidebar-open {
        transform: translateX(0);
    }

    .main-content {
        padding: 16px;
        width: 100%;
    }

    /* Mobile-only: stack form-row vertically */
    .form-row {
        grid-template-columns: 1fr;
    }

    /* Cards: tighter padding on mobile */
    .card-body {
        padding: 16px;
    }
    .card-header {
        padding: 14px 16px;
        font-size: 0.95rem;
    }

    /* Page title: smaller icon, smaller text */
    .page-title {
        font-size: 1.15rem;
        margin-bottom: 16px;
    }

    /* Notification panel: nearly full width */
    .notification-panel {
        inset-inline-end: -12px;
        width: min(320px, calc(100vw - 24px));
    }

    /* Landing nav: shrink everything */
    .nav-container {
        padding: 0 12px;
        gap: 6px;
    }

    .nav-logo {
        font-size: 1.1rem;
    }
    .nav-logo img {
        height: 30px;
    }

    /* Lang switcher: hide text label on mobile, show only flag */
    .lang-switcher button .lang-name,
    .lang-switcher button .lang-name-text,
    .lang-switcher button span:nth-child(2) {
        display: none;
    }

    /* Hero: more vertical rhythm */
    .hero-stats-row {
        flex-wrap: wrap;
        gap: 8px;
    }

    .glass-stat-card {
        flex: 1 1 100%;
        max-width: 100%;
    }

    /* Footer: stack columns */
    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }

    /* Tables: horizontal scroll if too wide; or transform to cards (kept simple) */
    .table-responsive {
        margin: 0 -16px;
        padding: 0 16px;
    }

    /* Step grid: 1 column on mobile */
    .steps-grid,
    .features-3d-grid {
        grid-template-columns: 1fr;
    }

    /* Modal: full-width */
    .modal-overlay > * {
        width: 100% !important;
    }
}

/* ----- 14. Small mobile (≤480px) ----- */
@media (max-width: 480px) {
    :root {
        --header-height: 54px;
    }

    .header {
        padding: 0 10px;
    }

    .header-logo img {
        height: 26px;
    }

    .header-logo .logo-text {
        font-size: 1rem;
    }

    /* Buttons: full-width stacks */
    .hero-cta-row,
    .cta-row {
        flex-direction: column;
        gap: 10px;
    }

    .hero-cta-row > *,
    .cta-row > * {
        width: 100%;
    }

    /* Footer: single column */
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    /* Page content: even tighter */
    .main-content {
        padding: 12px;
    }

    .card-body {
        padding: 14px;
    }

    /* Hero: even smaller */
    .hero-main-title {
        font-size: clamp(1.4rem, 6vw, 2rem);
    }

    .glass-stat-card {
        padding: 10px 12px;
    }

    /* Hamburger: smaller */
    .hamburger {
        width: 40px;
        height: 40px;
        font-size: 1.05rem;
    }

    /* Sidebar: narrower on tiny screens */
    .sidebar {
        width: min(260px, 88vw);
    }
}

/* ----- 15. Very small mobile (≤360px) — last-resort tweaks ----- */
@media (max-width: 360px) {
    .header-logo .logo-text,
    .header-logo span {
        font-size: 0.95rem;
    }

    .hero-main-title {
        font-size: 1.35rem;
    }

    .card-header {
        font-size: 0.9rem;
        padding: 12px 14px;
    }
}

/* ----- 16. Landscape phones (height < 500px) ----- */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .landing-hero {
        min-height: auto;
        padding: 80px 16px 40px;
    }

    .hero-stats-row {
        flex-wrap: wrap;
    }

    .sidebar {
        top: 0;
        height: 100vh;
    }
}

/* ----- 17. Print styles (for invoices / payout receipts) ----- */
@media print {
    .header,
    .sidebar,
    .sidebar-overlay,
    .hamburger,
    .footer,
    .landing-footer,
    .notification-bell,
    .cookie-consent-overlay,
    .btn,
    button {
        display: none !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
    }

    .main-content {
        padding: 0 !important;
        width: 100% !important;
    }

    .card {
        border: 1px solid #ccc !important;
        break-inside: avoid;
    }
}

/* ----- 18. Reduce motion (accessibility) ----- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ----- 19. Dark mode scrollbar (nicer UX) ----- */
@media (prefers-color-scheme: dark) {
    *::-webkit-scrollbar {
        width: 10px;
        height: 10px;
    }
    *::-webkit-scrollbar-track {
        background: var(--dark);
    }
    *::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 5px;
    }
    *::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.2);
    }
}

/* ----- 20. Helper utilities ----- */
.text-center { text-align: center; }
.text-start  { text-align: start; }
.text-end    { text-align: end; }
.d-none      { display: none !important; }
.d-block     { display: block !important; }
.d-flex      { display: flex !important; }
.flex-wrap   { flex-wrap: wrap !important; }
.gap-1       { gap: 4px; }
.gap-2       { gap: 8px; }
.gap-3       { gap: 16px; }
.gap-4       { gap: 24px; }
.mt-1        { margin-top: 4px; }
.mt-2        { margin-top: 8px; }
.mt-3        { margin-top: 16px; }
.mt-4        { margin-top: 24px; }
.mb-1        { margin-bottom: 4px; }
.mb-2        { margin-bottom: 8px; }
.mb-3        { margin-bottom: 16px; }
.mb-4        { margin-bottom: 24px; }
.w-100       { width: 100% !important; }
