:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --sidebar: #0b1220;
    --sidebar-soft: #111b2e;
    --text: #172033;
    --muted: #718096;
    --muted-2: #9aa7b8;
    --border: #e5eaf1;
    --primary: #176b87;
    --primary-strong: #10566e;
    --primary-soft: #e8f5f8;
    --success: #15936c;
    --warning: #d28a16;
    --danger: #d64d5c;
    --shadow-sm: 0 8px 30px rgba(15, 23, 42, .06);
    --shadow-lg: 0 24px 70px rgba(15, 23, 42, .14);
    --sidebar-width: 286px;
    --topbar-height: 82px;
    --radius-sm: 12px;
    --radius-md: 18px;
    --radius-lg: 26px;
    --transition: 180ms ease;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    font-family:
        Tahoma,
        Arial,
        "Segoe UI",
        sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

button,
input {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    cursor: pointer;
}

a {
    color: inherit;
    text-decoration: none;
}

svg {
    display: block;
    width: 1.35rem;
    height: 1.35rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

[hidden] {
    display: none !important;
}

.eyebrow,
.panel-kicker {
    color: var(--primary);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .12em;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: #5b687b;
    transition:
        background var(--transition),
        color var(--transition),
        border var(--transition);
}

.icon-button:hover {
    background: var(--surface-soft);
    color: var(--text);
}

/* ========================================================
   FORM CONTROLS (login page: login.css)
======================================================== */

.field {
    margin-bottom: 1.2rem;
}

.field label {
    display: block;
    margin-bottom: .55rem;
    color: #344055;
    font-size: .86rem;
    font-weight: 700;
}

.input-shell {
    position: relative;
}

.input-shell input {
    width: 100%;
    height: 54px;
    padding: 0 3rem 0 3rem;
    border: 1px solid #dce3eb;
    border-radius: 14px;
    outline: none;
    background: white;
    color: var(--text);
    transition:
        border var(--transition),
        box-shadow var(--transition);
}

.input-shell input:focus {
    border-color: #6bb5c7;
    box-shadow: 0 0 0 4px rgba(23,107,135,.09);
}

.input-shell input::placeholder {
    color: #b0bac7;
}

.input-icon {
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-50%);
    color: #8c99aa;
    pointer-events: none;
}

.input-icon svg {
    width: 19px;
    height: 19px;
}

.input-action {
    position: absolute;
    top: 50%;
    left: .55rem;
    transform: translateY(-50%);
    width: 38px;
    height: 38px;
    border: 0;
}

.primary-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 54px;
    margin-top: .5rem;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(135deg, #176b87, #115a73);
    box-shadow: 0 12px 25px rgba(23,107,135,.2);
    color: white;
    font-weight: 800;
    transition:
        transform var(--transition),
        box-shadow var(--transition),
        opacity var(--transition);
}

.primary-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 30px rgba(23,107,135,.26);
}

.primary-button:disabled {
    cursor: wait;
    opacity: .7;
    transform: none;
}

.button-loader {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.alert {
    margin-bottom: 1.2rem;
    padding: .85rem 1rem;
    border: 1px solid #f3c6cb;
    border-radius: 12px;
    background: #fff1f2;
    color: #a83845;
    font-size: .86rem;
    line-height: 1.6;
}

.status-dot,
.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 4px rgba(21,147,108,.1);
}

/* ========================================================
   ADMIN SHELL
======================================================== */

.admin-view {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    z-index: 40;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    background:
        radial-gradient(circle at 50% 0, rgba(27,116,145,.12), transparent 26%),
        var(--sidebar);
    color: #c4cfdd;
    box-shadow: -1px 0 0 rgba(255,255,255,.03) inset;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--topbar-height);
    padding: 0 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .8rem;
}

.sidebar-logo {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(236,233,226,.14);
    border-radius: 8px;
    background: transparent;
    color: #ece9e2;
}

.sidebar-logo svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    stroke: none;
}

.sidebar-brand strong,
.sidebar-brand small {
    display: block;
}

.sidebar-brand strong {
    color: white;
    font-size: .93rem;
}

.sidebar-brand small {
    margin-top: .2rem;
    color: #718398;
    font-size: .65rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem .85rem;
    scrollbar-width: thin;
}

