/* ===== CUSTOM PROPERTIES ===== */
:root {
    --bg: #ffffff;
    --bg-soft: #f8fafc;
    --bg-hover: #f1f5f9;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --blue: #1e40af;
    --blue-light: #2563eb;
    --blue-bg: #eff6ff;
    --blue-border: #bfdbfe;
    --teal: #0f766e;
    --teal-light: #0d9488;
    --teal-bg: #f0fdfa;
    --teal-border: #99f6e4;
    --purple: #7c3aed;
    --purple-bg: #f5f3ff;
    --purple-border: #ddd6fe;
    --radius: 16px;
    --radius-sm: 12px;
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.04), 0 2px 6px rgba(0, 0, 0, 0.02);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.07), 0 1px 4px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.1), 0 4px 12px rgba(0, 0, 0, 0.04);
    --font: 'Plus Jakarta Sans', 'Segoe UI', 'Inter', system-ui, -apple-system, sans-serif;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== RESET ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

/* ===== BODY & TYPOGRAPHY ===== */
body {
    background: radial-gradient(circle at top right, #e2e8f0 0%, var(--bg) 60%),
        radial-gradient(circle at bottom left, #eaf0f6 0%, var(--bg) 60%);
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 15px;
    height: 100vh;
    overflow: hidden;
    position: relative;
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: linear-gradient(rgba(148, 163, 184, 0.15) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.15) 1px, transparent 1px);
    background-size: 30px 30px;
    z-index: -1;
    mask-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 1) 30%, rgba(0, 0, 0, 0) 80%);
    -webkit-mask-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 1) 30%, rgba(0, 0, 0, 0) 80%);
}

/* ===== BASE STYLES ===== */
.i {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.i-sm {
    width: 16px;
    height: 16px;
}

.i-lg {
    width: 22px;
    height: 22px;
}

.i-go {
    width: 16px;
    height: 16px;
    opacity: 0.35;
    transition: opacity var(--transition);
}

/* ===== CANVAS (full viewport) ===== */
.canvas {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== TOP BAR ===== */
.topbar {
    padding: 1rem 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    flex-shrink: 0;
    z-index: 10;
}

.topbar-title {
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--blue), var(--teal));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.topbar-sub {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== GRID AREA ===== */
.grid-area {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 80px 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 0;
    padding: 1.5rem 2.5rem;
    min-height: 0;
    align-items: center;
}

/* ===== NODE CARDS ===== */
.node-card {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 16px;
    padding: 1.6rem 1.8rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03), inset 0 1px 0 rgba(255, 255, 255, 1);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    transition: all var(--transition);
    overflow: hidden;
    position: relative;
}

.node-card:hover {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.02), inset 0 1px 0 rgba(255, 255, 255, 1);
    transform: translateY(-2px);
}

.central-node {
    grid-column: 1;
    grid-row: 1 / 3;
    align-self: center;
    border-top: 4px solid var(--blue);
    box-shadow: 0 10px 30px -5px rgba(37, 99, 235, 0.1), inset 0 1px 0 rgba(255, 255, 255, 1);
}

.central-node:hover {
    box-shadow: 0 25px 35px -5px rgba(37, 99, 235, 0.15), inset 0 1px 0 rgba(255, 255, 255, 1);
}

.hospital-stack {
    grid-column: 3;
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
    align-self: center;
}

.hospital-node {
    border-top: 4px solid var(--teal);
    box-shadow: 0 8px 25px -5px rgba(13, 148, 136, 0.08), inset 0 1px 0 rgba(255, 255, 255, 1);
}

.hospital-node:hover {
    box-shadow: 0 20px 30px -5px rgba(13, 148, 136, 0.12), inset 0 1px 0 rgba(255, 255, 255, 1);
}

/* Connector column */
.conn-labels {
    grid-column: 2;
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    padding: 2rem 0;
}

.conn-label {
    writing-mode: vertical-lr;
    text-orientation: mixed;
    font-size: 0.58rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.02em;
    text-align: center;
    opacity: 0.7;
}

/* ===== NODE HEAD ===== */
.node-head {
    margin-bottom: 0.6rem;
}

.node-badge {
    display: inline-block;
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    padding: 0.15rem 0;
}

.badge-blue {
    color: var(--blue);
}

.badge-teal {
    color: var(--teal);
}

.node-desc {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    font-weight: 500;
    line-height: 1.4;
}

.identical-tag {
    float: right;
    font-size: 0.72rem;
    color: var(--text-muted);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-weight: 500;
}

