:root {
    --bs-bg: #f5f7fb;
    --bs-card: #ffffff;
    --bs-text: #101828;
    --bs-muted: #667085;
    --bs-border: #e5e7eb;
    --bs-primary: #2563eb;
    --bs-primary-dark: #1e40af;
    --bs-sidebar: #0f172a;
    --bs-sidebar-soft: #1e293b;
    --bs-shadow: 0 16px 40px rgba(15, 23, 42, .08);
    --bs-radius: 22px;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bs-bg);
    color: var(--bs-text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.rtl {
    font-family: Tahoma, Arial, sans-serif;
}

body.dark-mode {
    --bs-bg: #0b1120;
    --bs-card: #111827;
    --bs-text: #f8fafc;
    --bs-muted: #94a3b8;
    --bs-border: #243044;
    --bs-sidebar: #030712;
    --bs-sidebar-soft: #111827;
    --bs-shadow: 0 16px 40px rgba(0, 0, 0, .3);
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: 280px;
    background: linear-gradient(180deg, var(--bs-sidebar), var(--bs-sidebar-soft));
    color: #fff;
    z-index: 1040;
    padding: 22px 16px;
    transition: transform .25s ease;
}

.brand-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 8px 24px;
}

.brand-mark,
.login-logo {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #38bdf8, #2563eb);
    color: #fff;
    font-weight: 900;
    box-shadow: 0 12px 30px rgba(37, 99, 235, .35);
}

.brand-title { font-weight: 800; letter-spacing: .5px; }
.brand-subtitle { color: rgba(255,255,255,.58); font-size: 12px; }

.sidebar-nav { display: grid; gap: 8px; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: rgba(255,255,255,.72);
    text-decoration: none;
    border-radius: 16px;
    padding: 13px 14px;
    transition: .2s ease;
}
.sidebar-link i { font-size: 18px; }
.sidebar-link:hover,
.sidebar-link.active {
    color: #fff;
    background: rgba(255,255,255,.10);
}
.disabled-link { opacity: .55; cursor: not-allowed; }

.app-main {
    width: 100%;
    margin-inline-start: 280px;
    min-height: 100vh;
}

.app-topbar {
    height: 74px;
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: rgba(245, 247, 251, .8);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--bs-border);
}
.dark-mode .app-topbar { background: rgba(11, 17, 32, .85); }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.language-switch { min-width: 118px; }

.btn-soft,
.icon-btn,
.user-menu {
    background: var(--bs-card);
    border: 1px solid var(--bs-border);
    color: var(--bs-text);
    border-radius: 14px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
}
.avatar-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #eff6ff;
    color: #1d4ed8;
    display: grid;
    place-items: center;
    font-weight: 800;
}

.content-wrap {
    padding: 26px;
}

.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}
.page-heading h1 { font-size: 28px; font-weight: 800; margin: 0 0 6px; }
.page-heading p { color: var(--bs-muted); margin: 0; }
.heading-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sticky-heading {
    position: sticky;
    top: 82px;
    z-index: 100;
    background: var(--bs-bg);
    padding: 8px 0;
}

.app-card,
.stat-card {
    background: var(--bs-card);
    border: 1px solid var(--bs-border);
    border-radius: var(--bs-radius);
    box-shadow: var(--bs-shadow);
}