.nav-section-title {
    display: block;
    padding: 1.15rem .85rem .55rem;
    color: #617186;
    font-size: .66rem;
    font-weight: 800;
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 46px;
    margin: .2rem 0;
    padding: 0 .8rem;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: #93a3b6;
    text-align: right;
    gap: .75rem;
    transition:
        color var(--transition),
        background var(--transition);
}

.nav-item:hover {
    background: rgba(255,255,255,.045);
    color: #e4ebf2;
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(29,132,160,.16), rgba(29,132,160,.07));
    color: #6ed0e3;
}

.nav-item.active::after {
    content: "";
    position: absolute;
    top: 10px;
    right: -13px;
    width: 3px;
    height: 26px;
    border-radius: 10px;
    background: #55c4da;
}

.nav-icon {
    flex: 0 0 auto;
}

.nav-icon svg {
    width: 20px;
    height: 20px;
}

.nav-placeholder {
    font-size: .86rem;
}

.soon-badge {
    margin-right: auto;
    padding: .2rem .42rem;
    border-radius: 6px;
    background: rgba(255,255,255,.06);
    color: #68798e;
    font-size: .57rem;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,.06);
}

.system-state {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem;
    border-radius: 12px;
    background: rgba(255,255,255,.035);
}

.system-state-icon {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #29b98a;
    box-shadow: 0 0 12px rgba(41,185,138,.45);
}

.system-state strong,
.system-state small {
    display: block;
}

.system-state strong {
    color: #cbd6e2;
    font-size: .72rem;
}

.system-state small {
    margin-top: .15rem;
    color: #617186;
    font-size: .62rem;
}

.app-frame {
    min-height: 100vh;
    margin-right: var(--sidebar-width);
}

.topbar {
    position: sticky;
    z-index: 25;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--topbar-height);
    padding: 0 clamp(1rem, 3vw, 2.2rem);
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(14px);
}

.topbar-start,
.topbar-actions {
    display: flex;
    align-items: center;
}

.topbar-start {
    gap: .8rem;
}

.topbar-actions {
    gap: .65rem;
}

.page-title span {
    color: var(--muted);
    font-size: .67rem;
}

.page-title h1 {
    margin: .15rem 0 0;
    font-size: 1.05rem;
}

.mobile-menu-button {
    display: none;
}

.live-status {
    display: flex;
    align-items: center;
    gap: .55rem;
    height: 38px;
    padding: 0 .8rem;
    border: 1px solid #dcefe8;
    border-radius: 10px;
    background: #f5fcf9;
    color: #34755f;
    font-size: .72rem;
    font-weight: 700;
}

.notification-button {
    position: relative;
}

.notification-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 6px;
    height: 6px;
    border: 2px solid white;
    border-radius: 50%;
    background: var(--danger);
}

.user-menu-wrap {
    position: relative;
}

.user-button {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: .25rem .45rem .25rem .75rem;
    border: 0;
    border-radius: 13px;
    background: transparent;
    color: var(--text);
    gap: .7rem;
}

.user-button:hover {
    background: var(--surface-soft);
}

.avatar {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(135deg, #163b4a, #176b87);
    color: white;
    font-size: .72rem;
    font-weight: 800;
}

.user-button-copy {
    text-align: right;
}

.user-button-copy strong,
.user-button-copy small {
    display: block;
}

.user-button-copy strong {
    max-width: 150px;
    overflow: hidden;
    font-size: .75rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-button-copy small {
    margin-top: .15rem;
    color: var(--muted);
    font-size: .62rem;
}

.chevron {
    width: 15px;
    height: 15px;
    color: var(--muted);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + .55rem);
    left: 0;
    width: 245px;
    padding: .5rem;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: white;
    box-shadow: var(--shadow-lg);
}

.dropdown-user {
    padding: .75rem;
    border-bottom: 1px solid var(--border);
}

.dropdown-user strong,
.dropdown-user small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-user strong {
    font-size: .8rem;
}

.dropdown-user small {
    margin-top: .3rem;
    color: var(--muted);
    font-size: .68rem;
    white-space: nowrap;
}

.logout-button {
    display: flex;
    align-items: center;
    width: 100%;
    margin-top: .35rem;
    padding: .7rem .75rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--danger);
    gap: .65rem;
    text-align: right;
}

.logout-button:hover {
    background: #fff3f4;
}

.logout-button svg {
    width: 18px;
    height: 18px;
}

/* ========================================================
   DASHBOARD
======================================================== */

.dashboard-content {
    width: min(100%, 1600px);
    margin: auto;
    padding: clamp(1.2rem, 3vw, 2.2rem);
}

