:root {
    --bg-0: #ecf1f4;
    --bg-1: #f8fafc;
    --text: #202b36;
    --muted: #5a6979;
    --sidebar: #2f3845;
    --sidebar-soft: #394554;
    --surface: rgba(255, 255, 255, 0.82);
    --surface-border: rgba(255, 255, 255, 0.92);
    --primary: #1c92bf;
    --primary-strong: #16789d;
    --danger: #ec6369;
    --success: #21a074;
    --shadow: 0 18px 44px rgba(21, 34, 50, 0.13);
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(1200px 600px at 6% -10%, rgba(28, 146, 191, 0.20), transparent 62%),
        radial-gradient(920px 620px at 105% 10%, rgba(236, 99, 105, 0.18), transparent 58%),
        linear-gradient(145deg, var(--bg-0), var(--bg-1));
    font-family: "Outfit", "Segoe UI", sans-serif;
}

html[lang="ar"] body {
    font-family: "Tajawal", "Segoe UI", sans-serif;
}

body.nav-open {
    overflow: hidden;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-strong);
}

.ambient-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(30px);
    pointer-events: none;
    z-index: 0;
}

.ambient-orb.one {
    width: 220px;
    height: 220px;
    background: rgba(28, 146, 191, 0.16);
    inset-inline-start: -60px;
    top: 110px;
}

.ambient-orb.two {
    width: 200px;
    height: 200px;
    background: rgba(236, 99, 105, 0.16);
    inset-inline-end: -56px;
    top: 260px;
}

.portal-shell {
    position: relative;
    min-height: 100vh;
    display: flex;
}

[dir="rtl"] .portal-shell {
    flex-direction: row-reverse;
}

[dir="ltr"] .portal-shell {
    flex-direction: row;
}

.portal-sidebar {
    width: 290px;
    background: linear-gradient(182deg, #4f5258, #474a50 36%, #3e4248 100%);
    color: #e6edf6;
    padding: 0.8rem 0;
    box-shadow: 0 0 26px rgba(20, 30, 43, 0.25);
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    transition: transform 0.24s ease;
}

.sidebar-overlay {
    display: none;
}

.mobile-sidebar-close {
    display: none;
}

.brand-block {
    border: 1px solid rgba(255, 255, 255, 0.09);
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
}

.brand-name {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 0.2px;
}

.brand-sub {
    margin: 0.3rem 0 0;
    opacity: 0.8;
    font-size: 0.9rem;
}

.sidebar-nav {
    display: grid;
    gap: 0;
}

.menu-main {
    width: 100%;
    border: 0;
    background: transparent;
    color: #e8edf6;
    text-align: start;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
    padding: 0.88rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-weight: 700;
    font-size: 1.14rem;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.menu-main:hover {
    color: #fff;
    background: rgba(162, 197, 187, 0.12);
}

.menu-main.active {
    color: #fff;
    background: rgba(162, 197, 187, 0.34);
}

.menu-main-label {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
}

.menu-main-label i {
    font-size: 1rem;
    opacity: 0.9;
}

.menu-toggle {
    cursor: pointer;
}

.menu-arrow {
    font-size: 0.88rem;
    transition: transform 0.2s ease;
    opacity: 0.85;
}

.menu-toggle.collapsed .menu-arrow {
    transform: rotate(-90deg);
}

[dir="ltr"] .menu-toggle.collapsed .menu-arrow {
    transform: rotate(90deg);
}

.menu-sub {
    background: rgba(21, 23, 27, 0.14);
}

.menu-sub-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #dce4ef;
    padding: 0.72rem 1.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-weight: 700;
    font-size: 1.02rem;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.menu-sub-link i {
    font-size: 0.86rem;
    opacity: 0.85;
}

.menu-sub-link:hover {
    color: #fff;
    background: rgba(157, 188, 178, 0.22);
}

.menu-sub-link.active {
    color: #fff;
    background: rgba(157, 188, 178, 0.4);
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 0.8rem;
    padding: 0 1rem 0.8rem;
}

.locale-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
}

.lang-chip {
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #d8e1ec;
    padding: 0.35rem 0.2rem;
    border-radius: 999px;
    font-size: 0.82rem;
    transition: 0.2s ease;
}

.lang-chip:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.45);
}

.lang-chip.active {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(145deg, rgba(28, 146, 191, 0.92), rgba(24, 123, 159, 0.96));
}

.user-identity {
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.75rem;
    display: grid;
    gap: 0.45rem;
}

.user-identity-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
}

.portal-main {
    flex: 1;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    padding: 0.75rem 1.2rem 1.4rem;
    overflow-x: hidden;
}

