/**
 * MedFlow — Composants UI
 * Cards, KPIs, boutons, formulaires, alertes, chat, bed grid
 */

/* ── Cards ── */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-3);
    font-weight: 600;
}

.card-body {
    padding: 0;
}

.card-body-padded {
    padding: var(--space-5);
}

/* ── KPI Cards ── */
.kpi {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: var(--space-5) var(--space-5) var(--space-4);
    box-shadow: var(--shadow);
    border-top: 3px solid transparent;
    position: relative;
    overflow: hidden;
    transition: box-shadow var(--duration);
}

.kpi:hover { box-shadow: var(--shadow-lg); }

.kpi--red    { border-top-color: var(--red); }
.kpi--amber  { border-top-color: var(--amber-raw); }
.kpi--blue   { border-top-color: var(--blue); }
.kpi--green  { border-top-color: var(--green); }

.kpi-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-3);
    margin-bottom: var(--space-3);
    font-weight: 500;
}

.kpi-value {
    font-family: var(--font-display);
    font-size: var(--text-3xl);
    font-weight: 400;
    line-height: 1;
    margin-bottom: var(--space-2);
}

.kpi--red .kpi-value    { color: var(--red); }
.kpi--amber .kpi-value  { color: var(--amber); }
.kpi--blue .kpi-value   { color: var(--blue); }
.kpi--green .kpi-value  { color: var(--green); }

.kpi-unit {
    font-family: var(--font-ui);
    font-size: var(--text-md);
    font-weight: 300;
}

.kpi-delta {
    font-size: var(--text-xs);
    color: var(--ink-3);
}

/* ── Boutons ── */
.btn {
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: var(--text-xs);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration);
    border: none;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    line-height: 1.4;
}

.btn--navy   { background: var(--navy); color: #fff; }
.btn--navy:hover { background: var(--navy-light); }

.btn--red    { background: var(--red); color: #fff; }
.btn--red:hover { background: var(--red-dark); }

.btn--green  { background: var(--green); color: #fff; }
.btn--green:hover { background: var(--green-dark); }

.btn--ghost  { background: transparent; color: var(--ink-2); border: 1px solid var(--border); }
.btn--ghost:hover { border-color: var(--navy); color: var(--navy); }

.btn--lg {
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
}

/* ── Service rows (occupation) ── */
.service-row {
    display: grid;
    grid-template-columns: 120px 1fr 46px;
    align-items: center;
    gap: var(--space-4);
    padding: 13px var(--space-5);
    border-bottom: 1px solid var(--bg);
    transition: background var(--duration);
}

.service-row:last-child { border: none; }
.service-row:hover { background: var(--surface-2); }

.service-name {
    font-size: var(--text-sm);
    color: var(--ink-2);
}

.progress-track {
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 1.2s var(--ease-out);
}

.service-pct {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 500;
    text-align: right;
}

/* ── Alert rows ── */
.alert-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--bg);
    transition: background var(--duration);
}

.alert-row:last-child { border: none; }
.alert-row:hover { background: var(--surface-2); }

.alert-bar {
    width: 3px;
    min-height: 36px;
    border-radius: 2px;
    flex-shrink: 0;
}

.alert-row--critical .alert-bar { background: var(--red); }
.alert-row--warning .alert-bar  { background: var(--amber-raw); }
.alert-row--info .alert-bar     { background: var(--blue); }

.alert-body { flex: 1; }

.alert-title {
    font-size: var(--text-sm);
    font-weight: 500;
    margin-bottom: 2px;
}

.alert-row--critical .alert-title { color: var(--red); }
.alert-row--warning .alert-title  { color: var(--amber); }
.alert-row--info .alert-title     { color: var(--blue); }

.alert-desc {
    font-size: var(--text-xs);
    color: var(--ink-3);
}

.alert-time {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--ink-4);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Forecast bars ── */
.forecast-area {
    padding: var(--space-5) var(--space-5) var(--space-4);
}

.forecast-bars {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: 100px;
    gap: var(--space-4);
}

.forecast-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
}

.forecast-pct {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    color: var(--ink-2);
}

