/* ── Variables ── */
:root {
    --bg-main: #000000;
    --bg-card: #181b26;
    --bg-office: #14161e;
    --text-main: #e2e8f0;
    --text-dim: #94a3b8;
    --accent: #3b82f6;
    --staff-color: #ef4444;
    --patient-color: #3b82f6;
    --desk-color: #64748b;
    --border: #2e344a;
    --radius: 12px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
}

/* ── Layout ── */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: 280px;
    min-width: 280px;
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px;
}
.sidebar-top { margin-bottom: 8px; }

/* ── Hospital info panel ── */
#hospital-info {
    display: block;
    margin-bottom: 12px;
    font-size: 0.78rem;
    color: var(--text-dim);
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
}
#hospital-info > * + * {
    margin-top: 5px;
}
.hi-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 2px;
}
.hi-row {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-main);
}
.hi-dept {
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    margin-top: 2px;
}
.hi-dept summary {
    padding: 5px 8px;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    list-style: none;
}
.hi-dept summary:hover { background: var(--border); }
.hi-code {
    font-size: 0.7rem;
    color: var(--text-dim);
    font-family: monospace;
}
.hi-doctors {
    list-style: none;
    padding: 4px 8px 6px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
    border-top: 1px solid var(--border);
    color: var(--text-main);
}
.logo p {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
}
.spacer { flex-grow: 0; }

/* ── Controls ── */
.controls { display: flex; flex-direction: column; gap: 16px; }
.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.control-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.control-group input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}
.api-key-optional {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: #475569;
}
.api-key-row {
    display: flex;
    gap: 6px;
}
.api-key-row input[type="password"],
.api-key-row input[type="text"] {
    flex: 1;
    background: #0f172a;
    border: 1px solid #2e344a;
    border-radius: 8px;
    padding: 7px 10px;
    color: var(--text-main);
    font-size: 0.82rem;
    outline: none;
    min-width: 0;
}
#api-key-toggle {
    flex: 0 0 auto;
    background: #1e293b;
    border: 1px solid #2e344a;
    border-radius: 8px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.9rem;
}
.range-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
}

/* ── Buttons ── */
#btn-sim-error {
    margin: 4px 0 0;
    font-size: 0.75rem;
    color: #ef4444;
    min-height: 1em;
}
.action-buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: #2563eb; }
.btn-primary:disabled { background: #475569; cursor: not-allowed; opacity: 0.5; }

/* ── Server status ── */
.server-status {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-align: center;
    min-height: 1.2rem;
    white-space: pre-line;
}

/* ── Main area ── */
.simulation-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 20px;
    overflow: auto;
}

/* ── Dashboard ── */
.dashboard {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 140px;
}
.stat-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
}

/* ── Office room ── */
.office-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.office-room {
    position: relative;
    width: 800px;
    height: 500px;
    background: var(--bg-office);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* ── Walls & doors ── */
.wall-label {
    position: absolute;
    font-size: 0.65rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.door {
    position: absolute;
    background: #334155;
    border: 1px dashed var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: var(--text-dim);
    letter-spacing: 0.05em;
}
.door-front {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    height: 20px;
    border-radius: 0 0 6px 6px;
}
.door-back {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    height: 20px;
    border-radius: 6px 6px 0 0;
}

/* ── Desk ── */
.desk {
    position: absolute;
    background: #1e293b;
    border: 2px solid var(--desk-color);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    color: var(--text-dim);
}

/* ── Person (circle) ── */
.person {
    position: absolute;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid;
    background: rgba(255,255,255,0.05);
    transition: left 0.6s ease, top 0.6s ease, opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5rem;
    font-weight: 700;
    color: var(--text-main);
}
.person.staff {
    border-color: var(--staff-color);
}
.person.patient {
    border-color: var(--patient-color);
}

/* ── Staff animation ── */
/* Staff movement is handled by JS positioning + CSS transition on .person */

/* ── Waiting area chairs ── */
.chair-row {
    position: absolute;
    display: flex;
    gap: 4px;
}
.chair {
    width: 20px;
    height: 20px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: #1e293b;
}

/* ── Legend ── */
.legend {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    padding: 8px 0;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-dim);
}
.blob {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 3px solid;
    background: rgba(255,255,255,0.05);
}
.staff-blob  { border-color: var(--staff-color); }
.patient-blob { border-color: var(--patient-color); }
.desk-blob {
    border-radius: 3px;
    border-color: var(--desk-color);
    background: #1e293b;
}

/* ── Speech bubble ── */
.speech-bubble {
    position: absolute;
    width: 22px;
    height: 22px;
    background: #fef3c7;
    border: 2px solid #f59e0b;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    z-index: 10;
    transition: transform 0.15s;
    user-select: none;
}
.speech-bubble:hover { transform: scale(1.2); }
.speech-bubble.loading { animation: bubble-pulse 1s ease-in-out infinite; }
@keyframes bubble-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.35; }
}