.welcome-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 1.6rem;
    gap: 1rem;
}

.welcome-row h2 {
    margin: .4rem 0 .35rem;
    font-size: clamp(1.5rem, 3vw, 2rem);
    letter-spacing: -.03em;
}

.welcome-row p {
    margin: 0;
    color: var(--muted);
    font-size: .85rem;
}

.date-chip {
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: 0 .85rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: white;
    color: #5e6c7e;
    box-shadow: var(--shadow-sm);
    font-size: .73rem;
    gap: .55rem;
}

.date-chip svg {
    width: 17px;
    height: 17px;
}

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

.metric-card,
.panel {
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.metric-card {
    min-height: 190px;
    padding: 1.15rem;
    border-radius: var(--radius-md);
}

.metric-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.metric-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--primary-soft);
    color: var(--primary);
}

.metric-icon svg {
    width: 20px;
    height: 20px;
}

.warning-icon {
    background: #fff6e7;
    color: var(--warning);
}

.metric-state {
    padding: .3rem .5rem;
    border-radius: 7px;
    font-size: .59rem;
    font-weight: 800;
}

.metric-state.neutral {
    background: #f2f5f8;
    color: #8592a2;
}

.metric-label {
    display: block;
    color: #5e6b7b;
    font-size: .75rem;
    font-weight: 700;
}

.metric-value {
    display: block;
    margin: .35rem 0 .35rem;
    font-size: 1.8rem;
}

.metric-card small {
    color: var(--muted-2);
    font-size: .67rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(300px, .75fr);
    margin-top: 1rem;
    gap: 1rem;
}

.panel {
    overflow: hidden;
    border-radius: var(--radius-md);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 78px;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.panel-header h3 {
    margin: .25rem 0 0;
    font-size: .95rem;
}

.panel-status {
    display: flex;
    align-items: center;
    padding: .35rem .55rem;
    border-radius: 8px;
    background: #f4faf8;
    color: #51816f;
    font-size: .62rem;
    gap: .4rem;
}

.panel-status span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}

.map-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 380px;
    padding: 2rem;
    background:
        linear-gradient(rgba(23,107,135,.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(23,107,135,.025) 1px, transparent 1px),
        #fbfdfe;
    background-size: 28px 28px;
    text-align: center;
}

.map-radar {
    position: relative;
    width: 140px;
    height: 140px;
    margin-bottom: 1rem;
}

.map-radar > span {
    position: absolute;
    border: 1px solid rgba(23,107,135,.12);
    border-radius: 50%;
}

.map-radar > span:nth-child(1) {
    inset: 0;
}

.map-radar > span:nth-child(2) {
    inset: 22px;
}

.map-radar > span:nth-child(3) {
    inset: 44px;
}

.map-pin {
    position: absolute;
    inset: 48px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: white;
    box-shadow: 0 8px 30px rgba(23,107,135,.16);
    color: var(--primary);
}

.map-pin svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    stroke: none;
}

.map-placeholder h4 {
    margin: .4rem 0;
    font-size: .9rem;
}

.map-placeholder p {
    max-width: 380px;
    margin: 0;
    color: var(--muted);
    font-size: .72rem;
    line-height: 1.8;
}

.system-list {
    padding: .55rem 1rem 1rem;
}

.system-list-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    min-height: 68px;
    border-bottom: 1px solid #eef1f5;
    gap: .7rem;
}

.system-list-item:last-child {
    border-bottom: 0;
}

