/* ========================================
   📱 USER PORTAL RESPONSIVE STYLES
   Centralized responsive CSS for all user portal pages
   ======================================== */

/* ========================================
   GENERAL RESPONSIVE UTILITIES
   ======================================== */

/* Tablet: 768px - 991px */
@media (max-width: 991px) {
    .main-content {
        margin-left: 0 !important;
        padding: 1rem;
    }

    .page-header h1 {
        font-size: 1.75rem;
    }
}

/* Mobile: ≤768px */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }

    .main-content {
        padding: 4.25rem 0.5rem 0.5rem 0.5rem !important;
        margin-top: 0 !important;
    }

    .page-header {
        margin-bottom: 0.75rem !important;
        padding: 2rem 1rem !important;
        border-radius: 8px !important;
    }

    .page-header h1 {
        font-size: 1.375rem !important;
        line-height: 1.3;
        margin-bottom: 0.25rem !important;
        word-wrap: break-word;
    }

    .page-header p {
        font-size: 0.8125rem !important;
        margin-bottom: 0 !important;
    }

    /* Convert grid layouts to single column */
    .credit-packages-grid,
    .packages-grid,
    .package-grid,
    .stats-grid,
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    /* Card adjustments */
    .card,
    .package-card,
    .credit-package,
    .stats-card {
        padding: 1rem !important;
    }

    /* Button adjustments */
    .btn,
    .btn-primary,
    .btn-secondary,
    button:not(.hamburger-menu):not(.app-header-theme-toggle) {
        min-height: 44px;
        padding: 0.75rem 1rem;
        font-size: 0.9375rem;
    }

    /* Full-width buttons on mobile */
    .btn-block,
    .action-btn-full {
        width: 100%;
        display: block;
    }

    /* Table responsive */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 0.875rem;
    }

    table th,
    table td {
        padding: 0.5rem !important;
    }

    /* Form responsive */
    .form-grid,
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    input,
    select,
    textarea {
        font-size: 16px !important;
        /* Prevents zoom on iOS */
        min-height: 44px;
    }

    /* Modal responsive */
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        margin: 1rem !important;
    }

    .modal-header h2 {
        font-size: 1.25rem !important;
    }

    .modal-body {
        padding: 1rem !important;
    }
}

/* Extra small mobile: ≤414px */
@media (max-width: 414px) {
    .page-header h1 {
        font-size: 1.375rem;
    }

    .card,
    .package-card {
        padding: 1rem !important;
    }

    /* Reduce spacing - keep top padding for header clearance */
    .main-content {
        padding: 4.25rem 0.75rem 0.75rem 0.75rem !important;
    }

    /* Smaller fonts for compact layouts */
    .package-price,
    .credit-amount {
        font-size: 1.75rem !important;
    }
}

/* Very small mobile: ≤375px */
@media (max-width: 375px) {
    .page-header h1 {
        font-size: 1.25rem;
    }

    body {
        font-size: 13px;
    }

    .main-content {
        padding: 4.25rem 0.5rem 0.5rem 0.5rem !important;
    }

    .card,
    .package-card {
        padding: 0.875rem !important;
    }

    button,
    .btn {
        font-size: 0.875rem !important;
    }
}

/* ========================================
   PAGE-SPECIFIC RESPONSIVE STYLES
   ======================================== */

/* Credit Shop Page */
@media (max-width: 768px) {
    .credit-packages-container .package-card {
        max-width: 100%;
    }

    .package-header {
        font-size: 1.125rem !important;
    }

    .package-price {
        font-size: 2rem !important;
    }

    .package-features li {
        font-size: 0.875rem;
        padding: 0.4rem 0;
    }

    .buy-package-btn,
    .test-purchase-btn {
        width: 100%;
        min-height: 48px;
    }
}

