/* ============================================
   DASHBOARD — Widgets, Gauges, Charts
   ============================================ */

/* Dashboard loading uses .gate-spinner from components.css */

/* Stats Row */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.stat-card {
    background: var(--color-bg-elevated);
    border: 1.5px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--space-lg) var(--space-md);
    text-align: center;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-card);
}

.stat-card:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-2px);
}

.stat-card .stat-value {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-top: 6px;
    line-height: 1.3;
    font-weight: 500;
}

.stat-card.optimal .stat-value { color: var(--color-optimal); }
.stat-card.suboptimal .stat-value { color: var(--color-suboptimal); }
.stat-card.critical .stat-value { color: var(--color-critical); }

/* System Overview Cards */
.system-card {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-card);
    display: grid;
    grid-template-rows: 4em auto auto 1fr;
    grid-template-areas:
        "name"
        "status"
        "summary"
        "markers";
}

.system-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
}

.system-card.good { border-color: var(--color-optimal-border); }
.system-card.good::before { background: linear-gradient(90deg, var(--color-optimal), #22c55e); }
.system-card.attention { border-color: var(--color-suboptimal-border); }
.system-card.attention::before { background: linear-gradient(90deg, var(--color-suboptimal), #f59e0b); }
.system-card.concern { border-color: var(--color-critical-border); }
.system-card.concern::before { background: linear-gradient(90deg, var(--color-critical), #ef4444); }

.system-card:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
}

.system-card .system-icon {
    display: none;
}

.system-card .system-name {
    grid-area: name;
    font-family: var(--font-heading);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.2;
    display: flex;
    align-items: flex-start;
}

.system-card .system-status {
    grid-area: status;
    margin-bottom: 4px;
}

.system-card .badge {
    font-size: 0.55rem;
    padding: 1px 5px;
    gap: 0;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.system-card .system-summary {
    grid-area: summary;
    font-size: 0.75rem;
    color: var(--color-text-light);
    line-height: 1.4;
}

.system-card .system-markers {
    grid-area: markers;
    align-self: end;
    padding-top: 6px;
    border-top: 1px solid var(--color-border-light);
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.system-card .marker-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    transition: transform var(--transition-fast);
}

.system-card:hover .marker-dot {
    transform: scale(1.15);
}

.marker-dot.optimal { background: var(--color-optimal); }
.marker-dot.suboptimal { background: var(--color-suboptimal); }
.marker-dot.critical { background: var(--color-critical); }
.marker-dot.missing { background: var(--color-border); }

/* Donut Chart */
.donut-chart {
    width: 160px;
    height: 160px;
    position: relative;
    margin: 0 auto;
}

.donut-chart svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.donut-chart .donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.donut-chart .donut-value {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1;
}

.donut-chart .donut-label {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* Patient Card */
.patient-card {
    background: var(--color-bg-elevated);
    border: 1.5px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-card);
}

.patient-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-2px);
}

.patient-card .patient-name {
    font-family: var(--font-heading);
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: var(--space-xs);
    letter-spacing: -0.01em;
}

.patient-card .patient-meta {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    display: flex;
    gap: var(--space-md);
}

.patient-card .patient-status {
    margin-top: var(--space-md);
}

/* Recent Tests List */
.test-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) 0;
    border-bottom: 1px solid var(--color-border-light);
}

.test-list-item:last-child {
    border-bottom: none;
}

.test-list-item .test-date {
    font-weight: 500;
    font-size: 1rem;
}

.test-list-item .test-status {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

/* Dashboard Table — Recent Analyses */
.dashboard-table {
    background: var(--color-bg-elevated);
    border: 1.5px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-card);
}

/* Grid: Patient | Lang (no header) | Status | Test Date | Analysis Date | View Oval | Delete */
.dashboard-table-header {
    display: grid;
    grid-template-columns: 1.5fr 0.45fr 1.5fr 1fr 1fr 104px 28px;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg-alt);
    border-bottom: 1px solid var(--color-border);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.dashboard-table-row {
    display: grid;
    grid-template-columns: 1.5fr 0.45fr 1.5fr 1fr 1fr 104px 28px;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border-light);
    align-items: center;
    transition: background var(--transition-fast);
}

.dash-row-clickable {
    cursor: pointer;
}

.dash-row-clickable:hover {
    background: rgba(30, 41, 59, 0.04);
}

.dashboard-table-row:last-child {
    border-bottom: none;
}

.dashboard-table-row:hover {
    background: var(--color-bg-alt);
}

.dashboard-table-cell {
    font-size: 0.9375rem;
}

.cell-date {
    color: var(--color-text-muted);
}

/* Date font-size only in data rows — header inherits the standard 0.75rem */
.dashboard-table-row .cell-date {
    font-size: 0.875rem;
}

/* ─── Dashboard Layout ─────────────────────────────────── */
.dash-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
}

