/* ============================================================
   SIVIA Patient Digital Twin - Styles
   Author: SisaTech AI Inc.
   
   COLLAPSIBLE KG: Added styles for collapsible knowledge graph
   header, toggle button, and smooth transitions.
   ============================================================ */

/* -- Layout -------------------------------------------------- */
#digital-twin-container {
    padding: 8px;
    height: calc(100vh - 260px);
    overflow-y: auto;
}

.dt-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.dt-full-width {
    grid-column: 1 / -1;
}

/* -- Cards --------------------------------------------------- */
.dt-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.dt-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #f1f5f9;
}

.dt-card-title {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
}

.dt-card-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

/* -- Knowledge Graph Visualization --------------------------- */
#pkg-network {
    width: 100%;
    height: 500px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fafbfc;
}

.dt-graph-controls {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.dt-graph-controls button {
    font-size: 11px;
    padding: 3px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    color: #475569;
    transition: all 0.15s;
}

.dt-graph-controls button:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.dt-graph-controls button.active {
    background: #4A90D9;
    color: #fff;
    border-color: #4A90D9;
}

.dt-graph-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}

.dt-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #64748b;
}

.dt-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

/* -- COLLAPSIBLE KG: Header & Toggle Styles ----------------- */
.dt-kg-card {
    /* Slightly different styling when collapsed to look compact */
}

.dt-kg-header {
    user-select: none;
    margin-bottom: 0;
    transition: margin-bottom 0.2s ease;
}

.dt-kg-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dt-kg-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dt-kg-toggle-icon {
    font-size: 10px;
    color: #64748b;
    transition: transform 0.2s ease;
    width: 14px;
    text-align: center;
}

.dt-kg-node-count {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 400;
    margin-left: 4px;
}

.dt-kg-toggle-btn {
    font-size: 11px;
    padding: 3px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    color: #475569;
    transition: all 0.15s;
}

.dt-kg-toggle-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

/* When KG body is visible, add margin to header */
.dt-kg-card .dt-kg-header:has(+ #dt-kg-body[style*="display: block"]) {
    margin-bottom: 8px;
}

/* -- Risk Assessment ----------------------------------------- */
.dt-risk-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

/* -- Risk Card (Option B: left border accent + icon) --------- */
.dt-risk-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 10px 12px;
    border-left: 3px solid #e2e8f0;
    transition: box-shadow 0.15s ease;
}