.portal-topbar {
    border: 1px solid rgba(255, 255, 255, 0.56);
    background: linear-gradient(180deg, #5e6268, #52565d);
    border-radius: var(--radius-md);
    padding: 0.82rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.8rem;
    color: #f4f7fb;
    gap: 0.75rem;
}

.topbar-copy {
    display: grid;
    gap: 0.15rem;
}

[dir="rtl"] .topbar-copy {
    margin-inline-start: auto;
    text-align: end;
}

[dir="ltr"] .topbar-copy {
    margin-inline-end: auto;
    text-align: start;
}

.mobile-menu-toggle {
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.12);
    color: #f4f7fb;
    border-radius: 10px;
    width: 42px;
    height: 42px;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
}

.mobile-menu-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.mobile-menu-toggle:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.75);
    outline-offset: 2px;
}

.topbar-title {
    margin: 0;
    font-size: clamp(1.15rem, 2vw, 1.45rem);
    font-weight: 800;
}

.topbar-eyebrow {
    margin: 0;
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.86rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.portal-crumb {
    border: 1px solid rgba(20, 35, 53, 0.1);
    background: rgba(233, 235, 238, 0.92);
    border-radius: var(--radius-sm);
    padding: 0.66rem 0.9rem;
    color: #4d5d70;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    min-width: 0;
}

.portal-crumb .sep {
    opacity: 0.56;
}

.portal-crumb strong {
    color: #2d3c4d;
    word-break: break-word;
}

.page-stack {
    display: grid;
    gap: 1rem;
}

.surface {
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: riseIn 0.35s ease;
}

.surface-head {
    border-bottom: 1px solid rgba(30, 50, 70, 0.07);
    padding: 0.9rem 1rem;
    font-size: 1rem;
    font-weight: 800;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.9), rgba(241, 247, 252, 0.85));
}

.surface-body {
    padding: 1rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.stat-card {
    border: 1px solid var(--surface-border);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.66));
    border-radius: var(--radius-md);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.stat-card p {
    margin: 0;
    color: var(--muted);
    font-weight: 600;
}

.stat-card h3 {
    margin: 0.2rem 0 0;
    font-size: 2rem;
    font-weight: 800;
}

.flow-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.7rem;
}

