/* Cards, badges, tables, modals, toasts, filters, login */

/* ── Stat cards ───────────────────────────────────────── */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.stat-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-md) 1.25rem;
    box-shadow: var(--shadow-xs);
}

.stat-card .label {
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.stat-card .value {
    font-size: var(--text-3xl);
    font-weight: 700;
    margin-top: var(--space-xs);
    color: var(--text-primary);
}

.stat-card .value.green { color: var(--green); }
.stat-card .value.red { color: var(--red); }
.stat-card .value.blue { color: var(--blue); }
.stat-card .value.yellow { color: var(--yellow); }

/* ── Hospital grid ────────────────────────────────────── */
.hospital-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.hospital-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
    box-shadow: var(--shadow-xs);
    cursor: pointer;
}

.hospital-card:hover {
    border-color: var(--blue);
    box-shadow: var(--shadow-sm);
}

.hospital-card .name {
    font-weight: 600;
    font-size: var(--text-lg);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.hospital-card .meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
    margin-top: 0.75rem;
    font-size: var(--text-base);
}

.hospital-card .meta .item {
    display: flex;
    flex-direction: column;
}

.hospital-card .meta .item .lbl {
    color: var(--text-dim);
    font-size: var(--text-xs);
    text-transform: uppercase;
    font-weight: 500;
}

.hospital-card .meta .item .val {
    font-weight: 600;
    margin-top: 0.125rem;
    color: var(--text-primary);
}

/* ── Table ────────────────────────────────────────────── */
.table-section {
    margin-bottom: var(--space-xl);
}

.table-wrap {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    box-shadow: var(--shadow-xs);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-base);
}

th {
    text-align: left;
    padding: 0.75rem var(--space-md);
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: var(--text-xs);
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: default;
}

th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover {
    color: var(--text-primary);
}

th .sort-arrow {
    margin-left: var(--space-xs);
    opacity: 0.4;
}

th .sort-arrow.active {
    opacity: 1;
}

td {
    padding: 0.625rem var(--space-md);
    border-bottom: 1px solid var(--bg-tertiary);
    color: var(--text-secondary);
}

tr.clickable {
    cursor: pointer;
}

tr.clickable:hover td {
    background: var(--bg-secondary);
}

/* ── Badges ───────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.125rem var(--space-sm);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    white-space: nowrap;
}

.badge.won, .badge.online { background: var(--green-bg); color: var(--green-text); }
.badge.lost { background: var(--red-bg); color: var(--red-text); }
.badge.error { background: var(--yellow-bg); color: var(--yellow-text); }
.badge.submitting { background: var(--blue-light); color: var(--blue-text); }
.badge.waiting { background: var(--purple-bg); color: var(--purple-text); }
.badge.detected { background: var(--bg-tertiary); color: var(--text-muted); }
.badge.completed { background: var(--green-bg); color: var(--green-text); }
.badge.offline { background: var(--bg-tertiary); color: var(--text-dim); }

/* ── Pagination ───────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem var(--space-md);
    border-top: 1px solid var(--border);
    font-size: var(--text-md);
    color: var(--text-muted);
}

.pagination .page-controls {
    display: flex;
    gap: var(--space-xs);
}

/* ── Filter bar ───────────────────────────────────────── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    align-items: center;
}

.filter-bar select,
.filter-bar input[type="date"] {
    width: auto;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    padding: 0.375rem 0.625rem;
    font-size: var(--text-md);
    font-family: var(--font-sans);
}

.filter-bar select:focus,
.filter-bar input[type="date"]:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ── Event log ────────────────────────────────────────── */
.events-log {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    max-height: 300px;
    overflow-y: auto;
    font-size: var(--text-base);
    font-family: var(--font-mono);
    box-shadow: var(--shadow-xs);
}

.events-log .entry {
    padding: var(--space-xs) 0;
    border-bottom: 1px solid var(--bg-tertiary);
    color: var(--text-muted);
}

.events-log .entry .time {
    color: var(--text-dim);
}

.events-log .entry .type {
    color: var(--blue);
    font-weight: 600;
}

/* ── Modal ────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

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

.modal {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    padding: var(--space-xl);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
}

.modal-header h2 {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
}

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

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

/* ── Toast ────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    display: flex;
    flex-direction: column-reverse;
    gap: var(--space-sm);
    z-index: 2000;
    pointer-events: none;
}

.toast {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.75rem var(--space-md);
    font-size: var(--text-md);
    color: var(--text-secondary);
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    animation: toast-in 0.3s ease;
    max-width: 360px;
}

.toast.toast-success { border-left: 3px solid var(--green); }
.toast.toast-error { border-left: 3px solid var(--red); }
.toast.toast-warning { border-left: 3px solid var(--yellow); }
.toast.toast-info { border-left: 3px solid var(--blue); }

.toast.toast-out {
    animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(10px); }
}

/* ── Login ────────────────────────────────────────────── */
.login-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

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

.login-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-md);
}