.health-icon {
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

.health-icon.healthy {
    background: var(--success);
    box-shadow: 0 0 0 4px rgba(21,147,108,.09);
}

.health-icon.pending {
    background: #c7ced8;
}

.system-list-item strong,
.system-list-item small {
    display: block;
}

.system-list-item strong {
    font-size: .74rem;
}

.system-list-item small {
    margin-top: .2rem;
    color: var(--muted);
    font-size: .62rem;
}

.health-label {
    color: var(--success);
    font-size: .61rem;
    font-weight: 800;
}

.pending-text {
    color: #9ba6b4;
}

/* ========================================================
   OVERLAYS / TOASTS
======================================================== */

.sidebar-backdrop {
    display: none;
}

.toast-container {
    position: fixed;
    z-index: 100;
    left: 1.2rem;
    bottom: 1.2rem;
    display: grid;
    width: min(360px, calc(100vw - 2.4rem));
    gap: .65rem;
}

.toast {
    padding: .9rem 1rem;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: white;
    box-shadow: var(--shadow-lg);
    font-size: .78rem;
    animation: toastIn .2s ease;
}

.toast.success {
    border-right: 4px solid var(--success);
}

.toast.error {
    border-right: 4px solid var(--danger);
}

/* ========================================================
   RESPONSIVE
======================================================== */

.mobile-only {
    display: none;
}

@media (max-width: 1180px) {
    .metrics-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(105%);
        transition: transform 220ms ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        z-index: 35;
        inset: 0;
        display: block;
        visibility: hidden;
        background: rgba(4,10,18,.48);
        opacity: 0;
        transition:
            opacity 220ms ease,
            visibility 220ms ease;
    }

    .sidebar-backdrop.visible {
        visibility: visible;
        opacity: 1;
    }

    .app-frame {
        margin-right: 0;
    }

    .mobile-menu-button,
    .mobile-only {
        display: inline-flex;
    }
}

@media (max-width: 640px) {
    .topbar {
        min-height: 70px;
        padding: 0 .8rem;
    }

    .page-title span {
        display: none;
    }

    .page-title h1 {
        font-size: .92rem;
    }

    .desktop-only {
        display: none !important;
    }

    .dashboard-content {
        padding: 1rem;
    }

    .welcome-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .date-chip {
        width: 100%;
        justify-content: center;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .metric-card {
        min-height: 165px;
    }

    .map-placeholder {
        min-height: 300px;
    }

    .user-button {
        padding: .2rem;
    }

    .user-dropdown {
        left: -.2rem;
        width: min(245px, calc(100vw - 2rem));
    }
}

/* ========================================================
   ANIMATIONS
======================================================== */

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* ========================================================
   USERS & PERMISSIONS
======================================================== */

.users-content {
    width: min(100%, 1600px);
    margin: auto;
    padding: clamp(1.2rem, 3vw, 2.2rem);
}

.users-hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 1.4rem;
    gap: 1rem;
}

.users-hero h2 {
    margin: .4rem 0 .35rem;
    font-size: clamp(1.55rem, 3vw, 2.15rem);
    letter-spacing: -.035em;
}

.users-hero p {
    max-width: 680px;
    margin: 0;
    color: var(--muted);
    font-size: .84rem;
    line-height: 1.8;
}

.users-primary-action,
.users-secondary-action,
.table-action,
.users-pagination button,
.users-icon-action {
    font: inherit;
}

.users-primary-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 1rem;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, #176b87, #10566e);
    box-shadow: 0 10px 24px rgba(23,107,135,.16);
    color: white;
    font-size: .76rem;
    font-weight: 800;
    gap: .55rem;
}

.users-primary-action svg {
    width: 18px;
    height: 18px;
}

.users-primary-action:disabled {
    cursor: wait;
    opacity: .65;
}

.users-secondary-action {
    min-height: 44px;
    padding: 0 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: white;
    color: #556274;
    font-size: .76rem;
    font-weight: 700;
}

.users-kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 1rem;
    gap: 1rem;
}

.users-kpi-card {
    min-height: 125px;
    padding: 1rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: white;
    box-shadow: var(--shadow-sm);
}

.users-kpi-card > span {
    display: block;
    color: #667487;
    font-size: .72rem;
    font-weight: 700;
}

.users-kpi-card strong {
    display: block;
    margin: .55rem 0 .25rem;
    font-size: 1.65rem;
}

.users-kpi-card small {
    color: var(--muted-2);
    font-size: .64rem;
}

.users-panel {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: white;
    box-shadow: var(--shadow-sm);
}

.users-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 76px;
    padding: .9rem 1rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}

.users-search {
    position: relative;
    flex: 1;
    max-width: 520px;
}

.users-search svg {
    position: absolute;
    top: 50%;
    right: .9rem;
    width: 18px;
    height: 18px;
    transform: translateY(-50%);
    color: #8d99a9;
}

.users-search input,
.users-filters select,
.drawer-field input,
.drawer-field select {
    outline: none;
    border: 1px solid #dce3eb;
    background: white;
    color: var(--text);
    transition:
        border var(--transition),
        box-shadow var(--transition);
}

.users-search input:focus,
.users-filters select:focus,
.drawer-field input:focus,
.drawer-field select:focus {
    border-color: #6bb5c7;
    box-shadow: 0 0 0 4px rgba(23,107,135,.08);
}