/* Invoice & Orders Tables */
@media (max-width: 768px) {

    /* Hide less important columns on mobile */
    .invoice-table .hide-mobile,
    .orders-table .hide-mobile {
        display: none;
    }

    /* Stack table rows as cards on very small screens */
    @media (max-width: 575px) {

        .invoice-table,
        .orders-table {
            display: block;
        }

        .invoice-table thead,
        .orders-table thead {
            display: none;
        }

        .invoice-table tbody,
        .orders-table tbody,
        .invoice-table tr,
        .orders-table tr {
            display: block;
        }

        .invoice-table tr,
        .orders-table tr {
            margin-bottom: 1rem;
            border: 1px solid var(--card-border);
            border-radius: var(--radius-md);
            padding: 0.75rem;
            background: var(--surface-2);
        }

        .invoice-table td,
        .orders-table td {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0.5rem 0 !important;
            border: none !important;
        }

        .invoice-table td::before,
        .orders-table td::before {
            content: attr(data-label);
            font-weight: 600;
            margin-right: 1rem;
            color: var(--text-secondary);
        }
    }
}

/* Profile Page */
@media (max-width: 768px) {
    .profile-header-card {
        padding: 1.25rem !important;
    }

    .profile-header-content {
        flex-direction: column !important;
        text-align: center;
    }

    .avatar-display {
        width: 64px !important;
        height: 64px !important;
    }

    .profile-section {
        padding: 1rem !important;
    }
}

/* Settings Page */
@media (max-width: 768px) {
    .permissions-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .permissions-table {
        min-width: 600px;
    }

    .toggle-switch {
        transform: scale(0.9);
    }
}

/* Credit History Page */
@media (max-width: 768px) {
    .transaction-card {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .transaction-details {
        width: 100%;
        margin-bottom: 0.75rem;
    }

    .transaction-amount {
        align-self: flex-end;
    }
}

/* ========================================
   TOUCH-FRIENDLY ELEMENTS
   ======================================== */

@media (max-width: 768px) {

    /* Ensure all interactive elements are at least 44x44px */
    a,
    button,
    input[type="checkbox"],
    input[type="radio"],
    .clickable {
        min-height: 44px;
        min-width: 44px;
    }

    /* Increase tap target for links in paragraphs */
    p a,
    li a {
        padding: 0.25rem 0.5rem;
        margin: -0.25rem -0.5rem;
    }

    /* Better spacing for form elements */
    .form-group {
        margin-bottom: 1rem;
    }

    label {
        margin-bottom: 0.5rem;
        font-size: 0.9375rem;
    }
}

/* ========================================
   PRINT STYLES (Bonus)
   ======================================== */

@media print {

    .sidebar-container,
    .app-header,
    .hamburger-menu,
    .mobile-backdrop,
    button,
    .btn {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }

    body {
        background: white !important;
        color: black !important;
    }
}

/* Otto 2026-06-02: cap ECU solution batches so desktop uses max 5,
   compact monitors use 3, and mobile stacks cleanly. */
#manualSolutionsContainer .solutions-grid,
#solutionsContainer .solutions-grid,
.wizard-shell #solutionsGrid.solutions-grid,
.solutions-grid {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 0.6rem !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow: visible !important;
}

#manualSolutionsContainer .solutions-grid > .solution-card,
#solutionsContainer .solutions-grid > .solution-card,
.wizard-shell #solutionsGrid.solutions-grid > .solution-card,
.solutions-grid > .solution-card {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: initial !important;
}

#manualSolutionsContainer .solution-card-main,
#solutionsContainer .solution-card-main,
.wizard-shell #solutionsGrid .solution-card-main,
#manualSolutionsContainer .solution-name,
#solutionsContainer .solution-name,
.wizard-shell #solutionsGrid .solution-name,
.solutions-grid .solution-name {
    min-width: 0 !important;
    white-space: normal !important;
    overflow-wrap: break-word !important;
    word-break: normal !important;
    hyphens: none !important;
}

#manualSolutionsContainer .solution-price-badge,
#solutionsContainer .solution-price-badge,
.wizard-shell #solutionsGrid .solution-price-badge,
.wizard-shell #solutionsGrid .solution-credits,
.solutions-grid .solution-price-badge,
.solutions-grid .solution-price {
    flex: 0 0 auto !important;
    margin-left: auto !important;
    white-space: nowrap !important;
}

@media (max-width: 1440px) {
    #manualSolutionsContainer .solutions-grid,
    #solutionsContainer .solutions-grid,
    .wizard-shell #solutionsGrid.solutions-grid,
    .solutions-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 700px) {
    .automatic-solutions-grid,
    #manualSolutionsContainer .solutions-grid,
    #solutionsContainer .solutions-grid,
    .wizard-shell #solutionsGrid.solutions-grid,
    .solutions-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Higher-specificity cache override: the production EJS view can render an older
   inline style after this stylesheet until the app is restarted. */
html body #manualSolutionsContainer .solutions-grid,
html body #solutionsContainer .solutions-grid {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 0.6rem !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow: visible !important;
}

html body #manualSolutionsContainer .solutions-grid > .solution-card,
html body #solutionsContainer .solutions-grid > .solution-card {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: initial !important;
}