.app-card { padding: 22px; }
.stat-card {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat-icon {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: #eff6ff;
    color: var(--bs-primary);
    font-size: 24px;
}
.stat-card span { display: block; color: var(--bs-muted); font-size: 14px; }
.stat-card strong { display: block; font-size: 28px; line-height: 1; margin-top: 5px; }

.card-title-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}
.card-title-row h5 { font-weight: 800; margin-bottom: 5px; }
.card-title-row p { color: var(--bs-muted); margin: 0; }
.phase-checklist { display: grid; gap: 10px; }
.phase-checklist div {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(37, 99, 235, .07);
}
.phase-checklist i { color: #16a34a; }
.gradient-card { background: linear-gradient(135deg, #2563eb, #0f172a); }

.app-table th {
    color: var(--bs-muted);
    font-size: 13px;
    white-space: nowrap;
    border-bottom: 1px solid var(--bs-border);
}
.app-table td { vertical-align: middle; border-color: var(--bs-border); }
.dark-mode .table { --bs-table-color: var(--bs-text); --bs-table-bg: transparent; --bs-table-border-color: var(--bs-border); }

.toolbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.search-box {
    position: relative;
    min-width: min(420px, 100%);
}
.search-box i {
    position: absolute;
    inset-inline-start: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--bs-muted);
}
.search-box input { padding-inline-start: 42px; border-radius: 14px; }
.translation-table-wrap { max-height: calc(100vh - 250px); }
.translation-input { min-width: 240px; border-radius: 12px; }

.form-control,
.form-select {
    background-color: var(--bs-card);
    color: var(--bs-text);
    border-color: var(--bs-border);
}
.form-control:focus,
.form-select:focus { box-shadow: 0 0 0 .2rem rgba(37,99,235,.15); }

.login-page {
    background: radial-gradient(circle at top left, #dbeafe, transparent 28%), linear-gradient(135deg, #f8fafc, #eef2ff);
}
.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    align-items: center;
    gap: 40px;
    padding: 50px;
}
.login-visual {
    position: relative;
    min-height: 560px;
    border-radius: 34px;
    overflow: hidden;
    background: linear-gradient(135deg, #020617, #1e40af);
    box-shadow: var(--bs-shadow);
}
.screen-frame {
    position: absolute;
    border-radius: 28px;
    background: linear-gradient(135deg, rgba(56,189,248,.85), rgba(37,99,235,.35));
    border: 1px solid rgba(255,255,255,.18);
    box-shadow: 0 24px 60px rgba(0,0,0,.28);
}
.screen-one { width: 48%; height: 42%; top: 10%; left: 9%; }
.screen-two { width: 30%; height: 60%; top: 22%; right: 11%; }
.screen-three { width: 42%; height: 22%; bottom: 12%; left: 18%; }
.visual-copy {
    position: absolute;
    left: 46px;
    right: 46px;
    bottom: 42px;
    color: #fff;
    max-width: 540px;
}
.brand-pill {
    display: inline-flex;
    padding: 8px 13px;
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    margin-bottom: 16px;
    font-weight: 800;
}
.visual-copy h1 { font-size: 44px; font-weight: 900; line-height: 1; margin-bottom: 12px; }
.visual-copy p { color: rgba(255,255,255,.75); font-size: 17px; }
.login-card {
    width: min(460px, 100%);
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,.7);
    border-radius: 30px;
    box-shadow: var(--bs-shadow);
    padding: 34px;
    justify-self: center;
}

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .42);
    z-index: 1030;
}