.users-search input {
    width: 100%;
    height: 44px;
    padding: 0 2.7rem 0 .9rem;
    border-radius: 11px;
}

.users-filters {
    display: flex;
    align-items: center;
    gap: .55rem;
}

.users-filters select {
    height: 44px;
    padding: 0 .8rem;
    border-radius: 11px;
    font-size: .72rem;
}

.users-icon-action {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: #f9fbfc;
    color: #607084;
}

.users-icon-action svg {
    width: 18px;
    height: 18px;
}

.users-table-wrap {
    overflow-x: auto;
    transition: opacity var(--transition);
}

.users-table-wrap.is-loading {
    opacity: .45;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .72rem;
}

.users-table th {
    height: 48px;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border);
    background: #fafbfd;
    color: #7b8797;
    text-align: right;
    white-space: nowrap;
}

.users-table td {
    min-height: 68px;
    padding: .8rem 1rem;
    border-bottom: 1px solid #eef1f5;
    vertical-align: middle;
}

.users-table tbody tr {
    transition: background var(--transition);
}

.users-table tbody tr:hover {
    background: #fbfdfe;
}

.user-identity-cell {
    display: flex;
    align-items: center;
    min-width: 210px;
    gap: .7rem;
}

.table-avatar {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: #e8f5f8;
    color: var(--primary);
    font-size: .68rem;
    font-weight: 900;
}

.user-identity-cell strong,
.user-identity-cell small {
    display: block;
}

.user-identity-cell strong {
    color: #263247;
    font-size: .75rem;
}

.user-identity-cell small {
    max-width: 220px;
    overflow: hidden;
    margin-top: .2rem;
    color: var(--muted);
    font-size: .63rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.role-chips {
    display: flex;
    flex-wrap: wrap;
    max-width: 260px;
    gap: .3rem;
}

.role-chip,
.type-chip {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 .5rem;
    border-radius: 7px;
    background: #f1f5f8;
    color: #586779;
    font-size: .6rem;
    font-weight: 700;
}

.type-chip {
    background: #edf7f9;
    color: #276f83;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    min-height: 27px;
    padding: 0 .55rem;
    border-radius: 8px;
    font-size: .61rem;
    font-weight: 800;
    gap: .4rem;
}

.status-chip span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-chip.active {
    background: #eefaf5;
    color: #278063;
}

.status-chip.active span {
    background: var(--success);
}

.status-chip.inactive {
    background: #fff2f3;
    color: #a94a55;
}

.status-chip.inactive span {
    background: var(--danger);
}

.last-login {
    color: #697789;
    white-space: nowrap;
}

.table-action {
    min-height: 34px;
    padding: 0 .7rem;
    border: 1px solid #dce5eb;
    border-radius: 9px;
    background: white;
    color: var(--primary);
    font-size: .65rem;
    font-weight: 800;
}

.table-action:hover {
    border-color: #b8d8e0;
    background: var(--primary-soft);
}

.users-loading,
.users-empty {
    padding: 3.5rem 1rem;
    text-align: center;
}

.users-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: .76rem;
    gap: .7rem;
}

.users-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid #dce5eb;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.users-empty-icon {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    margin: 0 auto .8rem;
    border-radius: 16px;
    background: #f0f6f8;
    color: var(--primary);
}

.users-empty strong,
.users-empty span {
    display: block;
}

.users-empty strong {
    margin-bottom: .35rem;
    font-size: .85rem;
}

.users-empty span {
    color: var(--muted);
    font-size: .7rem;
}

.users-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    padding: .7rem 1rem;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: .68rem;
}

.users-pagination > div {
    display: flex;
    align-items: center;
    gap: .45rem;
}

.users-pagination button {
    min-height: 34px;
    padding: 0 .7rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: white;
    color: #566477;
    font-size: .66rem;
    font-weight: 700;
}

.users-pagination button:disabled {
    cursor: not-allowed;
    opacity: .45;
}

#usersPageNumber {
    display: grid;
    place-items: center;
    min-width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--sidebar);
    color: white;
    font-weight: 800;
}

.muted-cell {
    color: var(--muted-2);
    font-size: .65rem;
}

/* Drawer */

body.drawer-open {
    overflow: hidden;
}

.user-drawer-backdrop {
    position: fixed;
    z-index: 70;
    inset: 0;
    background: rgba(4,10,18,.5);
    backdrop-filter: blur(2px);
}