.dash-greeting-bar {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.dash-greeting {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
}

.dash-date {
    color: var(--color-text-muted);
    font-size: 0.9375rem;
}

.dash-summary-line {
    display: block;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    font-weight: 400;
    margin-top: 2px;
}

/* ─── Search — Prominent Full Width ──────────────────── */
.dash-search-input {
    display: block;
    width: 100%;
    padding: 11px 16px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    font-family: var(--font-body);
    background: var(--color-bg-elevated);
    color: var(--color-text);
    margin-bottom: var(--space-lg);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: var(--shadow-card);
}

.dash-search-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(30, 41, 59, 0.12);
}

.dash-search-input::placeholder {
    color: var(--color-text-muted);
    font-weight: 500;
}

.dash-no-results {
    justify-content: center;
    color: var(--color-text-muted);
    font-style: italic;
}

/* ─── Quick Actions ────────────────────────────────────── */
.dash-section-title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--space-md);
    color: var(--color-text);
    letter-spacing: -0.01em;
}

.dash-action-row {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.dash-action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px !important;
    font-size: 0.9375rem !important;
    border-radius: var(--radius-md) !important;
}

.dash-action-icon {
    font-size: 1.1rem;
}

/* ─── Status Badges ────────────────────────────────────── */
.dash-status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.dash-status-badge.status-pending {
    background: rgba(212, 168, 67, 0.12);
    color: var(--color-suboptimal);
}