.dt-risk-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.dt-risk-card.risk-border-critical { border-left-color: #dc2626; }
.dt-risk-card.risk-border-high { border-left-color: #ef4444; }
.dt-risk-card.risk-border-moderate { border-left-color: #f59e0b; }
.dt-risk-card.risk-border-low { border-left-color: #22c55e; }

.dt-risk-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.dt-risk-card-title {
    font-size: 11.5px;
    font-weight: 600;
    color: #334155;
    line-height: 1.2;
}

.dt-risk-card-evidence {
    font-size: 11px;
    color: #64748b;
    line-height: 1.4;
}

/* -- Inline Action Row --------------------------------------- */
.dt-risk-card-action {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #f1f5f9;
    font-size: 11px;
    font-weight: 500;
    color: #1e40af;
    line-height: 1.4;
}

.dt-action-icon {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    margin-top: 1px;
    color: #1e40af;
}

/* -- Severity Icons ------------------------------------------ */
.dt-risk-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* -- Overall Risk Banner ------------------------------------- */
.dt-overall-risk {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 10px;
}

.dt-overall-risk.risk-low { background: #f0fdf4; border: 1px solid #bbf7d0; }
.dt-overall-risk.risk-moderate { background: #fffbeb; border: 1px solid #fde68a; }
.dt-overall-risk.risk-high { background: #fef2f2; border: 1px solid #fecaca; }
.dt-overall-risk.risk-critical { background: #fef2f2; border: 1px solid #fca5a5; }

.dt-overall-icon {
    padding-top: 2px;
    flex-shrink: 0;
}

.dt-overall-icon .dt-risk-icon {
    width: 20px;
    height: 20px;
}

.dt-overall-info {
    flex: 1;
}

.dt-overall-level {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
}

.dt-overall-summary {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
    line-height: 1.4;
}

/* -- Alerts & Gaps ------------------------------------------- */
.dt-alert-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.dt-alert-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 12px;
}

.dt-alert-item:last-child {
    border-bottom: none;
}

.dt-alert-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: #fff;
}

.dt-alert-icon.high { background: #ef4444; }
.dt-alert-icon.medium { background: #f59e0b; }
.dt-alert-icon.low { background: #3b82f6; }

.dt-alert-text {
    flex: 1;
    color: #334155;
    line-height: 1.4;
}

.dt-alert-action {
    font-size: 11px;
    color: #64748b;
    font-style: italic;
}

/* -- Clinical Simulation Engine ------------------------------ */
.dt-sim-card {
    border: 1px solid #c7d2fe;
    background: linear-gradient(135deg, #fefefe 0%, #f8faff 100%);
}

.dt-sim-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #e0e7ff;
    color: #4338ca;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.dt-whatif-input {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.dt-whatif-input select,
.dt-whatif-input input {
    font-size: 12px;
    padding: 6px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
}

.dt-whatif-input input {
    flex: 1;
}

.dt-whatif-input button {
    font-size: 12px;
    padding: 6px 16px;
    background: linear-gradient(135deg, #4f46e5, #4A90D9);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    font-weight: 600;
    transition: all 0.2s;
}

.dt-whatif-input button:hover {
    background: linear-gradient(135deg, #4338ca, #3a7bc8);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

.dt-whatif-input button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.dt-sim-result {
    display: none;
}

/* -- Phased Loading Animation ------------------------------- */
.dt-sim-loading {
    padding: 16px;
}

.dt-sim-phases {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dt-sim-phase {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.dt-sim-phase.active {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
}

.dt-sim-phase.pending {
    opacity: 0.5;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.dt-sim-phase.done {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    opacity: 1;
}

.dt-sim-phase-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dt-sim-phase-text {
    font-size: 12px;
    color: #334155;
}

.dt-sim-phase-detail {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 1px;
}

.dt-spinner-sm {
    width: 16px;
    height: 16px;
    border: 2px solid #e2e8f0;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: dt-spin 0.8s linear infinite;
}

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

.dt-phase-check {
    color: #16a34a;
    font-size: 14px;
    font-weight: 700;
}

/* -- Simulation Result Container ----------------------------- */
.dt-sim-result-container {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

/* -- Header -------------------------------------------------- */
.dt-sim-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.dt-sim-header.rec-proceed { background: linear-gradient(135deg, #f0fdf4, #dcfce7); border-bottom: 2px solid #22c55e; }
.dt-sim-header.rec-caution { background: linear-gradient(135deg, #fffbeb, #fef3c7); border-bottom: 2px solid #f59e0b; }
.dt-sim-header.rec-defer { background: linear-gradient(135deg, #f8fafc, #f1f5f9); border-bottom: 2px solid #94a3b8; }
.dt-sim-header.rec-contra { background: linear-gradient(135deg, #fef2f2, #fecaca); border-bottom: 2px solid #ef4444; }

.dt-sim-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dt-sim-rec-icon {
    font-size: 20px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255,255,255,0.7);
    flex-shrink: 0;
}

.rec-proceed .dt-sim-rec-icon { color: #16a34a; }
.rec-caution .dt-sim-rec-icon { color: #d97706; }
.rec-defer .dt-sim-rec-icon { color: #64748b; }
.rec-contra .dt-sim-rec-icon { color: #dc2626; }

.dt-sim-rec-label {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.rec-proceed .dt-sim-rec-label { color: #16a34a; }
.rec-caution .dt-sim-rec-label { color: #d97706; }
.rec-defer .dt-sim-rec-label { color: #64748b; }
.rec-contra .dt-sim-rec-label { color: #dc2626; }

.dt-sim-scenario {
    font-size: 12px;
    color: #475569;
    margin-top: 2px;
}

.dt-sim-header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.dt-sim-conf {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
}

.dt-sim-conf.conf-high { background: #dcfce7; color: #16a34a; }
.dt-sim-conf.conf-mod { background: #fef3c7; color: #d97706; }
.dt-sim-conf.conf-low { background: #fee2e2; color: #dc2626; }

.dt-sim-impact-stats {
    display: flex;
    gap: 10px;
    font-size: 10px;
    color: #94a3b8;
}

/* -- Affected Conditions Bar --------------------------------- */
.dt-sim-conds-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.dt-sim-cond-tag {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #e0e7ff;
    color: #4338ca;
    font-weight: 500;
}

/* -- Sections ------------------------------------------------ */
.dt-sim-section {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
}

.dt-sim-section:last-of-type {
    border-bottom: none;
}

.dt-sim-section-title {
    font-size: 12px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* -- Risk Score Grid ----------------------------------------- */
.dt-sim-risk-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.dt-sim-risk-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 10px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.dt-sim-risk-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.dt-sim-risk-card.risk-decrease::before { background: #22c55e; }
.dt-sim-risk-card.risk-increase::before { background: #ef4444; }
.dt-sim-risk-card.risk-neutral::before { background: #94a3b8; }

.dt-sim-risk-label {
    font-size: 10px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.dt-sim-risk-arrow {
    font-size: 22px;
    line-height: 1;
    margin-bottom: 2px;
}

.risk-decrease .dt-sim-risk-arrow { color: #22c55e; }
.risk-increase .dt-sim-risk-arrow { color: #ef4444; }
.risk-neutral .dt-sim-risk-arrow { color: #94a3b8; }

.dt-sim-risk-mag {
    font-size: 11px;
    font-weight: 600;
    text-transform: capitalize;
    margin-bottom: 4px;
}

.risk-decrease .dt-sim-risk-mag { color: #16a34a; }
.risk-increase .dt-sim-risk-mag { color: #dc2626; }
.risk-neutral .dt-sim-risk-mag { color: #64748b; }

.dt-sim-risk-expl {
    font-size: 10px;
    color: #64748b;
    line-height: 1.3;
}

/* -- Pills --------------------------------------------------- */
.dt-sim-pills-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dt-sim-pills-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.dt-sim-pills-label {
    font-size: 11px;
    font-weight: 600;
    color: #475569;
    margin-right: 4px;
}

.dt-sim-pill {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.pill-benefit { background: #dcfce7; color: #16a34a; }
.pill-risk { background: #fee2e2; color: #dc2626; }
.pill-interaction { background: #fef3c7; color: #d97706; }

/* -- Prose --------------------------------------------------- */
.dt-sim-prose {
    font-size: 12px;
    line-height: 1.6;
    color: #334155;
    max-height: 500px;
    overflow-y: auto;
    padding-right: 8px;
}

.dt-sim-prose h3.dt-sim-h1,
.dt-sim-prose h4.dt-sim-h2,
.dt-sim-prose h5.dt-sim-h3 {
    color: #1e293b;
    margin: 12px 0 6px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid #f1f5f9;
}

.dt-sim-prose h4.dt-sim-h2 {
    font-size: 13px;
    font-weight: 600;
}

.dt-sim-prose h5.dt-sim-h3 {
    font-size: 12px;
    font-weight: 600;
}

.dt-sim-prose ul {
    margin: 4px 0;
    padding-left: 18px;
}

.dt-sim-prose li {
    margin-bottom: 3px;
}

.dt-sim-prose strong {
    color: #1e293b;
}

/* -- Monitoring Timeline ------------------------------------- */
.dt-sim-timeline {
    display: flex;
    flex-direction: column;
    position: relative;
    padding-left: 20px;
}

.dt-sim-timeline::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: #e2e8f0;
}

.dt-sim-timeline-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 0;
    position: relative;
}

.dt-sim-timeline-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #4f46e5;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px #c7d2fe;
    flex-shrink: 0;
    position: absolute;
    left: -20px;
    top: 8px;
}

.dt-sim-timeline-content {
    flex: 1;
}

.dt-sim-timeline-time {
    font-size: 11px;
    font-weight: 600;
    color: #4f46e5;
    margin-bottom: 2px;
}

.dt-sim-timeline-actions {
    font-size: 11px;
    color: #475569;
    margin: 0;
    padding-left: 16px;
}

.dt-sim-timeline-actions li {
    margin-bottom: 1px;
}

/* -- Footer -------------------------------------------------- */
.dt-sim-footer {
    display: flex;
    justify-content: space-between;
    padding: 8px 16px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    font-size: 9px;
    color: #94a3b8;
}

/* -- Error & Empty States ------------------------------------ */
.dt-sim-error {
    padding: 16px;
    text-align: center;
    color: #dc2626;
    font-size: 12px;
    background: #fef2f2;
    border-radius: 6px;
}

.dt-sim-empty {
    padding: 12px;
    text-align: center;
    color: #94a3b8;
    font-size: 12px;
    font-style: italic;
}

/* -- Query Panel --------------------------------------------- */
.dt-query-input {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.dt-query-input input {
    flex: 1;
    font-size: 12px;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
}

.dt-query-input button {
    font-size: 12px;
    padding: 6px 14px;
    background: #4A90D9;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.dt-query-result {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 10px;
    font-size: 12px;
    line-height: 1.5;
    color: #334155;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.dt-query-result.visible {
    display: block;
}

/* -- Node Stats Bar ------------------------------------------ */
.dt-stats-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.dt-stat-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: #f1f5f9;
    border-radius: 12px;
    font-size: 11px;
    color: #475569;
}

.dt-stat-chip .count {
    font-weight: 600;
    color: #1e293b;
}

/* -- Loading & Empty States ---------------------------------- */
.dt-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #94a3b8;
}

.dt-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e2e8f0;
    border-top-color: #4A90D9;
    border-radius: 50%;
    animation: dt-spin 0.8s linear infinite;
    margin-bottom: 10px;
}

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

.dt-empty {
    text-align: center;
    padding: 20px;
    color: #94a3b8;
    font-size: 13px;
}

/* -- Toolbar ------------------------------------------------- */
.dt-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 4px 0;
}

.dt-toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dt-toolbar-right {
    display: flex;
    gap: 6px;
}

.dt-toolbar button {
    font-size: 11px;
    padding: 4px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    color: #475569;
}

.dt-toolbar button:hover {
    background: #f1f5f9;
}

.dt-toolbar .dt-title {
    font-size: 15px;
    font-weight: 600;
    color: #1e293b;
}

.dt-toolbar .dt-subtitle {
    font-size: 11px;
    color: #94a3b8;
}


/* -- Session Chain (What-If Memory) ------------------------------ */
.dt-session-chain {
    margin: 0 16px 8px 16px;
}

.dt-chain-banner {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #eef2ff 0%, #f0f9ff 100%);
    border: 1px solid #c7d2fe;
    border-radius: 6px;
    font-size: 12px;
}

.dt-chain-label {
    font-weight: 600;
    color: #4338ca;
    white-space: nowrap;
}

.dt-chain-item {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dt-chain-item.chain-proceed {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}

.dt-chain-item.chain-caution {
    background: #fef9c3;
    color: #854d0e;
    border: 1px solid #fde047;
}

.dt-chain-item.chain-defer {
    background: #e2e8f0;
    color: #475569;
    border: 1px solid #cbd5e1;
}

.dt-chain-item.chain-contra {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.dt-chain-arrow {
    color: #6366f1;
    font-weight: bold;
    font-size: 14px;
}

.dt-sim-reset-btn {
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: 4px;
}

.dt-sim-reset-btn:hover {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fca5a5;
}