.routing-card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.routing-card {
    border: 1px solid rgba(26, 44, 60, 0.12);
    border-radius: 12px;
    color: #fff;
    padding: 0.85rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 1.15rem;
    font-weight: 800;
    box-shadow: 0 10px 20px rgba(20, 30, 43, 0.14);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.routing-card:hover {
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 14px 26px rgba(20, 30, 43, 0.17);
}

.routing-card i {
    font-size: 1.9rem;
}

.routing-card-text {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.05;
    gap: 0.25rem;
}

[dir='ltr'] .routing-card-text {
    align-items: flex-start;
}

.routing-card-title {
    font-size: 1.65rem;
    font-weight: 800;
}

.routing-card-count {
    font-size: 2.25rem;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.routing-card--internal {
    background: linear-gradient(145deg, #22a6a3, #219f9f);
}

.routing-card--outgoing {
    background: linear-gradient(145deg, #ef6f76, #ea636b);
}

.routing-card--incoming {
    background: linear-gradient(145deg, #1c92bf, #177da3);
}

.routing-card.is-active {
    outline: 3px solid rgba(255, 255, 255, 0.65);
    outline-offset: -3px;
}

.flow-step {
    border-radius: var(--radius-sm);
    padding: 0.72rem 0.8rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(145deg, rgba(28, 146, 191, 0.92), rgba(24, 123, 159, 0.95));
}

.flow-step.is-active {
    background: linear-gradient(145deg, rgba(236, 99, 105, 0.94), rgba(221, 79, 86, 0.97));
    box-shadow: 0 11px 20px rgba(236, 99, 105, 0.28);
}

.flow-step span {
    display: block;
    font-size: 0.8rem;
    opacity: 0.86;
    margin-top: 0.2rem;
}

.wizard-steps .flow-step {
    border: 0;
    width: 100%;
    text-align: start;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.wizard-steps .flow-step:hover {
    transform: translateY(-1px);
}

.wizard-steps .flow-step:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.75);
    outline-offset: -2px;
}

.wizard-pane {
    display: none;
}

.wizard-pane.is-active {
    display: block;
    animation: riseIn 0.22s ease;
}

.wizard-pane-title {
    margin: 0 0 1rem;
    font-size: 1.45rem;
    font-weight: 800;
    color: #334457;
}

.wizard-actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
}

.wizard-actions .btn {
    min-width: 118px;
}

.form-control,
.form-select {
    border-radius: 10px;
    border-color: rgba(34, 55, 77, 0.17);
    background: rgba(255, 255, 255, 0.95);
    min-height: 42px;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(28, 146, 191, 0.72);
    box-shadow: 0 0 0 0.2rem rgba(28, 146, 191, 0.15);
}

.table-wrap {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    margin: 0;
}

.users-table {
    table-layout: auto;
}

.users-table .users-col-name {
    min-width: 120px;
}

.users-table .users-col-email {
    min-width: 190px;
}

.users-table .users-email-text {
    display: inline-block;
    word-break: break-word;
}

.users-table .users-col-title {
    min-width: 115px;
}

.users-table .users-col-privilege {
    min-width: 130px;
}

.users-table .users-col-status {
    min-width: 82px;
}

.users-table .users-col-totp {
    min-width: 170px;
}

.users-table .users-col-actions {
    min-width: 160px;
}

.users-table .users-totp-actions {
    margin-top: 0.45rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.users-table .users-totp-actions form {
    margin: 0;
}

.users-table .users-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: flex-start;
}

[dir="rtl"] .users-table .users-row-actions {
    justify-content: flex-end;
}

.table thead th {
    font-weight: 800;
    color: #344457;
    border-bottom-width: 1px;
}

.table > :not(caption) > * > * {
    padding: 0.7rem 0.72rem;
    vertical-align: middle;
    background: transparent;
}

.table tbody tr:hover {
    background: rgba(28, 146, 191, 0.06);
}

.legacy-details-surface {
    border-radius: 12px;
}

.legacy-detail-table {
    margin: 0;
}

.legacy-detail-table > :not(caption) > * > * {
    padding: 0.65rem 0.72rem;
    border-color: rgba(70, 72, 75, 0.12);
}

.legacy-detail-table th {
    width: min(34%, 320px);
    background: #76787c;
    color: #f7f7f8;
    font-weight: 700;
    text-align: center;
}

.legacy-detail-table td {
    background: rgba(255, 255, 255, 0.92);
    text-align: center;
}

.legacy-pill {
    border-radius: 999px;
    min-width: 170px;
}

.barcode-cell {
    background: #ffffff;
}

.legacy-barcode-image {
    width: min(240px, 100%);
    height: 56px;
    object-fit: contain;
}

.badge-flag {
    display: inline-block;
    font-size: 0.76rem;
    border-radius: 999px;
    padding: 0.2rem 0.52rem;
    background: rgba(28, 146, 191, 0.13);
    color: #185f7c;
    border: 1px solid rgba(28, 146, 191, 0.3);
    margin: 0.12rem;
    font-weight: 700;
}

.btn {
    border-radius: 10px;
    font-weight: 700;
}

.btn-primary {
    background: linear-gradient(145deg, var(--primary), var(--primary-strong));
    border-color: transparent;
}

.btn-primary:hover,
.btn-primary:focus {
    background: linear-gradient(145deg, #1a87b1, #146f93);
}

.btn-outline-danger {
    border-color: rgba(236, 99, 105, 0.5);
    color: #d64553;
}

.btn-outline-danger:hover {
    background: rgba(236, 99, 105, 0.12);
    color: #bf3645;
    border-color: rgba(236, 99, 105, 0.65);
}

.btn-outline-secondary {
    border-color: rgba(27, 45, 64, 0.25);
    color: #2e4055;
}

.btn-outline-secondary:hover {
    background: rgba(46, 64, 85, 0.08);
}

.alert {
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
}

.alert-success {
    background: rgba(33, 160, 116, 0.13);
    border-color: rgba(33, 160, 116, 0.35);
    color: #1a6f51;
}

.alert-danger {
    background: rgba(236, 99, 105, 0.13);
    border-color: rgba(236, 99, 105, 0.35);
    color: #8f2f39;
}

.pagination {
    margin: 0;
    gap: 0.3rem;
}

.page-link {
    border-radius: 9px !important;
    border-color: rgba(33, 55, 77, 0.2);
    color: #254259;
}

.page-item.active .page-link {
    background: linear-gradient(145deg, var(--primary), var(--primary-strong));
    border-color: transparent;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-card {
    width: min(520px, 100%);
    border: 1px solid var(--surface-border);
    border-radius: 22px;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.auth-head {
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid rgba(30, 50, 70, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}

.auth-title {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
}

.auth-sub {
    margin: 0.2rem 0 0;
    color: var(--muted);
}

.auth-body {
    padding: 1.2rem 1.25rem 1.3rem;
}

.modal {
    z-index: 2000;
}

.modal-backdrop {
    z-index: 1990;
}

.modal-content {
    pointer-events: auto;
    border-radius: var(--radius-md);
}

.modal-open .sidebar-overlay,
.modal-open .portal-sidebar {
    pointer-events: none !important;
}

.muted-label {
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.rtl-fix {
    text-align: start;
}

@media (max-width: 1200px) {
    .portal-shell {
        flex-direction: column !important;
    }

    .portal-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        width: min(90vw, 340px);
        padding: 0.8rem 0;
        z-index: 40;
        overflow-y: auto;
        visibility: hidden;
        pointer-events: none;
    }

    [dir="rtl"] .portal-sidebar {
        inset-inline-end: 0;
        inset-inline-start: auto;
        transform: translate3d(calc(100% + 12px), 0, 0);
    }

    [dir="ltr"] .portal-sidebar {
        inset-inline-start: 0;
        inset-inline-end: auto;
        transform: translate3d(calc(-100% - 12px), 0, 0);
    }

    .portal-sidebar.is-open {
        transform: translate3d(0, 0, 0);
        visibility: visible;
        pointer-events: auto;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(10, 18, 28, 0.45);
        z-index: 35;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    .sidebar-overlay.is-open {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-nav {
        grid-template-columns: 1fr;
    }

    .portal-main {
        padding: 0.9rem;
    }

    .stats-grid,
    .flow-steps,
    .routing-card-grid {
        grid-template-columns: 1fr;
    }

    .routing-card-title {
        font-size: 1.35rem;
    }

    .routing-card-count {
        font-size: 2rem;
    }

    .mobile-menu-toggle {
        display: inline-flex;
        flex-shrink: 0;
    }

    .mobile-sidebar-close {
        border: 0;
        background: transparent;
        color: #eef3fa;
        width: 38px;
        height: 38px;
        border-radius: 10px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        position: sticky;
        top: 0.5rem;
        margin-inline-start: auto;
        margin-inline-end: 0.6rem;
        z-index: 2;
    }

    .wizard-actions {
        justify-content: stretch;
    }

    .wizard-actions .btn {
        min-width: 0;
        flex: 1;
    }
}

@media (max-width: 640px) {
    .sidebar-nav {
        grid-template-columns: 1fr;
    }

    .portal-topbar {
        padding: 0.75rem 0.85rem;
    }

    .topbar-title {
        font-size: 1.05rem;
    }

    .surface-head,
    .surface-body {
        padding: 0.8rem;
    }

    .menu-main,
    .menu-sub-link {
        font-size: 0.98rem;
    }

    .wizard-actions {
        flex-direction: column;
    }

    .wizard-actions .btn {
        width: 100%;
    }
}

@media (max-width: 1024px) {
    .table-wrap {
        overflow: visible;
    }

    .table:not(.legacy-detail-table) thead {
        display: none;
    }

    .table:not(.legacy-detail-table) tbody {
        display: grid;
        gap: 0.7rem;
        padding: 0.5rem;
    }

    .table:not(.legacy-detail-table) tbody tr {
        display: block;
        border: 1px solid rgba(25, 44, 63, 0.14);
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.96);
        overflow: hidden;
    }

    .table:not(.legacy-detail-table) tbody td {
        display: block;
        border-bottom: 1px solid rgba(25, 44, 63, 0.08);
        padding: 0.6rem 0.72rem;
    }

    .table:not(.legacy-detail-table) tbody td:last-child {
        border-bottom: 0;
    }

    .table:not(.legacy-detail-table) tbody td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 0.28rem;
        color: var(--muted);
        font-size: 0.76rem;
        font-weight: 700;
    }

    .table:not(.legacy-detail-table) tbody td[colspan] {
        text-align: center;
        font-weight: 600;
    }

    .table:not(.legacy-detail-table) tbody td[colspan]::before {
        content: "";
        display: none;
    }

    .table:not(.legacy-detail-table) tbody td input,
    .table:not(.legacy-detail-table) tbody td select,
    .table:not(.legacy-detail-table) tbody td .btn,
    .table:not(.legacy-detail-table) tbody td form {
        width: 100%;
    }

    .table:not(.legacy-detail-table) tbody td .d-inline {
        display: block !important;
    }

    .legacy-detail-table th,
    .legacy-detail-table td {
        display: block;
        width: 100%;
    }

    .legacy-detail-table th {
        text-align: center;
        padding-bottom: 0.35rem;
    }

    .legacy-detail-table td {
        border-top: 0;
    }

    .legacy-pill {
        min-width: 0;
        width: 100%;
    }
}

@keyframes riseIn {
    from {
        transform: translateY(8px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}