.user-drawer {
    position: fixed;
    z-index: 75;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    width: min(720px, 94vw);
    background: #f7f9fc;
    box-shadow: 20px 0 70px rgba(8,15,25,.18);
    transform: translateX(-105%);
    transition: transform 240ms ease;
}

/*
 * Shared drawer visibility contract.
 *
 * Legacy Users module uses: .open
 * Outlets module uses:      .is-open
 *
 * Both states intentionally resolve to the same
 * base drawer presentation.
 */
.user-drawer.open,
.user-drawer.is-open {
    transform: translateX(0);
}

.user-drawer-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    min-height: 84px;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: white;
}

.user-drawer-header > div > span {
    color: var(--primary);
    font-size: .62rem;
    font-weight: 900;
    letter-spacing: .1em;
}

.user-drawer-header h2 {
    margin: .25rem 0 0;
    font-size: 1.15rem;
}

.user-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.drawer-alert {
    margin-bottom: 1rem;
    padding: .85rem 1rem;
    border: 1px solid #f0c4ca;
    border-radius: 12px;
    background: #fff1f2;
    color: #a43c49;
    font-size: .72rem;
    line-height: 1.7;
}

.drawer-section {
    margin-bottom: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: white;
    box-shadow: 0 5px 20px rgba(15,23,42,.035);
}

.drawer-section > header {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    gap: .7rem;
}

.drawer-section > header > span {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: .62rem;
    font-weight: 900;
}

.drawer-section header strong,
.drawer-section header small {
    display: block;
}

.drawer-section header strong {
    font-size: .78rem;
}

.drawer-section header small {
    margin-top: .15rem;
    color: var(--muted);
    font-size: .62rem;
}

.drawer-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .8rem;
}

.drawer-field {
    display: block;
}

.drawer-field-wide {
    grid-column: 1 / -1;
}

.drawer-field > span {
    display: block;
    margin-bottom: .4rem;
    color: #4f5d70;
    font-size: .67rem;
    font-weight: 800;
}

.drawer-field input,
.drawer-field select {
    width: 100%;
    height: 44px;
    padding: 0 .75rem;
    border-radius: 10px;
}

.drawer-field > small {
    display: block;
    margin-top: .35rem;
    color: var(--muted);
    font-size: .6rem;
}

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

.role-option {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 62px;
    padding: .65rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    gap: .65rem;
}

.role-option:hover {
    border-color: #b8d7df;
    background: #fbfdfe;
}

.role-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.role-option-check {
    position: relative;
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: 20px;
    height: 20px;
    border: 1px solid #cdd7e1;
    border-radius: 6px;
}

.role-option input:checked + .role-option-check {
    border-color: var(--primary);
    background: var(--primary);
}

.role-option input:checked + .role-option-check::after {
    content: "";
    width: 8px;
    height: 4px;
    margin-top: -2px;
    border-right: 2px solid white;
    border-bottom: 2px solid white;
    transform: rotate(45deg);
}

.role-option strong,
.role-option small {
    display: block;
}

.role-option strong {
    font-size: .7rem;
}

.role-option small {
    margin-top: .15rem;
    color: var(--muted);
    font-size: .56rem;
}

.permission-legend {
    display: flex;
    margin-bottom: .7rem;
    gap: .4rem;
}

.permission-legend span,
.permission-choice span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 26px;
    padding: 0 .5rem;
    border-radius: 7px;
    font-size: .58rem;
    font-weight: 800;
}

.permission-legend .inherit,
.permission-choice .inherit {
    background: #f1f4f7;
    color: #6d7988;
}

.permission-legend .allow,
.permission-choice .allow {
    background: #eaf8f2;
    color: #28795f;
}

.permission-legend .deny,
.permission-choice .deny {
    background: #fff0f1;
    color: #a84551;
}

.permissions-grid {
    display: grid;
    gap: .45rem;
}

.permission-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 58px;
    padding: .55rem .65rem;
    border: 1px solid #edf0f4;
    border-radius: 11px;
    gap: 1rem;
}

.permission-copy strong,
.permission-copy small {
    display: block;
}

.permission-copy strong {
    font-size: .68rem;
}

.permission-copy small {
    margin-top: .18rem;
    color: var(--muted);
    font-size: .56rem;
}

.permission-choice {
    display: flex;
    flex: 0 0 auto;
    gap: .3rem;
}

.permission-choice label {
    cursor: pointer;
}

