/* ═══════════════════════════════════════════════════════════════════════════
   ALMUDIR Global Pro v1.0 — System-wide auto-injection layer
   Applies to: body.alm-shell, .alm-pro-page--system, modals, all modules
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Phase A: System auto-wrapper ─────────────────────────────────────────── */
.alm-pro-page--system {
    min-height: 100%;
    --alm-radius: 14px;
    --alm-radius-sm: 10px;
    --alm-border: #e2e8f0;
    --alm-card: #ffffff;
    --alm-text: #1e293b;
    --alm-muted: #64748b;
    --alm-accent: var(--tm-brand, #0040c1);
    --alm-accent-soft: var(--tm-brand-subtle, #e8eeff);
    --alm-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
}

/* Passthrough when page already has its own alm-pro-page wrapper */
.alm-pro-page--system:has(> .alm-pro-page) {
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
}

.alm-pro-page--system:has(> .alm-pro-page) > .content-header {
    display: none !important;
}

/* Legacy AdminLTE content-header → hero-style header (auto, no manual hero) */
.alm-pro-page--system > .content-header:first-child,
.alm-pro-page--system > section.content > .content-header:first-child {
    display: block !important;
    background: linear-gradient(135deg, var(--tm-header-from, #0038a8) 0%, var(--tm-brand-light, #004eeb) 100%);
    border-radius: var(--alm-radius);
    padding: 18px 22px;
    margin: 12px 16px 14px;
    border: none;
    box-shadow: 0 6px 24px var(--tm-brand-glow, rgba(0, 64, 193, 0.18));
}

.alm-pro-page--system > .content-header h1,
.alm-pro-page--system > section.content > .content-header h1,
.alm-pro-page--system .content-header .alm-legacy-hero__title {
    margin: 0 !important;
    font-size: 1.35rem !important;
    font-weight: 800 !important;
    color: #fff !important;
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.alm-pro-page--system > .content-header h1 small,
.alm-pro-page--system > section.content > .content-header h1 small,
.alm-pro-page--system .content-header .alm-legacy-hero__subtitle {
    display: block;
    margin-top: 4px;
    font-size: 0.85rem !important;
    font-weight: 500 !important;
    color: rgba(255, 255, 255, 0.82) !important;
}

.alm-pro-page--system > section.content,
.alm-pro-page--system > .content {
    padding: 0 16px 32px;
}

@media (max-width: 639px) {
    .alm-pro-page--system > .content-header:first-child,
    .alm-pro-page--system > section.content > .content-header:first-child {
        margin: 8px 10px 10px;
        padding: 14px 16px;
    }

    .alm-pro-page--system > section.content,
    .alm-pro-page--system > .content {
        padding: 0 10px 24px;
    }
}

/* ── Phase B: Global forms & inputs (body.alm-shell) ──────────────────────── */
body.alm-shell .form-control,
body.alm-shell .select2-container--default .select2-selection--single,
body.alm-shell .select2-container--default .select2-selection--multiple {
    border-radius: 10px !important;
    border-color: #cbd5e1 !important;
    min-height: 40px;
    font-size: 13px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

body.alm-shell .form-control:focus,
body.alm-shell .select2-container--open .select2-selection {
    border-color: var(--tm-brand, #0040c1) !important;
    box-shadow: 0 0 0 3px rgba(0, 64, 193, 0.12) !important;
    outline: none !important;
}

body.alm-shell textarea.form-control {
    min-height: 88px;
    height: auto;
}

body.alm-shell .input-group .input-group-addon {
    border-radius: 10px;
    border-color: #cbd5e1;
    background: #f8fafc;
}

body.alm-shell .btn,
body.alm-shell .tw-dw-btn {
    border-radius: 10px !important;
    font-weight: 600;
    transition: transform 0.12s, box-shadow 0.12s;
}

body.alm-shell .btn-primary,
body.alm-shell .tw-dw-btn-primary {
    background: var(--tm-brand, #0040c1) !important;
    border-color: var(--tm-brand, #0040c1) !important;
}

@media (max-width: 767px) {
    body.alm-shell .btn,
    body.alm-shell .tw-dw-btn,
    body.alm-shell .pagination > li > a {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    body.alm-shell .form-group {
        margin-bottom: 12px;
    }
}

/* ── Global boxes / cards ─────────────────────────────────────────────────── */
body.alm-shell .box,
body.alm-shell .box-primary,
body.alm-shell .box-solid,
body.alm-shell .tw-bg-white.tw-shadow-sm.tw-rounded-xl {
    border-radius: var(--alm-radius-sm, 12px) !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05) !important;
    overflow: hidden;
}

body.alm-shell .box-header {
    background: linear-gradient(to left, #f8fafc, #fff);
    border-bottom: 1px solid #e2e8f0;
    padding: 12px 16px !important;
}

body.alm-shell .box-header .box-title {
    font-weight: 700 !important;
    font-size: 14px !important;
    color: #1e293b !important;
}

body.alm-shell .box-body {
    padding: 14px 16px !important;
}

/* ── Global tables (desktop polish) ───────────────────────────────────────── */
body.alm-shell #scrollable-container table.table thead th,
body.alm-shell .modal table.table thead th {
    background: #f1f5f9 !important;
    color: #334155 !important;
    font-weight: 700 !important;
    font-size: 12px !important;
    padding: 10px 12px !important;
    white-space: nowrap;
    border-color: #e2e8f0 !important;
}

body.alm-shell #scrollable-container table.table tbody td,
body.alm-shell .modal table.table tbody td {
    font-size: 13px;
    vertical-align: middle !important;
    padding: 9px 12px !important;
    color: #475569;
}

body.alm-shell #scrollable-container table.table tbody tr:hover td {
    background: #f8fafc !important;
}

body.alm-shell .table-responsive {
    border-radius: 10px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

/* Prevent horizontal page scroll on mobile */
@media (max-width: 767px) {
    body.alm-shell #scrollable-container {
        overflow-x: hidden;
    }

    body.alm-shell .row {
        margin-left: 0;
        margin-right: 0;
    }

    body.alm-shell [class*="col-"] {
        padding-left: 8px;
        padding-right: 8px;
    }
}

/* ── Modals ───────────────────────────────────────────────────────────────── */
body.alm-shell .modal-content.alm-modal-pro,
body.alm-shell .modal.alm-enhanced .modal-content {
    border: none;
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.18);
    overflow: hidden;
}

body.alm-shell .modal-content.alm-modal-pro .modal-header,
body.alm-shell .modal.alm-enhanced .modal-header {
    background: linear-gradient(135deg, var(--tm-header-from, #0038a8), var(--tm-brand-light, #004eeb));
    color: #fff;
    border: none;
    padding: 16px 20px;
}

body.alm-shell .modal-content.alm-modal-pro .modal-header .modal-title,
body.alm-shell .modal.alm-enhanced .modal-header .modal-title {
    font-weight: 700;
    font-size: 1.05rem;
}

body.alm-shell .modal-content.alm-modal-pro .modal-header .close,
body.alm-shell .modal.alm-enhanced .modal-header .close {
    color: #fff;
    opacity: 0.85;
    text-shadow: none;
    font-size: 1.5rem;
}

body.alm-shell .modal-content.alm-modal-pro .modal-body,
body.alm-shell .modal.alm-enhanced .modal-body {
    padding: 18px 20px;
}

body.alm-shell .modal-content.alm-modal-pro .modal-footer,
body.alm-shell .modal.alm-enhanced .modal-footer {
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    padding: 12px 16px;
}

@media (max-width: 575px) {
    body.alm-shell .modal-dialog {
        margin: 10px;
        max-width: calc(100vw - 20px);
    }
}

/* ── Phase C: Module polish ───────────────────────────────────────────────── */

/* Repair */
.alm-pro-page--repair .box-solid,
.alm-pro-page--repair-job-sheet .box-solid,
body.alm-shell [data-alm-module="repair"] .nav-tabs-custom {
    border-radius: 12px;
    overflow: hidden;
}

/* HMS / Hotel */
.alm-pro-page--hms .db-kpi-grid,
.alm-pro-page--hms .box-solid,
body.alm-shell [data-alm-module="hms"] .content {
    overflow-x: hidden;
}

.alm-pro-page--hms .table-responsive,
body.alm-shell [data-alm-module="hms"] .table-responsive {
    max-width: 100%;
}

/* ZATCA */
.alm-pro-page--zatca-integrationksa .box-solid,
.alm-pro-page--zatcaintegrationksa .content,
body.alm-shell [data-alm-module="zatca-integration-ksa"] .table-responsive {
    overflow-x: auto;
}

/* Manufacturing */
body.alm-shell [data-alm-module="manufacturing"] .ingredients-table,
body.alm-shell [data-alm-module="manufacturing"] .table-responsive {
    overflow-x: auto;
}

/* Product Catalogue QR */
body.alm-shell [data-alm-module="product-catalogue"] .product-list,
body.alm-shell [data-alm-module="catalogue-qr"] img {
    max-width: 100%;
    height: auto;
}

/* Accounting */
body.alm-shell [data-alm-module="accounting"] .nav-tabs-custom,
body.alm-shell [data-alm-module="accounting"] .box-solid {
    margin-bottom: 14px;
}

/* Superadmin */
body.sa-module-page .alm-pro-page--system > .content-header {
    margin-top: 8px;
}

/* CRM legacy layout */
body.crm-module-page .content-wrapper .alm-pro-page--system,
.crm-module-page.alm-shell .content-wrapper {
    background: var(--tm-body-bg, #f0f4f9);
}

/* Essentials / HRM tabs */
body.alm-shell [data-alm-module="essentials"] .nav-tabs,
body.alm-shell [data-alm-module="hrm"] .nav-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Icon clipping fix */
body.alm-shell .fa,
body.alm-shell .fas,
body.alm-shell .far,
body.alm-shell svg {
    flex-shrink: 0;
}

body.alm-shell .sb-icon svg,
body.alm-shell .btn svg,
body.alm-shell .alm-hero__icon i {
    overflow: visible;
}

/* Select2 dropdown z-index in modals */
body.alm-shell .select2-container {
    max-width: 100%;
}

/* DataTables controls stack on mobile */
@media (max-width: 767px) {
    body.alm-shell .dataTables_wrapper .dataTables_length,
    body.alm-shell .dataTables_wrapper .dataTables_filter,
    body.alm-shell .dataTables_wrapper .dt-buttons {
        float: none !important;
        width: 100%;
        text-align: right;
        margin-bottom: 8px;
    }

    body.alm-shell .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        margin-right: 0 !important;
    }
}

/* ── Dark mode ────────────────────────────────────────────────────────────── */
[data-theme="dark"] body.alm-shell .box,
[data-theme="dark"] body.alm-shell .box-primary,
[data-theme="dark"] body.alm-shell .box-solid {
    background: #1e293b !important;
    border-color: #334155 !important;
}

[data-theme="dark"] body.alm-shell .box-header {
    background: linear-gradient(to left, #1e293b, #0f172a) !important;
    border-color: #334155 !important;
}

[data-theme="dark"] body.alm-shell .form-control {
    background: #0f172a !important;
    border-color: #475569 !important;
    color: #f1f5f9 !important;
}

[data-theme="dark"] .alm-pro-page--system > .content-header {
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] body.alm-shell .modal-content.alm-modal-pro .modal-footer {
    background: #0f172a;
    border-color: #334155;
}

/* ── Phase D: Enterprise extensions (tabs, info boxes, breadcrumbs) ─────────── */
body.alm-shell .info-box {
    border-radius: 14px !important;
    box-shadow: 0 2px 12px rgba(15, 23, 42, .06) !important;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    min-height: 88px;
}

body.alm-shell .info-box-icon {
    border-radius: 0 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
}

body.alm-shell .info-box-content {
    padding: 12px 14px !important;
}

body.alm-shell .info-box-text {
    font-size: 12px !important;
    font-weight: 600 !important;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #64748b !important;
}

body.alm-shell .info-box-number {
    font-size: 22px !important;
    font-weight: 800 !important;
    color: #0f172a !important;
}

body.alm-shell .breadcrumb {
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    font-size: 12px;
}

body.alm-shell .breadcrumb > li + li:before {
    color: rgba(255, 255, 255, .5);
}

body.alm-shell .content-header .breadcrumb > .active {
    color: rgba(255, 255, 255, .9) !important;
}

body.alm-shell .pagination > .active > a,
body.alm-shell .pagination > .active > span {
    background: var(--tm-brand, #2563eb) !important;
    border-color: var(--tm-brand, #2563eb) !important;
}

body.alm-shell .nav-pills > li.active > a {
    background: var(--tm-brand, #2563eb) !important;
    border-radius: 10px !important;
}

body.alm-shell .well,
body.alm-shell .panel {
    border-radius: 12px !important;
    border-color: #e2e8f0 !important;
    box-shadow: 0 2px 10px rgba(15, 23, 42, .04) !important;
}

body.alm-shell .panel-heading {
    border-radius: 12px 12px 0 0 !important;
    font-weight: 700;
}

/* Empty state helper */
body.alm-shell .tw-text-center.tw-text-gray-500 {
    padding: 24px;
}

/* Print: strip decorative layers */
@media print {
    .alm-pro-page--system > .content-header {
        background: none !important;
        color: #000 !important;
        box-shadow: none !important;
        margin: 0;
        padding: 0;
    }

    .alm-pro-page--system > .content-header h1,
    .alm-pro-page--system > .content-header h1 small {
        color: #000 !important;
    }
}
