:root {
    --fm-bg: #ffffff;
    --fm-surface: #ffffff;
    --fm-text: #111827;
    --fm-muted: #9ca3af;
    --fm-muted-2: #6b7280;
    --fm-line: #f3f4f6;
    --fm-blue: #3b82f6;
    --fm-red: #f87171;
    --fm-orange: #fb923c;
    --fm-cyan: #22d3ee;
    --fm-green: #34d399;
    --fm-slate: #64748b;
    --fm-purple: #8b5cf6;
    --fm-radius: 20px;
    --fm-shadow: 0 1px 1px rgba(15, 23, 42, 0.03), 0 10px 28px rgba(15, 23, 42, 0.05);
    --fm-shadow-hover: 0 2px 4px rgba(15, 23, 42, 0.04), 0 16px 36px rgba(15, 23, 42, 0.08);
    --fm-sidebar: 240px;
}

* {
    box-sizing: border-box;
}

html,
body.fm-body {
    background: var(--fm-bg);
    color: var(--fm-text);
    font-family: Inter, "Segoe UI", system-ui, sans-serif;
    min-height: 100%;
}

body.fm-body {
    margin: 0;
}

.fm-shell {
    display: flex;
    min-height: 100vh;
    background: #ffffff;
}

.fm-sidebar {
    width: var(--fm-sidebar);
    background: var(--fm-surface);
    flex-shrink: 0;
    padding: 1.35rem 1rem 1.5rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}

.fm-logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.15rem 0.6rem 1.35rem;
    color: var(--fm-text);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.35rem;
    letter-spacing: -0.03em;
}

.fm-logo:hover {
    color: var(--fm-text);
}

.fm-logo-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #111827;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.fm-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.fm-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.62rem 0.8rem;
    border-radius: 10px;
    color: #4b5563;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}

.fm-nav-item i {
    font-size: 1.05rem;
    width: 1.25rem;
    text-align: center;
    color: #6b7280;
}

.fm-nav-item:hover {
    background: #f9fafb;
    color: var(--fm-text);
}

.fm-nav-item.is-active {
    background: #f3f4f6;
    color: var(--fm-text);
}

.fm-nav-item.is-active i {
    color: var(--fm-text);
}

.fm-nav-plus {
    margin-left: auto;
    font-size: 1.1rem;
    color: #d1d5db;
    line-height: 1;
}

.fm-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.fm-topbar {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    gap: 1rem;
}

.fm-icon-btn {
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    border-radius: 10px;
    color: #6b7280;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
}

.fm-icon-btn:hover {
    background: #e5e7eb;
    color: var(--fm-text);
}

.fm-topbar-right {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.fm-month {
    border: 0;
    background: var(--fm-surface);
    border-radius: 10px;
    padding: 0.45rem 0.85rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: #374151;
    box-shadow: var(--fm-shadow);
    cursor: default;
}

.fm-user {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    background: transparent;
    border: 0;
    padding: 0.15rem 0.15rem 0.15rem 0.25rem;
    text-decoration: none;
    color: inherit;
}

.fm-user-copy {
    text-align: left;
}

.fm-user-name {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--fm-text);
    line-height: 1.2;
}

.fm-user-role {
    display: block;
    font-size: 0.75rem;
    color: var(--fm-muted);
}

.fm-user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    background: #dbeafe;
    color: #1d4ed8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
}

.fm-page {
    padding: 0 1.75rem 2rem;
}

.fm-kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.fm-kpi {
    --kpi-accent: #3b82f6;
    position: relative;
    isolation: isolate;
    overflow: hidden;
    background: #ffffff;
    border-radius: var(--fm-radius);
    box-shadow: var(--fm-shadow);
    padding: 1.3rem 1.35rem 1.2rem;
    cursor: pointer;
    border: 1px solid color-mix(in srgb, var(--kpi-accent) 12%, #e8eaef);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.fm-kpi::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.fm-kpi::after {
    content: "";
    position: absolute;
    width: 140px;
    height: 140px;
    right: -42px;
    top: -56px;
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--kpi-accent) 18%, transparent), transparent 68%);
    pointer-events: none;
    z-index: 0;
}