html body #manualSolutionsContainer .solution-card-main,
html body #solutionsContainer .solution-card-main,
html body #manualSolutionsContainer .solution-name,
html body #solutionsContainer .solution-name {
    min-width: 0 !important;
    white-space: normal !important;
    overflow-wrap: break-word !important;
    word-break: normal !important;
    hyphens: none !important;
}

html body #manualSolutionsContainer .solution-price-badge,
html body #solutionsContainer .solution-price-badge {
    flex: 0 0 auto !important;
    margin-left: auto !important;
    white-space: nowrap !important;
}

@media (max-width: 1440px) {
    html body #manualSolutionsContainer .solutions-grid,
    html body #solutionsContainer .solutions-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 700px) {
    html body #manualSolutionsContainer .solutions-grid,
    html body #solutionsContainer .solutions-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ===== FIX-03: global checkbox/radio sizing (Angel UI), toggle-safe (Dieter) ===== */
input[type=checkbox]:not([role=switch]):not(.toggle):not(.switch):not(.form-switch-input):not(.toggle-input),
input[type=radio]{
  appearance:none;-webkit-appearance:none;box-sizing:border-box;
  width:18px!important;height:18px!important;min-width:18px!important;max-width:18px!important;
  min-height:18px!important;max-height:18px!important;align-self:center!important;
  border:1.5px solid var(--card-border,rgba(255,255,255,.22));
  background:var(--surface-2,rgba(255,255,255,.04));
  cursor:pointer;position:relative;flex:0 0 auto!important;vertical-align:middle;
  transition:background .14s ease-out,border-color .14s ease-out;margin:0;padding:0;
}
input[type=checkbox]:not([role=switch]):not(.toggle):not(.switch):not(.form-switch-input):not(.toggle-input){border-radius:5px;}
input[type=radio]{border-radius:50%;}
input[type=checkbox]:not([role=switch]):not(.toggle):not(.switch):not(.form-switch-input):not(.toggle-input):hover,
input[type=radio]:hover{border-color:var(--accent-primary,#D03725);}
input[type=checkbox]:not([role=switch]):not(.toggle):not(.switch):not(.form-switch-input):not(.toggle-input):checked,
input[type=radio]:checked{background:var(--accent-primary,#D03725);border-color:var(--accent-primary,#D03725);}
input[type=checkbox]:not([role=switch]):not(.toggle):not(.switch):not(.form-switch-input):not(.toggle-input):checked::after{content:"";position:absolute;left:5px;top:2px;width:4px;height:8px;border:solid #fff;border-width:0 2px 2px 0;transform:rotate(45deg);}
input[type=radio]:checked::after{content:"";position:absolute;left:5px;top:5px;width:6px;height:6px;border-radius:50%;background:#fff;}
input[type=checkbox]:not([role=switch]):not(.toggle):not(.switch):not(.form-switch-input):not(.toggle-input):focus-visible,
input[type=radio]:focus-visible{outline:2px solid var(--accent-primary,#D03725);outline-offset:2px;}

/* protect hidden toggle-switch inputs from the sizing above (they must stay 0x0/invisible) */
.toggle-switch input[type=checkbox],
label.toggle-switch input,
.toggle input[type=checkbox]{
  appearance:auto!important;-webkit-appearance:auto!important;
  width:0!important;height:0!important;min-width:0!important;max-width:0!important;
  min-height:0!important;max-height:0!important;opacity:0!important;
  border:0!important;background:none!important;position:absolute!important;
}
.toggle-switch input[type=checkbox]::after{display:none!important;content:none!important;}
/* ===== end FIX-03 ===== */

/* Global auth-page slop kill (Mayk): no marketing feature-wall / brand-copy on ANY auth page */
.auth-feature-grid, .auth-brand-copy, .auth-kicker { display: none !important; }

/* Global auth-page layout (Mayk): logo 512 left + box 400x498 right, 1:1 alte Seite, ALLE auth-Seiten identisch */
@media (min-width: 701px) {
 body.auth-portal .auth-layout { display: flex !important; flex-direction: row !important; align-items: center !important; justify-content: flex-end !important; width: 100% !important; max-width: 100% !important; padding: 48px clamp(24px,6vw,90px) !important; position: relative !important; gap: 0 !important; grid-template-columns: none !important; }
 body.auth-portal .auth-brand { position: absolute !important; z-index: 1 !important; left: clamp(40px,5.8vw,80px) !important; top: 50% !important; transform: translateY(-50%) !important; max-width: 46vw !important; display: flex !important; align-items: center !important; padding: 0 !important; margin: 0 !important; overflow: visible !important; }
 body.auth-portal .auth-brand-head { display: flex !important; align-items: center !important; margin: 0 !important; overflow: visible !important; }
 body.auth-portal .auth-logo { max-width: 512px !important; max-height: 102px !important; width: auto !important; height: auto !important; transform: none !important; overflow: visible !important; }
 body.auth-portal .auth-card, body.auth-portal .auth-card-register { position: relative !important; z-index: 2 !important; width: 400px !important; max-width: 400px !important; margin-right: clamp(30px,4.2vw,60px) !important; height: auto !important; min-height: 0 !important; max-height: 498px !important; border-radius: 8px !important; background-color: #242526 !important; overflow-y: auto !important; transform: none !important; flex: 0 0 auto !important; }
 body.auth-portal .auth-card-header { text-align: center !important; }
}

/* Global brand cleanup (Mayk): nacktes Logo, kein Titel/Glas auf ANY auth page */
.auth-brand-title { display: none !important; }
body.auth-portal .auth-brand, body.auth-portal .auth-brand-head, body.auth-portal .auth-logo-wrap { background: none !important; background-image: none !important; border: none !important; box-shadow: none !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
body.auth-portal .auth-brand::before, body.auth-portal .auth-brand::after { display: none !important; content: none !important; background: none !important; }

/* Card box-sizing: 400x498 inkl. Padding (sonst blaeht Padding auf 450x548) */
body.auth-portal .auth-card, body.auth-portal .auth-card-register { box-sizing: border-box !important; }

/* FIX-04 20260611 (Dieter): .page-container Default (design-system) hatte width:100% + padding:0 2rem bei content-box -> 64px Overflow auf Seiten ohne Page-CSS (z.B. /user/support). Root-Cause: box-sizing. border-box zieht das Padding in die 100% Breite -> rechte Kante buendig zur main-content-Margin, kein horizontaler Overflow. Admin-Listen ueberschreiben .page-container (grid, padding:0) -> unberuehrt. */
.page-container { box-sizing: border-box !important; }