/* ===== PORTAL CARDS (square, in a row) ===== */
.portal-list {
    display: flex;
    flex-direction: row;
    gap: 0.6rem;
    margin-bottom: 0.6rem;
}

.portal-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    text-align: center;
    padding: 1.1rem 0.7rem;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    text-decoration: none;
    color: var(--text);
    background: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    /* playful spring bounce */
    cursor: pointer;
    aspect-ratio: 1 / 1;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.hospital-node .portal-link {
    aspect-ratio: auto;
    padding: 0.85rem 0.5rem;
}

.portal-link::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 12px;
    background: var(--blue-bg);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.portal-link.teal::before {
    background: var(--teal-bg);
}

.portal-link:hover {
    border-color: var(--blue);
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 12px 20px -8px rgba(37, 99, 235, 0.4);
}

.portal-link:hover::before {
    opacity: 1;
}

.portal-link.teal:hover {
    border-color: var(--teal);
    box-shadow: 0 12px 20px -8px rgba(13, 148, 136, 0.4);
}

.portal-link>.i:first-child {
    color: var(--blue);
    width: 30px;
    height: 30px;
}

.portal-link.teal>.i:first-child {
    color: var(--teal);
}

.portal-link .i-go {
    display: none;
}

.pl-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    min-width: 0;
}

.pl-text strong {
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1.25;
}

.pl-text small {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 400;
    line-height: 1.3;
}

/* Component tags on portal cards */
.comp-tags {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.2rem;
    margin-top: 0.25rem;
}

.ctag {
    font-size: 0.58rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    letter-spacing: 0.01em;
}

.ctag.blue {
    background: var(--blue-bg);
    color: var(--blue);
}

.ctag.teal {
    background: var(--teal-bg);
    color: var(--teal);
}

.ctag.purple {
    background: var(--purple-bg);
    color: var(--purple);
}

.tag-shared {
    color: var(--blue-light);
    font-style: normal;
    font-weight: 600;
}

.tag-sep {
    color: var(--purple);
    font-style: normal;
    font-weight: 600;
}

/* ===== EXPAND BUTTON ===== */
.expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.3rem;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
    flex-shrink: 0;
}

.expand-btn:hover {
    background: var(--blue-bg);
    border-color: var(--blue-border);
    color: var(--blue);
}

.expand-btn.teal:hover {
    background: var(--teal-bg);
    border-color: var(--teal-border);
    color: var(--teal);
}

/* ===== SVG CONNECTORS ===== */
.connectors-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    /* Behind node cards */
    opacity: 0.85;
}

.connectors-svg line {
    stroke: url(#lineGradient);
    stroke-width: 2.5;
    stroke-dasharray: 8 6;
    animation: dashFlow 2s linear infinite;
    filter: drop-shadow(0 0 6px rgba(37, 99, 235, 0.4));
}

@keyframes dashFlow {
    to {
        stroke-dashoffset: -20;
    }
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.25);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2vh 2vw;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
}

.modal-overlay.hidden {
    display: none;
}

.modal-panel {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 1400px;
    max-height: 96vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

#modal-body {
    padding: 2.2rem 2.8rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Modal Multi-Column Layout */
.modal-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2.5rem;
    align-items: flex-start;
}

.modal-col {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Modal Layer Nav (Tabs) */
.layer-nav {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border-light);
}

.layer-btn {
    background: transparent;
    border: none;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 0.8rem 1rem;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all var(--transition);
}

.layer-btn:hover {
    color: var(--teal);
}

.layer-btn.active {
    color: var(--teal);
    border-bottom-color: var(--teal);
}

.layer-content {
    display: block;
    animation: fadeIn 0.3s ease;
}

.layer-content.hidden {
    display: none;
}



@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
}

.modal-close {
    position: absolute;
    top: 1.2rem;
    right: 1.5rem;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
    z-index: 10;
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text);
}

/* ===== MODAL CONTENT ===== */
.m-title {
    font-size: 1.65rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.m-title.blue {
    color: var(--blue);
}

.m-title.teal {
    color: var(--teal);
}

.m-sub {
    font-size: 0.92rem;
    color: var(--text-muted);
    font-weight: 500;
    margin: 0.3rem 0 1.5rem;
    line-height: 1.5;
    max-width: 800px;
}

/* Section headers */
.m-section {
    margin-bottom: 1.5rem;
}

.m-section-head {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    padding: 0.35rem 0 0.35rem 0.75rem;
    border-left: 3px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: none;
}

.m-section-head.blue {
    color: var(--blue);
    border-left-color: var(--blue);
}

.m-section-head.teal {
    color: var(--teal);
    border-left-color: var(--teal);
}

.m-section-head.purple {
    color: var(--purple);
    border-left-color: var(--purple);
}

/* Component list in modal */
.comp-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
}