.dash-status-badge.status-progress {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.dash-status-badge.status-done {
    background: rgba(22, 163, 74, 0.12);
    color: var(--color-optimal);
}

/* ─── Status Ovals ────────────────────────────────────── */
.dash-ovals {
    display: flex;
    gap: 4px;
    align-items: center;
}

.dash-oval {
    display: inline-block;
    padding: 2px 7px;
    border-radius: var(--radius-full, 9999px);
    font-size: 0.6rem;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.2s ease;
    letter-spacing: -0.01em;
}

.dash-oval.full {
    background: var(--color-optimal, #5A8F6E);
    color: #fff;
}

.dash-oval.partial {
    background: rgba(59, 130, 246, 0.12);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.25);
}

.dash-oval.empty {
    background: rgba(0, 0, 0, 0.04);
    color: var(--color-text-muted, #94a3b8);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.cell-status {
    min-width: 0;
}

/* ─── Empty State ──────────────────────────────────────── */
.dash-empty-state {
    text-align: center;
    padding: var(--space-3xl) var(--space-lg);
    background: var(--color-bg-elevated);
    border: 1.5px dashed var(--color-border);
    border-radius: var(--radius-lg);
}

.dash-empty-icon {
    font-size: 3rem;
    margin-bottom: var(--space-md);
    opacity: 0.5;
}

.dash-empty-state p {
    color: var(--color-text-muted);
    margin-bottom: var(--space-lg);
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

/* ─── Loading ──────────────────────────────────────────── */
.dash-loading {
    text-align: center;
    padding: var(--space-3xl);
    color: var(--color-text-muted);
    font-size: 1rem;
}

/* ─── Stat Card Icon ───────────────────────────────────── */
.stat-card .stat-icon {
    font-size: 1.5rem;
    margin-bottom: var(--space-xs);
}

/* Patient name column bold */
.cell-patient {
    font-weight: 600;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ─── Language Column ─────────────────────────────────── */
.cell-lang {
    display: flex;
    align-items: center;
}

.dash-lang-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    background: var(--bg-muted, #e2e8de);
    border-radius: var(--radius-xl, 999px);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary, #475569);
    white-space: nowrap;
    cursor: default;
}

.dash-lang-badge-flag {
    font-size: 0.9rem;
    line-height: 1;
}

/* ─── File Indicator Badges ───────────────────────────── */
.dash-file-badges {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

.dash-file-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    padding: 1px 5px;
    border-radius: var(--radius-sm);
    background: rgba(44, 95, 75, 0.08);
    cursor: default;
    transition: background var(--transition-fast);
    line-height: 1.3;
}

.dash-file-badge:hover {
    background: rgba(44, 95, 75, 0.15);
}

.dash-file-stored {
    font-size: 0.6875rem;
    gap: 2px;
}

/* ─── Sortable Column Headers ─────────────────────────── */
.dash-sort-header {
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color var(--transition-fast);
    border-radius: var(--radius-sm);
    padding: 2px 4px;
    margin: -2px -4px;
}

.dash-sort-header:hover {
    color: var(--color-text);
    background: rgba(30, 41, 59, 0.06);
}

.dash-sort-header.active {
    color: var(--color-primary);
}

.dash-sort-arrow {
    display: inline-block;
    font-size: 0.875rem;
    font-weight: 700;
    line-height: 1;
    color: #94a3b8;
    transition: color var(--transition-fast);
}

.dash-sort-header.active .dash-sort-arrow {
    color: var(--color-primary);
}

.dash-sort-header:hover .dash-sort-arrow {
    color: #475569;
}

/* ─── View + Delete Cells (now separate columns) ─────── */
.cell-view {
    display: flex;
    align-items: center;
}

.cell-delete {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* "Patient Report" header label above view column */
.cell-view-header {
    cursor: default !important;
    pointer-events: none;
}

/* Empty lang-column header — no pointer/hover */
.cell-no-header {
    cursor: default !important;
    pointer-events: none;
}

.dash-delete-btn,
.dash-view-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    opacity: 0.35;
    transition: opacity var(--transition-fast), background var(--transition-fast);
}

.dashboard-table-row:hover .dash-delete-btn,
.dashboard-table-row:hover .dash-view-btn:not(.disabled) {
    opacity: 0.6;
}

.dash-delete-btn:hover {
    opacity: 1 !important;
    background: rgba(192, 84, 79, 0.1);
}

.dash-view-btn:not(.disabled):hover {
    opacity: 1 !important;
    background: rgba(44, 95, 75, 0.1);
}

.dash-view-btn.disabled {
    opacity: 0.2;
    cursor: default;
    pointer-events: none;
}

/* ─── Patient View Oval Button ────────────────────────── */
.dash-view-oval {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 9px;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    border: 1px solid;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    white-space: nowrap;
    line-height: 1;
    background: none;
}

.dash-view-oval.available {
    background: rgba(44, 95, 75, 0.08);
    color: var(--color-primary);
    border-color: rgba(44, 95, 75, 0.3);
}

.dashboard-table-row:hover .dash-view-oval.available {
    background: rgba(44, 95, 75, 0.14);
}

.dash-view-oval.available:hover {
    background: var(--color-primary) !important;
    color: #fff !important;
    border-color: var(--color-primary) !important;
}

.dash-view-oval.unavailable {
    background: rgba(0, 0, 0, 0.03);
    color: var(--color-text-muted);
    border-color: rgba(0, 0, 0, 0.08);
    cursor: default;
    pointer-events: none;
    opacity: 0.5;
}

/* ─── Danger Button (for delete confirmation) ─────────── */
.btn-danger {
    background: #C0544F;
    color: #fff;
    border: 1px solid #C0544F;
    padding: 8px 20px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.btn-danger:hover {
    background: #a8403b;
    border-color: #a8403b;
}

@media (max-width: 768px) {
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    /* On mobile: patient + lang + status + view + delete (hide date columns) */
    .dashboard-table-header,
    .dashboard-table-row {
        grid-template-columns: 1.4fr 0.4fr 1.2fr 90px 28px;
    }

    .cell-date,
    .dashboard-table-header .cell-date {
        display: none;
    }

    /* Always show delete button on mobile (no hover) */
    .dash-delete-btn {
        opacity: 0.5;
    }
}