.permission-choice input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.permission-choice input:not(:checked) + span {
    opacity: .35;
    filter: grayscale(.7);
}

.permission-choice input:checked + span {
    box-shadow: inset 0 0 0 1px currentColor;
}

.effective-permissions {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.effective-permissions > span {
    padding: .35rem .55rem;
    border-radius: 7px;
    background: #edf7f9;
    color: #286f83;
    font-size: .58rem;
    font-weight: 800;
}

.user-form-footer {
    position: sticky;
    bottom: -1rem;
    display: flex;
    justify-content: flex-end;
    margin: 1rem -1rem -1rem;
    padding: .9rem 1rem;
    border-top: 1px solid var(--border);
    background: rgba(247,249,252,.95);
    backdrop-filter: blur(12px);
    gap: .6rem;
}

@media (max-width: 1180px) {
    .users-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .users-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .users-search {
        max-width: none;
    }
}

@media (max-width: 760px) {
    .users-content {
        padding: 1rem;
    }

    .users-hero {
        align-items: stretch;
        flex-direction: column;
    }

    .users-primary-action {
        width: 100%;
    }

    .users-filters {
        display: grid;
        grid-template-columns: 1fr 1fr auto;
    }

    .users-filters select {
        width: 100%;
    }

    .users-table {
        display: block;
    }

    .users-table thead {
        display: none;
    }

    .users-table tbody,
    .users-table tr,
    .users-table td {
        display: block;
        width: 100%;
    }

    .users-table tbody {
        padding: .7rem;
    }

    .users-table tr {
        overflow: hidden;
        margin-bottom: .7rem;
        border: 1px solid var(--border);
        border-radius: 14px;
        background: white;
    }

    .users-table td {
        display: grid;
        grid-template-columns: 105px minmax(0, 1fr);
        align-items: center;
        min-height: 48px;
        padding: .65rem .8rem;
        border-bottom: 1px solid #eef1f5;
        gap: .7rem;
    }

    .users-table td::before {
        content: attr(data-label);
        color: #8a96a5;
        font-size: .6rem;
        font-weight: 800;
    }

    .users-table td:first-child {
        display: block;
    }

    .users-table td:first-child::before {
        display: none;
    }

    .users-table td:last-child {
        border-bottom: 0;
    }

    .users-actions-cell .table-action {
        width: 100%;
    }

    .users-pagination {
        align-items: stretch;
        flex-direction: column;
        gap: .7rem;
    }

    .users-pagination > div {
        justify-content: space-between;
    }

    .user-drawer {
        width: 100%;
    }

    .drawer-form-grid,
    .roles-grid {
        grid-template-columns: 1fr;
    }

    .permission-row {
        align-items: stretch;
        flex-direction: column;
    }

    .permission-choice {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .permission-choice span {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .users-kpis {
        grid-template-columns: 1fr 1fr;
        gap: .7rem;
    }

    .users-kpi-card {
        min-height: 110px;
    }

    .users-filters {
        grid-template-columns: 1fr;
    }

    .users-icon-action {
        width: 100%;
    }
}
/* ========================================================
   Dashboard production D3.5
   ======================================================== */

#dashboardPage {
    min-width: 0;
}

.dashboard-heading-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.dashboard-refresh-button {
    min-height: 42px;
    padding: 0 15px;
    border: 1px solid rgba(148, 163, 184, .20);
    border-radius: 12px;
    background: rgba(255, 255, 255, .055);
    color: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition:
        transform .18s ease,
        background .18s ease,
        border-color .18s ease,
        opacity .18s ease;
}

.dashboard-refresh-button:hover:not(:disabled) {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, .09);
    border-color: rgba(148, 163, 184, .32);
}

.dashboard-refresh-button:focus-visible {
    outline: 3px solid rgba(59, 130, 246, .22);
    outline-offset: 2px;
}

.dashboard-refresh-button:disabled {
    opacity: .62;
    cursor: wait;
}

.dashboard-refresh-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.dashboard-refresh-button.is-loading svg {
    animation: dashboard-refresh-spin .85s linear infinite;
}

@keyframes dashboard-refresh-spin {
    to {
        transform: rotate(360deg);
    }
}

.dashboard-error {
    margin: 0 0 18px;
    padding: 13px 16px;
    border: 1px solid rgba(239, 68, 68, .24);
    border-radius: 14px;
    background: rgba(239, 68, 68, .08);
    color: #dc2626;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.7;
}

.dashboard-error[hidden] {
    display: none;
}

#dashboardMetrics[aria-busy="true"] .metric-card {
    opacity: .72;
}