.forecast-bar {
    width: 100%;
    max-width: 48px;
    border-radius: 3px 3px 0 0;
    transition: height 1s var(--ease-out);
}

.forecast-labels {
    display: flex;
    justify-content: space-around;
    margin-top: var(--space-2);
    border-top: 1px solid var(--border-light);
    padding-top: var(--space-2);
}

.forecast-label {
    font-size: 10px;
    color: var(--ink-3);
    text-align: center;
    flex: 1;
}

/* ── Legend ── */
.legend {
    display: flex;
    gap: var(--space-5);
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-5);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    color: var(--ink-2);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 2px;
}

/* ── Bed grid ── */
.bed-unit {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    margin-bottom: var(--space-4);
    overflow: hidden;
}

.bed-unit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-5);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.bed-unit-name {
    font-weight: 500;
    color: var(--navy);
}

.bed-unit-sub {
    font-size: var(--text-xs);
    color: var(--ink-3);
    margin-top: 2px;
}

.bed-unit-pct {
    font-family: var(--font-mono);
    font-size: var(--text-md);
    font-weight: 500;
}

.bed-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    gap: 6px;
    padding: var(--space-4);
}

.bed-cell {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    transition: all var(--duration);
    position: relative;
}

.bed-cell:hover { transform: scale(1.08); }

.bed-cell--occupied  { background: var(--red-light); color: var(--red); }
.bed-cell--free      { background: var(--green-light); color: var(--green); }
.bed-cell--reserved  { background: var(--amber-light); color: var(--amber); }
.bed-cell--cleaning  { background: var(--blue-light); color: var(--blue); }

.bed-icon { font-size: 16px; }
.bed-number { font-family: var(--font-mono); font-size: 9px; font-weight: 500; }

/* ── Chat (triage) ── */
.chat-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    height: 520px;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
}

.chat-avatar {
    width: 36px;
    height: 36px;
    background: var(--navy);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
}

.chat-name {
    font-weight: 500;
    font-size: var(--text-sm);
}

.chat-status {
    font-size: var(--text-xs);
    color: var(--ink-3);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.message {
    display: flex;
    gap: var(--space-3);
    max-width: 85%;
}

.message--bot { align-self: flex-start; }
.message--user { align-self: flex-end; flex-direction: row-reverse; }

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.message--bot .message-avatar  { background: var(--navy); color: #fff; }
.message--user .message-avatar { background: var(--bg-alt); color: var(--ink-2); }

.message-bubble {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    line-height: 1.6;
}

.message--bot .message-bubble  { background: var(--surface-2); color: var(--ink); }
.message--user .message-bubble { background: var(--navy); color: #fff; }

.chat-input-area {
    border-top: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
}

.chat-chips {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-3);
}

.chip {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: var(--text-xs);
    color: var(--ink-2);
    cursor: pointer;
    transition: all var(--duration);
}

.chip:hover {
    border-color: var(--navy);
    color: var(--navy);
    background: var(--surface-2);
}

.chat-input-row {
    display: flex;
    gap: var(--space-2);
}

.chat-input {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    resize: none;
    outline: none;
    transition: border-color var(--duration);
}

.chat-input:focus { border-color: var(--navy); }

.chat-send {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--navy);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 16px;
    cursor: pointer;
    transition: background var(--duration);
}

.chat-send:hover { background: var(--navy-light); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Typing indicator ── */
.typing {
    display: flex;
    gap: 4px;
    padding: var(--space-3) var(--space-4);
    background: var(--surface-2);
    border-radius: var(--radius-md);
    width: fit-content;
}

.typing span {
    width: 6px;
    height: 6px;
    background: var(--ink-3);
    border-radius: 50%;
    animation: typingDot 1.4s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ── Orientation card (triage result) ── */
.orientation {
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin-top: var(--space-3);
}

.orientation--high   { background: var(--red-light); border: 1px solid var(--red); }
.orientation--medium { background: var(--amber-light); border: 1px solid var(--amber-raw); }
.orientation--low    { background: var(--green-light); border: 1px solid var(--green); }

.orientation-badge {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

.orientation--high .orientation-badge   { color: var(--red); }
.orientation--medium .orientation-badge { color: var(--amber); }
.orientation--low .orientation-badge    { color: var(--green); }

.orientation-line {
    font-size: var(--text-sm);
    margin-bottom: var(--space-1);
}

.orientation-emergency {
    margin-top: var(--space-3);
    padding: var(--space-2) var(--space-3);
    background: var(--red);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    text-align: center;
}

/* ── Triage sidebar ── */
.triage-sidebar-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    padding: var(--space-5);
    margin-bottom: var(--space-4);
}

.triage-sidebar-title {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-3);
    font-weight: 600;
    margin-bottom: var(--space-4);
}

.step-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    color: var(--ink-3);
}

.step-row--done { color: var(--green); }
.step-row--active { color: var(--navy); font-weight: 500; }

.step-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid currentColor;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xs);
    font-weight: 600;
    flex-shrink: 0;
}

