:root {
    --bg-body: #f3f4f6;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;

    --text-main: #111827;
    --text-muted: #6b7280;

    --primary: #0284c7;
    /* Clinical Blue */
    --prominent: #0ea5e9;

    --success: #10b981;
    --warning: #f59e0b;
    --alert: #ef4444;
    --danger: #ef4444;

    --border: #e5e7eb;

    --font-main: 'Inter', sans-serif;
    --radius: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    display: flex;
}

/* Sidebar */
.app-wrapper {
    display: flex;
    width: 100vw;
    height: 100vh;
}

.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    z-index: 10;
}

.logo {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2rem;
    cursor: pointer;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.nav-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

.patient-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.patient-card {
    background: transparent;
    border: 1px solid transparent;
    padding: 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
}

.patient-card:hover {
    background: #f9fafb;
    border-color: var(--border);
}

.patient-card.active {
    background: #e0f2fe;
    /* Light Blue */
    border-color: var(--primary);
}

.patient-id {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
}

.patient-scenario {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* Main Content */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    overflow-y: auto;
    position: relative;
    max-width: 1600px;
    /* Prevent stretching on wide screens */
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

#pageTitle {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-main);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

.time-badge {
    background: #ffffff;
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.9rem;
    color: var(--text-muted);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Stats Row */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
}

.stat-val {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    font-feature-settings: "tnum";
}

.stat-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.stat-card.blue .stat-val {
    color: var(--primary);
}

.stat-card.green .stat-val {
    color: var(--success);
}

.stat-card.orange .stat-val {
    color: var(--warning);
}

.stat-card.red .stat-val {
    color: var(--alert);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.col-left,
.col-right {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Card General */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Vitals Grid */
.vitals-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.metric-box {
    background: #f9fafb;
    border: 1px solid var(--border);
    padding: 0.75rem;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
}

.metric-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.metric-input {
    background: transparent;
    border: none;
    font-family: inherit;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    width: 100%;
}

.metric-input:focus {
    outline: none;
    border-bottom: 2px solid var(--primary);
}

/* Body Position Illustration */
.illus-container {
    background: #1a1b26;
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow: hidden;
    min-height: 200px;
}

.illus-container svg {
    width: 100%;
    height: 200px;
    display: block;
}

.illus-subtitle {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-muted);
    font-style: italic;
}

/* Posture Selector Buttons */
.posture-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.posture-btn {
    flex: 1;
    min-width: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem;
    border-radius: 8px;
    background: #f9fafb;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.posture-btn:hover {
    background: #e0f2fe;
    border-color: var(--primary);
}

.posture-btn.active {
    background: #e0f2fe;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.25);
}

.posture-btn span {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-main);
}

.posture-mini {
    width: 120px;
    height: 60px;
    border-radius: 4px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
}


/* Decision Engine */
.decision-card {
    border-top: 4px solid #e5e7eb;
}

.alert-status {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.status-SAFE {
    color: var(--success);
    border-color: var(--success);
}

.status-WARNING {
    color: var(--warning);
    border-color: var(--warning);
}

.status-ALERT {
    color: var(--alert);
    border-color: var(--alert);
}

.alert-message {
    font-size: 1rem;
    color: var(--text-main);
    line-height: 1.5;
    margin-bottom: 1.5rem;
}

.logic-chain {
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Actions */
.action-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    margin-top: 1rem;
    width: 100%;
    transition: background 0.2s;
}

.action-btn:hover {
    background: #026aa7;
}

/* History */
.history-log {
    max-height: 200px;
    overflow-y: auto;
}

.history-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.history-item:last-child {
    border-bottom: none;
}

.hist-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.hist-action {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
}

.hist-detail {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Chart */
.chart-container {
    height: 250px;
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    padding-bottom: 1rem;
}

.chart-bar-group {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    position: relative;
}

.chart-bar {
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    transition: height 0.5s;
    width: 100%;
}

.bar-val {
    position: absolute;
    top: -20px;
    width: 100%;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
}

.bar-label {
    position: absolute;
    bottom: -25px;
    width: 100%;
    text-align: center;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===================================================================
   SIMULATOR STYLES
   =================================================================== */

/* Load Cells Grid */
.load-cells-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.load-cell {
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

.lc-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
}

.lc-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-main);
    font-feature-settings: "tnum";
}

.lc-unit {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Sim Rows */
.sim-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0;
}

.sim-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 110px;
    font-weight: 500;
}

.sim-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}

/* Risk Progress Bar */
.risk-progress-container {
    background: #e5e7eb;
    border-radius: 4px;
    height: 8px;
    margin: 0.4rem 0;
    overflow: hidden;
}

.risk-progress-bar {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.risk-bar-none     { background: var(--success); }
.risk-bar-low      { background: #fbbf24; }
.risk-bar-medium   { background: #f97316; }
.risk-bar-high     { background: var(--danger); }
.risk-bar-critical { background: #dc2626; animation: pulse-risk 1s infinite; }

@keyframes pulse-risk {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Risk Badge */
.risk-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 2rem;
    font-weight: 600;
    font-size: 0.8rem;
    display: inline-block;
}

.risk-none     { background: #d1fae5; color: #065f46; }
.risk-low      { background: #fef3c7; color: #92400e; }
.risk-medium   { background: #ffedd5; color: #9a3412; }
.risk-high     { background: #fee2e2; color: #991b1b; }
.risk-critical { background: #fecaca; color: #7f1d1d; font-weight: 800; }

/* Confidence Badge */
.confidence-badge {
    font-size: 0.8rem;
    font-weight: 600;
    margin-left: 0.25rem;
    padding: 0.15rem 0.5rem;
    border-radius: 2rem;
    background: #f3f4f6;
}

.conf-high { color: var(--success); background: #d1fae5; }
.conf-med  { color: var(--warning); background: #fef3c7; }
.conf-low  { color: var(--danger); background: #fee2e2; }

/* Zone Tags */
.zone-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.zone-tag {
    background: #fef3c7;
    color: #92400e;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.72rem;
    font-weight: 500;
}

/* Sim Recommendation */
.sim-recommendation {
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    margin: 0.4rem 0;
    font-style: italic;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Sim Toggle Button */
.sim-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.35rem 0.9rem;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s;
}

.sim-btn:hover { background: #026aa7; }

/* Sim History */
.sim-history {
    max-height: 150px;
    overflow-y: auto;
}

.sim-hist-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    padding: 0.3rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
}

.sim-hist-row:last-child {
    border-bottom: none;
}

.sim-hist-time {
    color: var(--text-muted);
    font-family: 'Roboto Mono', monospace;
    font-size: 0.75rem;
    min-width: 60px;
}

.sim-hist-posture {
    font-weight: 600;
    color: var(--text-main);
    flex: 1;
}

.sim-hist-dur {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.mono {
    font-family: 'Roboto Mono', monospace;
}

/* Utilities */
.hidden {
    display: none;
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-out;
}

.animate-alert {
    animation: pulseWarning 2s infinite;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulseWarning {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}