@media (max-width: 992px) {
    .app-sidebar { transform: translateX(-105%); }
    html[dir="rtl"] .app-sidebar { transform: translateX(105%); }
    .app-sidebar.show { transform: translateX(0); }
    .app-main { margin-inline-start: 0; }
    .content-wrap { padding: 18px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .mobile-overlay.show { display: block; }
    .login-shell { grid-template-columns: 1fr; padding: 24px; }
    .login-visual { display: none; }
}

@media (max-width: 576px) {
    .app-topbar { padding: 0 12px; gap: 8px; }
    .topbar-title { display: none; }
    .topbar-actions { gap: 6px; }
    .language-switch { min-width: 96px; }
    .app-card { padding: 16px; }
    .toolbar-row { flex-direction: column; align-items: stretch; }
    .sticky-heading { top: 74px; }
}

/* Phase 3 — Companies + Branding */
.companies-heading {
    z-index: 1010;
}
.compact-stat {
    min-height: 102px;
}
.wide-table-wrap {
    overflow-x: auto;
}
.action-col {
    position: sticky;
    inset-inline-end: 0;
    background: var(--bs-card) !important;
    z-index: 3;
    min-width: 160px;
}
.table-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
    white-space: nowrap;
}
.company-logo-box,
.company-logo-placeholder {
    width: 54px;
    height: 42px;
    border: 1px solid var(--bs-border);
    border-radius: 14px;
    background: #fff;
    display: grid;
    place-items: center;
    overflow: hidden;
}
.company-logo-box img {
    max-width: 90%;
    max-height: 82%;
    object-fit: contain;
}
.company-logo-placeholder {
    background: linear-gradient(135deg, rgba(37,99,235,.14), rgba(56,189,248,.2));
    color: var(--bs-primary);
    font-weight: 900;
}
.color-dots {
    display: flex;
    align-items: center;
    gap: 6px;
}
.color-dots span {
    width: 22px;
    height: 22px;
    border-radius: 999px;
    border: 2px solid rgba(255,255,255,.9);
    box-shadow: 0 0 0 1px var(--bs-border);
}
.form-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 15px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(37, 99, 235, .08);
    color: var(--bs-primary);
    margin-bottom: 14px;
}
.required-label::after {
    content: ' *';
    color: #dc2626;
}
.app-modal {
    border: 0;
    border-radius: 24px;
    overflow: hidden;
    background: var(--bs-card);
    color: var(--bs-text);
}
.logo-preview {
    min-height: 54px;
    border: 1px dashed var(--bs-border);
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, .03);
}
.logo-preview img {
    max-width: 160px;
    max-height: 46px;
    object-fit: contain;
}
.dark-preview {
    background: #0f172a;
}
.dark-mode .modal-content {
    background: var(--bs-card);
    color: var(--bs-text);
}
.dark-mode .btn-close {
    filter: invert(1) grayscale(100%);
}

@media (max-width: 576px) {
    .table-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .action-col {
        min-width: 110px;
    }
    .company-logo-box,
    .company-logo-placeholder {
        width: 46px;
        height: 36px;
    }
}

/* Phase 3.1 — B|SCREENS brand assets + Update Center */
.brand-logo-img {
    display: block;
    object-fit: contain;
}
.brand-logo-sidebar {
    width: 210px;
    max-width: 100%;
    height: 54px;
    object-position: left center;
}
html[dir="rtl"] .brand-logo-sidebar {
    object-position: right center;
}
.brand-text-fallback {
    display: none;
}
.brand-pill {
    min-height: 42px;
    align-items: center;
}
.brand-pill img {
    width: 190px;
    max-width: 100%;
    height: auto;
    display: block;
}
.login-logo-img {
    width: 140px;
    height: 102px;
    border-radius: 20px;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: rgba(15, 23, 42, .04);
    border: 1px solid rgba(15, 23, 42, .08);
}
.login-logo-img img {
    width: 118px;
    height: auto;
    object-fit: contain;
}
.feature-badge,
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(37, 99, 235, .1);
    color: var(--bs-primary);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}
.update-progress {
    height: 22px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(37, 99, 235, .12);
}
.update-progress .progress-bar {
    font-weight: 800;
}
.update-status-applied,
.update-status-validated {
    background: rgba(22, 163, 74, .11);
    color: #16a34a;
}
.update-status-failed {
    background: rgba(220, 38, 38, .11);
    color: #dc2626;
}
.update-status-reverted {
    background: rgba(245, 158, 11, .14);
    color: #b45309;
}
.update-status-uploaded {
    background: rgba(37, 99, 235, .1);
    color: var(--bs-primary);
}
.dark-mode .login-logo-img {
    background: rgba(255, 255, 255, .06);
    border-color: rgba(255, 255, 255, .12);
}
@media (max-width: 992px) {
    .brand-logo-sidebar {
        width: 190px;
    }
}