.step-row--done .step-number { background: var(--green); color: #fff; border-color: var(--green); }
.step-row--active .step-number { border-color: var(--navy); color: var(--navy); }

.step-text { font-size: var(--text-sm); }

/* ── Emergency card ── */
.emergency-card {
    background: var(--red);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    text-align: center;
    color: #fff;
}

.emergency-label {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.8;
    margin-bottom: var(--space-2);
}

.emergency-number {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: 600;
}

.emergency-sub {
    font-size: var(--text-xs);
    opacity: 0.7;
    margin-top: var(--space-1);
}

/* ── Forms ── */
.form-group {
    margin-bottom: var(--space-5);
}

.form-label {
    display: block;
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--ink-2);
    margin-bottom: var(--space-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--text-md);
    color: var(--ink);
    background: var(--surface);
    outline: none;
    transition: border-color var(--duration), box-shadow var(--duration);
}

.form-input:focus {
    border-color: var(--navy);
    box-shadow: 0 0 0 3px rgba(27,50,82,0.1);
}

.form-input--code {
    font-family: var(--font-mono);
    font-size: var(--text-2xl);
    text-align: center;
    letter-spacing: 0.3em;
}

.form-hint {
    font-size: var(--text-xs);
    color: var(--ink-3);
    margin-top: var(--space-1);
}

.form-error {
    font-size: var(--text-xs);
    color: var(--red);
    margin-top: var(--space-1);
}

/* ── Login page ── */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: var(--space-6);
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: var(--space-12) var(--space-10);
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-brand {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    color: var(--navy);
    margin-bottom: var(--space-2);
}

.login-brand span { font-style: italic; color: var(--blue); }

.login-subtitle {
    font-size: var(--text-sm);
    color: var(--ink-3);
    margin-bottom: var(--space-8);
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26,26,46,0.5);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    opacity: 0;
    visibility: hidden;
    transition: all var(--duration);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(20px);
    transition: transform var(--duration-lg) var(--ease-out);
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: var(--space-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    color: var(--navy);
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 16px;
    color: var(--ink-3);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-body {
    padding: var(--space-5);
}

.modal-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
}

/* ── Toast notifications ── */
.toast-container {
    position: fixed;
    top: var(--space-5);
    right: var(--space-5);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.toast {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-4) var(--space-5);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 280px;
    animation: slideIn var(--duration-lg) var(--ease-out);
    border-left: 3px solid var(--blue);
}

.toast--success { border-left-color: var(--green); }
.toast--error   { border-left-color: var(--red); }
.toast--warning { border-left-color: var(--amber-raw); }

.toast-message { font-size: var(--text-sm); flex: 1; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Status select (bed modal) ── */
.status-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.status-option {
    padding: var(--space-3) var(--space-4);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: center;
    font-size: var(--text-sm);
    font-weight: 500;
    transition: all var(--duration);
}

.status-option:hover { border-color: var(--navy); }
.status-option.selected { border-color: var(--navy); background: var(--surface-2); }

.status-option--occupied  { color: var(--red); }
.status-option--free      { color: var(--green); }
.status-option--reserved  { color: var(--amber); }
.status-option--cleaning  { color: var(--blue); }