.comp-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--border-light);
    border-left: 3px solid var(--border);
    border-radius: 4px 10px 10px 4px;
    background: var(--bg);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
}

.comp-item:hover {
    background: var(--bg-soft);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.03);
    transform: translateY(-1px);
}

.comp-item.blue:hover {
    border-left-color: var(--blue);
}

.comp-item.teal:hover {
    border-left-color: var(--teal);
}

.comp-item.purple:hover {
    border-left-color: var(--purple);
}

.comp-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.comp-icon.blue {
    background: var(--blue-bg);
    color: var(--blue);
}

.comp-icon.teal {
    background: var(--teal-bg);
    color: var(--teal);
}

.comp-icon.purple {
    background: var(--purple-bg);
    color: var(--purple);
}

.comp-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.25;
}

.comp-desc {
    font-size: 0.76rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin-top: 0.15rem;
}

/* Portal cards in modal */
.m-portals {
    display: grid;
    gap: 0.5rem;
    grid-template-columns: 1fr 1fr;
}

.m-portals.cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.m-portals.cols-2 {
    grid-template-columns: 1fr 1fr;
}

.m-portals.cols-1 {
    grid-template-columns: 1fr;
}

.m-portal {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 1.1rem 1.15rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    transition: all var(--transition);
    background: var(--bg-soft);
}

.m-portal:hover {
    background: var(--bg);
    box-shadow: var(--shadow);
    border-color: var(--blue-border);
    transform: translateY(-2px);
}

.m-portal.teal:hover {
    border-color: var(--teal-border);
}

.m-portal-name {
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.m-portal-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.m-portal-go {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--blue);
    margin-top: 0.25rem;
    letter-spacing: 0.01em;
}

.m-portal.teal .m-portal-go {
    color: var(--teal);
}

/* Role badges */
.role-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.25rem;
}

.role-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--teal-bg);
    color: var(--teal);
    border: 1px solid var(--teal-border);
}

/* Flow sections (collapsible) */
.flow-toggle {
    width: 100%;
    text-align: left;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.9rem;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.flow-toggle:hover {
    background: var(--bg-soft);
    color: var(--text);
    border-color: var(--blue-border);
}

.flow-toggle.active {
    background: var(--blue-bg);
    color: var(--blue);
    border-color: var(--blue-border);
}

.flow-toggle.active.teal-flow {
    background: var(--teal-bg);
    color: var(--teal);
    border-color: var(--teal-border);
}

.flow-body {
    display: none;
    padding: 0.85rem 1rem;
    background: var(--bg-soft);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    margin-top: -0.25rem;
}

.flow-body.open {
    display: block;
}

.flow-step {
    position: relative;
    padding: 0.35rem 0 0.35rem 1.4rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

.flow-step::before {
    content: '';
    position: absolute;
    left: 0.3rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--blue-border);
}

.flow-step::after {
    content: '';
    position: absolute;
    left: 0.1rem;
    top: 0.55rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--blue-bg);
    border: 2px solid var(--blue-light);
}

.flow-step:last-child::before {
    height: 55%;
}

.flow-step b {
    color: var(--text);
    font-weight: 700;
}

.flow-step.teal-step::before {
    background: var(--teal-border);
}

.flow-step.teal-step::after {
    background: var(--teal-bg);
    border-color: var(--teal-light);
}

/* Partition legend */
.partition-box {
    background: var(--bg-soft);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-top: 0.4rem;
}

.partition-box strong {
    color: var(--teal);
    font-weight: 700;
}

/* Divider */
.m-divider-wrap {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 2.2rem 0;
}

.m-divider {
    flex: 1;
    border: none;
    border-top: 1px dashed var(--border);
    margin: 0;
}

.m-divider-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--teal);
    background: var(--teal-bg);
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--teal-border);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 960px) {
    .grid-area {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        gap: 1rem;
        overflow-y: auto;
    }

    .central-node {
        grid-column: 1;
        grid-row: 1;
    }

    .hospital-stack {
        grid-column: 1;
        grid-row: 2;
    }

    .conn-labels {
        display: none;
    }

    html,
    body {
        overflow: auto;
    }

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

    .m-portals {
        grid-template-columns: 1fr;
    }
}