/* Phase 4 — Branches, Screens, Pairing, and safe modal overlay layering */
.modal-backdrop {
    z-index: 1045 !important;
}
.modal {
    z-index: 1055 !important;
}
.modal.show {
    z-index: 1055 !important;
}
body.modal-open .mobile-overlay {
    display: none !important;
    pointer-events: none !important;
}
.modal-open .app-sidebar.show {
    transform: translateX(-105%);
}
html[dir="rtl"] .modal-open .app-sidebar.show {
    transform: translateX(105%);
}

.location-card-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}
.branch-code,
.screen-code,
.pairing-code {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 12px;
    font-weight: 800;
    background: rgba(15, 23, 42, .06);
    color: var(--bs-text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    white-space: nowrap;
}
.dark-mode .branch-code,
.dark-mode .screen-code,
.dark-mode .pairing-code {
    background: rgba(255, 255, 255, .08);
}
.branch-company-label,
.screen-branch-label {
    display: block;
    color: var(--bs-muted);
    font-size: 12px;
    margin-top: 3px;
}
.orientation-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(37, 99, 235, .1);
    color: var(--bs-primary);
    font-weight: 800;
    font-size: 12px;
}
.connection-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    background: #94a3b8;
    box-shadow: 0 0 0 4px rgba(148, 163, 184, .15);
}
.connection-dot.online {
    background: #16a34a;
    box-shadow: 0 0 0 4px rgba(22, 163, 74, .15);
}
.connection-dot.offline {
    background: #dc2626;
    box-shadow: 0 0 0 4px rgba(220, 38, 38, .15);
}
.connection-dot.pending {
    background: #f59e0b;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, .16);
}
.status-stack {
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: flex-start;
}
.copyable-input-group .form-control {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
}
.player-shell {
    min-height: 100vh;
    background: radial-gradient(circle at top left, rgba(37,99,235,.24), transparent 32%), linear-gradient(135deg, #020617, #111827);
    color: #fff;
    display: grid;
    place-items: center;
    padding: 24px;
}
.player-card {
    width: min(560px, 100%);
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(15, 23, 42, .72);
    backdrop-filter: blur(18px);
    border-radius: 32px;
    box-shadow: 0 30px 90px rgba(0,0,0,.38);
    padding: 34px;
}
.player-card .brand-logo-img {
    width: 220px;
    max-width: 100%;
    margin-bottom: 18px;
}
.player-ready-box {
    border: 1px dashed rgba(255,255,255,.24);
    border-radius: 22px;
    padding: 18px;
    background: rgba(255,255,255,.06);
}
.screen-preview-frame {
    width: 92px;
    height: 52px;
    border-radius: 14px;
    border: 3px solid currentColor;
    display: grid;
    place-items: center;
    color: var(--bs-primary);
    background: rgba(37, 99, 235, .07);
}
.screen-preview-frame.portrait {
    width: 48px;
    height: 76px;
}
.screen-preview-frame.square {
    width: 62px;
    height: 62px;
}
@media (max-width: 1200px) {
    .location-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 576px) {
    .location-card-grid { grid-template-columns: 1fr; }
    .app-table .table-actions { min-width: 96px; }
    .player-card { padding: 22px; border-radius: 24px; }
}


/* Phase 5 — Media Library, AI Assistant, and stronger modal overlay safety */
body.modal-open .modal-backdrop.show {
    opacity: .5;
    pointer-events: auto;
}
body.modal-open .modal.show {
    display: block;
    pointer-events: auto;
}
body.modal-open .app-topbar,
body.modal-open .app-sidebar,
body.modal-open .mobile-overlay {
    z-index: 1030 !important;
}
.media-preview-thumb {
    width: 96px;
    height: 58px;
    object-fit: cover;
    border-radius: 14px;
    background: rgba(15, 23, 42, .06);
    border: 1px solid var(--bs-border);
}
.media-preview-thumb.portrait {
    width: 48px;
    height: 78px;
}
.media-preview-thumb.square {
    width: 64px;
    height: 64px;
}
.media-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    background: rgba(37, 99, 235, .1);
    color: var(--bs-primary);
}
.media-meta-small {
    display: block;
    font-size: 12px;
    color: var(--bs-muted);
    margin-top: 3px;
}
.dropzone-lite {
    border: 2px dashed var(--bs-border);
    border-radius: 22px;
    padding: 22px;
    background: rgba(37,99,235,.035);
    text-align: center;
    transition: .2s ease;
}
.dropzone-lite:hover {
    border-color: var(--bs-primary);
    background: rgba(37,99,235,.07);
}
.upload-progress-wrap {
    display: none;
    margin-top: 12px;
}
.ai-fab {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1015;
    border: 0;
    border-radius: 999px;
    padding: 13px 18px;
    box-shadow: 0 16px 42px rgba(15, 23, 42, .22);
    background: linear-gradient(135deg, var(--bs-primary), #111827);
    color: #fff;
    font-weight: 800;
}
html[dir="rtl"] .ai-fab {
    right: auto;
    left: 22px;
}
body.modal-open .ai-fab {
    z-index: 1030;
}
.ai-result-box {
    min-height: 220px;
    border: 1px solid var(--bs-border);
    border-radius: 20px;
    background: rgba(15, 23, 42, .03);
    padding: 18px;
    white-space: pre-wrap;
    color: var(--bs-text);
}
.dark-mode .ai-result-box {
    background: rgba(255,255,255,.05);
}
.ai-context-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    background: rgba(245, 158, 11, .12);
    color: #b45309;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 800;
}
@media (max-width: 576px) {
    .ai-fab { right: 14px; bottom: 14px; padding: 12px 14px; }
    html[dir="rtl"] .ai-fab { left: 14px; }
    .ai-fab span { display: none; }
    .media-preview-thumb { width: 84px; height: 52px; }
    .table-actions { display: grid; grid-template-columns: 1fr; gap: 6px; }
    .table-actions .btn { width: 100%; justify-content: center; }
}