.login-card .login-logo {
    display: block;
    margin: 0 auto var(--space-md);
    height: 40px;
    width: auto;
    object-fit: contain;
}

.login-card h2 {
    font-size: var(--text-2xl);
    color: var(--text-primary);
    margin-bottom: var(--space-lg);
    text-align: center;
    font-weight: 700;
}

.login-card .form-group {
    margin-bottom: var(--space-md);
}

.login-card label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.login-card input[type="text"],
.login-card input[type="password"] {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.625rem 0.75rem;
    font-size: var(--text-md);
    font-family: var(--font-sans);
}

.login-card input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.login-card .login-error {
    color: var(--red);
    font-size: var(--text-md);
    margin-bottom: var(--space-md);
    text-align: center;
}

.login-card .btn-primary {
    width: 100%;
    padding: 0.625rem;
    font-size: var(--text-lg);
    justify-content: center;
    margin-top: var(--space-sm);
}

/* ── Section title ────────────────────────────────────── */
.section-title {
    font-size: var(--text-xl);
    font-weight: 600;
    margin-bottom: var(--space-md);
    color: var(--text-primary);
}

/* ── Loading spinner ──────────────────────────────────── */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    color: var(--text-muted);
    gap: var(--space-sm);
}

.loading-spinner::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ── Health status dots ───────────────────────────────── */
.health-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
    background: var(--text-dim);
}

.health-dot.green {
    background: var(--green);
    box-shadow: 0 0 4px var(--green);
}

.health-dot.yellow {
    background: var(--yellow);
    box-shadow: 0 0 4px var(--yellow);
}

.health-dot.red {
    background: var(--red);
    box-shadow: 0 0 4px var(--red);
    animation: health-pulse 1.5s ease-in-out infinite;
}

.health-dot.unknown {
    background: var(--text-dim);
}

@keyframes health-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Health badge (large, for detail page) ───────────── */
.health-badge {
    display: inline-block;
    padding: 0.375rem 1rem;
    border-radius: var(--radius-full);
    font-size: var(--text-lg);
    font-weight: 700;
    letter-spacing: 0.05em;
}

.health-badge.green {
    background: var(--green-bg);
    color: var(--green-text);
}

.health-badge.yellow {
    background: var(--yellow-bg);
    color: var(--yellow-text);
}

.health-badge.red {
    background: var(--red-bg);
    color: var(--red-text);
}

.health-badge.unknown {
    background: var(--bg-tertiary);
    color: var(--text-dim);
}

/* ── Health status section ───────────────────────────── */
.health-status-section {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: var(--space-md);
    box-shadow: var(--shadow-xs);
}

/* ── Health timeline ─────────────────────────────────── */
.health-timeline {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    max-height: 400px;
    overflow-y: auto;
    box-shadow: var(--shadow-xs);
}

.health-event-entry {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) 0;
    border-bottom: 1px solid var(--bg-tertiary);
    font-size: var(--text-base);
    font-family: var(--font-mono);
}

.health-event-entry .time {
    color: var(--text-dim);
}

.health-event-entry .type {
    color: var(--blue);
    font-weight: 600;
}

/* ── Confirm dialog ───────────────────────────────────── */
.confirm-body {
    font-size: var(--text-md);
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ── Alert banner ────────────────────────────────────── */
.alert-banner {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
    font-size: var(--text-md);
    font-weight: 500;
    border-left: 4px solid transparent;
}

.alert-banner.warning {
    background: var(--yellow-bg);
    border-left-color: var(--yellow);
    color: var(--yellow-text);
}

.alert-banner.danger {
    background: var(--red-bg);
    border-left-color: var(--red);
    color: var(--red-text);
}

.alert-banner .alert-hospitals {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-sm);
    margin-left: var(--space-sm);
}

.alert-banner .alert-hospital-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 600;
}

.alert-banner .alert-hospital-link:hover {
    opacity: 0.8;
}

/* ── Pipeline counts ─────────────────────────────────── */
.pipeline-counts {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-sm);
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

.pipeline-counts .pipeline-stage {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.pipeline-counts .pipeline-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.pipeline-dot.submitting { background: var(--blue); }
.pipeline-dot.waiting { background: var(--purple-text); }
.pipeline-dot.detected { background: var(--text-dim); }
.pipeline-dot.completed { background: var(--green); }

/* ── Quick actions on hospital cards ─────────────────── */
.quick-actions {
    display: flex;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--bg-tertiary);
}

.quick-actions .btn {
    font-size: var(--text-xs);
    padding: 0.25rem 0.5rem;
    flex: 1;
}

/* ── Urgent hospital card accents ────────────────────── */
.hospital-card.urgent-red {
    border-left: 3px solid var(--red);
    background: color-mix(in srgb, var(--red-bg) 30%, var(--bg-primary));
}

.hospital-card.urgent-yellow {
    border-left: 3px solid var(--yellow);
    background: color-mix(in srgb, var(--yellow-bg) 20%, var(--bg-primary));
}

.hospital-card.urgent-offline {
    border-left: 3px solid var(--text-dim);
    opacity: 0.85;
}