#dashboardMetrics .metric-card {
    transition:
        opacity .18s ease,
        transform .18s ease,
        border-color .18s ease;
}

#dashboardMetrics .metric-card:hover {
    transform: translateY(-2px);
}

.dashboard-state-live {
    border-color: rgba(34, 197, 94, .22) !important;
    background: rgba(34, 197, 94, .08) !important;
    color: #16a34a !important;
}

.dashboard-state-unavailable {
    opacity: .76;
}

.dashboard-map-shell {
    position: relative;
    overflow: hidden;
    min-width: 0;
    min-height: 430px;
    border: 1px solid rgba(148, 163, 184, .12);
    border-radius: 18px;
    background: rgba(15, 23, 42, .035);
}

.dashboard-live-map {
    width: 100%;
    height: 430px;
    min-height: 430px;
    z-index: 1;
    background: rgba(148, 163, 184, .08);
}

.dashboard-map-empty {
    position: absolute;
    z-index: 500;
    inset: 0 0 55px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 7px;
    padding: 30px;
    text-align: center;
    background: rgba(255, 255, 255, .86);
    backdrop-filter: blur(6px);
}

.dashboard-map-empty[hidden] {
    display: none;
}

.dashboard-map-empty strong {
    font-size: 16px;
}

.dashboard-map-empty span {
    max-width: 380px;
    font-size: 13px;
    line-height: 1.7;
    opacity: .68;
}

.dashboard-map-footer {
    min-height: 55px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-top: 1px solid rgba(148, 163, 184, .14);
}

.dashboard-map-footer > div {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dashboard-map-footer strong {
    font-size: 17px;
    line-height: 1;
}

.dashboard-map-footer span {
    font-size: 12px;
    opacity: .68;
}

.dashboard-generated-at {
    direction: rtl;
    text-align: end;
}

.dashboard-map-popup {
    min-width: 175px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    direction: rtl;
    text-align: right;
    line-height: 1.45;
}

.dashboard-map-popup strong {
    margin-bottom: 3px;
    font-size: 14px;
}

.dashboard-map-popup span {
    font-size: 12px;
}

#dashboardPage .leaflet-container {
    font-family: inherit;
}

#dashboardPage .leaflet-popup-content-wrapper {
    border-radius: 13px;
}

#dashboardPage .leaflet-popup-content {
    margin: 13px 15px;
}

#dashboardPage .leaflet-control-zoom a {
    text-decoration: none;
}

.health-icon.offline {
    background: #ef4444;
    box-shadow: 0 0 0 5px rgba(239, 68, 68, .10);
}

.health-label.offline-text {
    color: #dc2626;
}

#dashboardPage .system-list-item {
    min-width: 0;
}

#dashboardPage .system-list-item > div {
    min-width: 0;
}

#dashboardPage .system-list-item small {
    overflow-wrap: anywhere;
}

/* Tablet */

@media (max-width: 1000px) {
    .dashboard-heading-actions {
        width: 100%;
        justify-content: space-between;
    }

    .dashboard-map-shell,
    .dashboard-live-map {
        min-height: 370px;
        height: 370px;
    }
}

/* Mobile */

@media (max-width: 640px) {
    .dashboard-heading-actions {
        align-items: stretch;
        gap: 8px;
    }

    .dashboard-refresh-button,
    .dashboard-heading-actions .date-chip {
        flex: 1 1 auto;
    }

    .dashboard-refresh-button {
        min-height: 44px;
    }

    .dashboard-map-shell,
    .dashboard-live-map {
        min-height: 320px;
        height: 320px;
    }

    .dashboard-map-footer {
        align-items: flex-start;
        flex-direction: column;
        gap: 7px;
    }

    .dashboard-map-empty {
        inset-bottom: 75px;
    }
}

/* PHASE 7.5V - SPA PAGE VISIBILITY CONTRACT */

/*
 * Hidden SPA pages must not participate in document layout.
 * This rule deliberately uses !important because individual
 * page modules may declare display:grid/flex after the
 * browser's native [hidden] rule.
 */
.app-page[hidden] {
    display: none !important;
}

/*
 * Defensive contract for all application main pages.
 */
main.app-page[hidden] {
    display: none !important;
}

/* END PHASE 7.5V */