/* Phase 5.1 — Hard modal overlay fix
   Reason: Bootstrap backdrops can appear above modals when modals are rendered inside layout containers or stale backdrops remain after AJAX/DataTable actions. */
:root {
    --bscreens-z-backdrop: 2147483000;
    --bscreens-z-modal: 2147483010;
    --bscreens-z-modal-dialog: 2147483020;
}

body.modal-open > .modal-backdrop,
body.modal-open .modal-backdrop,
.modal-backdrop,
.modal-backdrop.fade,
.modal-backdrop.fade.show,
.modal-backdrop.show {
    position: fixed !important;
    inset: 0 !important;
    z-index: var(--bscreens-z-backdrop) !important;
    pointer-events: auto !important;
}

body.modal-open > .modal,
body.modal-open .modal,
body.modal-open .modal.show,
.modal.show {
    position: fixed !important;
    inset: 0 !important;
    z-index: var(--bscreens-z-modal) !important;
    pointer-events: none !important;
}

body.modal-open .modal .modal-dialog,
.modal.show .modal-dialog {
    position: relative !important;
    z-index: var(--bscreens-z-modal-dialog) !important;
    pointer-events: auto !important;
}

body.modal-open .modal .modal-content,
.modal.show .modal-content {
    position: relative !important;
    z-index: var(--bscreens-z-modal-dialog) !important;
}

body.modal-open .app-sidebar,
body.modal-open .app-topbar,
body.modal-open .mobile-overlay,
body.modal-open .ai-fab,
body.modal-open .dropdown-menu,
body.modal-open .sticky-heading,
body.modal-open .action-col {
    z-index: 1000 !important;
}

body.modal-open .mobile-overlay,
body.modal-open .mobile-overlay.show {
    display: none !important;
    pointer-events: none !important;
}

body.modal-open .app-sidebar.show {
    transform: translateX(-105%) !important;
}

html[dir="rtl"] body.modal-open .app-sidebar.show {
    transform: translateX(105%) !important;
}