/* ── Dialog sidebar ── */
#dialog-sidebar {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 270px;
    min-width: 270px;
    max-width: 600px;
    background: #0f172a;
    border-left: 1px solid #1e293b;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 12px;
    overflow-y: auto;
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

/* ── Dialog sidebar resize handle ── */
#dialog-sidebar-resize {
    position: fixed;
    right: 270px;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: ew-resize;
    z-index: 51;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
body:has(#dialog-sidebar.visible) #dialog-sidebar-resize {
    opacity: 1;
    pointer-events: auto;
}
#dialog-sidebar-resize::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(255, 255, 255, 0.15);
    transition: background 0.2s;
}
#dialog-sidebar-resize:hover::after,
#dialog-sidebar-resize.dragging::after {
    background: rgba(59, 130, 246, 0.8);
}
#dialog-sidebar.visible { transform: translateX(0); }
#dialog-sidebar .sidebar-title {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    flex-shrink: 0;
    margin-bottom: 4px;
}

/* ── Dialog card (per pair) ── */
.dialog-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
}
.dialog-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 12px;
    cursor: pointer;
    user-select: none;
    gap: 8px;
}
.dialog-card-header:hover { background: #263548; }
.dialog-card-meta { display: flex; flex-direction: column; gap: 2px; }
.dialog-card-title {
    font-size: 11px;
    font-weight: 600;
    color: #e2e8f0;
}
.dialog-card-label {
    font-size: 10px;
    color: #64748b;
}
.dialog-card-arrow {
    font-size: 10px;
    color: #475569;
    margin-top: 2px;
    transition: transform 0.2s;
}
.dialog-card.dialog-active {
    border-color: #10b981;
    box-shadow: 0 0 0 1px #10b981;
}
.dialog-card.dialog-done {
    border-color: #475569;
}
.dialog-card.expanded .dialog-card-arrow { transform: rotate(180deg); }
.dialog-card-body {
    max-height: 0;
    overflow-y: auto;
    transition: max-height 0.3s ease, padding 0.2s ease;
    font-size: 11px;
    color: #cbd5e1;
    line-height: 1.6;
    padding: 0 12px;
}
.dialog-card.expanded .dialog-card-body {
    max-height: 300px;
    padding: 6px 12px 10px;
}
.dialog-card-body .turn { margin-bottom: 6px; }
.dialog-card-body .turn.admin   strong { color: #f87171; }
.dialog-card-body .turn.patient strong { color: #60a5fa; }
.dialog-card-loading {
    color: #475569;
    font-style: italic;
    font-size: 11px;
    padding: 8px 0;
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .app-container { flex-direction: column; }
    .sidebar {
        width: 100%;
        min-width: unset;
        flex-direction: row;
        flex-wrap: wrap;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 12px 16px;
        gap: 12px;
    }
    .spacer { display: none; }
    .controls { flex-direction: row; flex-wrap: wrap; gap: 12px; }
    .control-group { min-width: 140px; }
    .office-room { width: 100%; height: 400px; }
}