.fm-kpi > * {
    position: relative;
    z-index: 1;
}

.fm-kpi:hover {
    transform: translateY(-3px);
    box-shadow: var(--fm-shadow-hover);
    border-color: color-mix(in srgb, var(--kpi-accent) 28%, #e8eaef);
}

.fm-kpi.is-active {
    border-color: color-mix(in srgb, var(--kpi-accent) 42%, #ffffff);
    box-shadow:
        0 1px 1px rgba(15, 23, 42, 0.03),
        0 12px 32px color-mix(in srgb, var(--kpi-accent) 16%, transparent),
        inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

.fm-kpi-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.05rem;
}

.fm-kpi-icon {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--kpi-accent);
    background: color-mix(in srgb, var(--kpi-accent) 14%, #ffffff);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.8),
        0 6px 14px color-mix(in srgb, var(--kpi-accent) 16%, transparent);
    font-size: 1.2rem;
}

.fm-spark {
    width: 96px;
    height: 36px;
    overflow: visible;
    color: var(--kpi-accent);
}

.fm-spark-area {
    fill: var(--kpi-accent);
    opacity: 0.16;
}

.fm-spark-line {
    fill: none;
    stroke: var(--kpi-accent);
    stroke-width: 2.25;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 2px 3px color-mix(in srgb, var(--kpi-accent) 35%, transparent));
}

.fm-kpi-label {
    font-size: 0.78rem;
    color: var(--fm-muted-2);
    font-weight: 500;
    letter-spacing: 0.01em;
    margin-bottom: 0.35rem;
}

.fm-kpi-value {
    font-size: 1.9rem;
    font-weight: 700;
    letter-spacing: -0.045em;
    color: var(--fm-text);
    line-height: 1.05;
    font-variant-numeric: tabular-nums;
}

.fm-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.fm-chart-hint {
    margin: 0.35rem 0 0;
    font-size: 0.72rem;
    color: var(--fm-muted);
}

#facilityVersionChart,
#facilityIntegrationChart {
    cursor: pointer;
}

.fm-split {
    display: grid;
    grid-template-columns: 1.55fr 0.9fr;
    gap: 1.25rem;
}

.fm-card {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.98), #ffffff);
    border-radius: var(--fm-radius);
    box-shadow: var(--fm-shadow);
    border: 1px solid rgba(226, 232, 240, 0.9);
    overflow: hidden;
}

.fm-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.2rem 1.4rem 0.45rem;
}

.fm-card-title {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 0;
    color: var(--fm-text);
}

.fm-card-body {
    padding: 0.85rem 1.4rem 1.35rem;
}

.fm-chart-wrap {
    height: 250px;
    position: relative;
}

.fm-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    align-items: end;
    padding: 0.45rem 1.4rem 1rem;
}

.fm-field {
    min-width: 8.5rem;
    flex: 1 1 8.5rem;
}

.fm-field.grow {
    flex: 2 1 14rem;
}

.fm-field label {
    display: block;
    font-size: 0.72rem;
    color: var(--fm-muted);
    margin-bottom: 0.2rem;
    font-weight: 500;
}

.fm-field .form-control,
.fm-field .form-select,
.fm-search {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    font-size: 0.8125rem;
    min-height: 36px;
    box-shadow: none;
}

.fm-field .form-control:focus,
.fm-field .form-select:focus,
.fm-search:focus {
    background: #fff;
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.fm-btn {
    border: 0;
    border-radius: 10px;
    padding: 0.42rem 0.9rem;
    font-size: 0.8rem;
    font-weight: 500;
    min-height: 36px;
}

.fm-btn-primary {
    background: var(--fm-blue);
    color: #fff;
}

.fm-btn-primary:hover {
    background: #2563eb;
    color: #fff;
}

.fm-btn-ghost {
    background: #ffffff;
    color: #4b5563;
    border: 1px solid #e5e7eb;
}

.fm-btn-ghost:hover {
    background: #e5e7eb;
    color: var(--fm-text);
}

.fm-page .card {
    background: #ffffff;
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: var(--fm-radius);
    box-shadow: var(--fm-shadow);
}

.fm-page .card-header {
    background: transparent;
    border-bottom: 0;
    font-weight: 600;
    padding: 1.05rem 1.25rem 0.35rem;
}

.fm-page .card-body {
    padding: 0.75rem 1.25rem 1.2rem;
}

.fm-table {
    width: 100%;
    margin: 0;
    font-size: 0.8125rem;
    --bs-table-bg: transparent;
    --bs-table-striped-bg: transparent;
    --bs-table-hover-bg: #f9fafb;
}

.fm-table-scroll {
    max-height: 380px;
    overflow: auto;
}

.fm-table thead th {
    color: #9ca3af;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: none;
    letter-spacing: 0;
    border-bottom: 1px solid #f3f4f6;
    background: #fff;
    padding: 0.7rem 1rem;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.fm-table tbody td {
    border-bottom: 1px solid #f9fafb;
    padding: 0.8rem 1rem;
    color: #374151;
    vertical-align: middle;
    background: transparent;
}

.fm-table tbody tr:last-child td {
    border-bottom: 0;
}

.fm-table.table-striped > tbody > tr:nth-of-type(odd) > td {
    background: transparent;
}

.fm-table tbody tr:hover td {
    background: #f9fafb;
}

.fm-person {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
}

.fm-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}

.fm-person-name {
    display: block;
    font-weight: 600;
    color: var(--fm-text);
    text-decoration: none;
    line-height: 1.25;
}

.fm-person-name:hover {
    color: var(--fm-blue);
}

.fm-person-meta {
    font-size: 0.72rem;
    color: var(--fm-muted);
}

.fm-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    font-weight: 500;
    color: #6b7280;
}

.fm-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d5db;
    display: inline-block;
}

.fm-status-ok {
    color: #059669;
}

.fm-status-ok .fm-dot {
    background: #34d399;
}

.fm-status-off .fm-dot {
    background: #f87171;
}

.fm-status-warn {
    color: #d97706;
}

.fm-status-warn .fm-dot {
    background: #fbbf24;
}

.fm-actions {
    display: flex;
    gap: 0.15rem;
}

.fm-action {
    width: 30px;
    height: 30px;
    border: 0;
    background: transparent;
    color: #9ca3af;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.fm-action:hover {
    background: #f3f4f6;
    color: var(--fm-blue);
}

.fm-status-list {
    list-style: none;
    margin: 0;
    padding: 0.25rem 0.4rem 0.6rem;
    max-height: 380px;
    overflow: auto;
}

.fm-status-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 0.85rem;
    border-bottom: 1px solid #f9fafb;
}

.fm-status-list li:last-child {
    border-bottom: 0;
}

.fm-empty,
.fm-loading {
    padding: 2rem 1.25rem;
    color: var(--fm-muted-2);
    font-size: 0.9rem;
}

.fm-alert {
    background: #fff7ed;
    color: #9a3412;
    border: 0;
    border-radius: 12px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.fm-perf {
    margin-top: 1.1rem;
}

code {
    background: #ffffff;
    color: #374151;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.12rem 0.4rem;
    font-size: 0.75rem;
}

.fm-sidebar-backdrop {
    display: none;
}

@media (min-width: 1600px) {
    .fm-kpi-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}

@media (max-width: 1400px) {
    .fm-charts {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 1100px) {
    .fm-charts,
    .fm-split {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .fm-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 8px 0 24px rgba(15, 23, 42, 0.08);
    }

    body.fm-sidebar-open .fm-sidebar {
        transform: none;
    }

    .fm-sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.28);
        z-index: 20;
    }

    body.fm-sidebar-open .fm-sidebar-backdrop {
        display: block;
    }
}

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

    .fm-page,
    .fm-topbar {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .fm-user-copy {
        display: none;
    }
}
