/* === Page Header === */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-6);
}

.page-header-content h1 {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
    margin-bottom: var(--space-1);
}

.page-header-content p {
    font-size: var(--font-size-sm);
    color: var(--color-muted);
    margin-bottom: 0;
}

.page-header-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

/* === Breadcrumbs === */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    font-size: var(--font-size-sm);
}

.breadcrumbs-item {
    color: var(--color-muted);
    text-decoration: none;
}

.breadcrumbs-item:hover {
    color: var(--color-primary);
}

.breadcrumbs-separator {
    color: var(--color-border);
}

.breadcrumbs-current {
    color: var(--color-text);
    font-weight: var(--font-weight-medium);
}

/* === Section Header === */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
    margin-top: var(--space-6);
}

.section-header h2 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
}

/* === Dashboard Grid === */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.dashboard-grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.dashboard-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.dashboard-grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* === Stat Card === */
.stat-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    transition: box-shadow var(--transition-fast);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
}

.stat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stat-card-label {
    font-size: var(--font-size-sm);
    color: var(--color-muted);
    font-weight: var(--font-weight-medium);
}

.stat-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card-icon svg {
    width: 20px;
    height: 20px;
}

.stat-card-icon.primary {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.stat-card-icon.success {
    background: var(--color-success-light);
    color: var(--color-success);
}

.stat-card-icon.warning {
    background: var(--color-warning-light);
    color: var(--color-warning);
}

.stat-card-icon.danger {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

.stat-card-icon.info {
    background: var(--color-info-light);
    color: var(--color-info);
}

.stat-card-value {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
    line-height: var(--line-height-tight);
}

.stat-card-value.text-success { color: var(--color-success); }
.stat-card-value.text-danger { color: var(--color-danger); }
.stat-card-value.text-warning { color: var(--color-warning); }
.stat-card-value.text-primary { color: var(--color-primary); }

.stat-card-footer {
    margin-top: var(--space-1);
}

.stat-card-footer a {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-primary);
}

/* === Dashboard Section === */
.dashboard-section {
    margin-bottom: var(--space-6);
}

.dashboard-section-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-2);
    border-bottom: 2px solid var(--color-border-light);
}

/* === Detail Card === */
.detail-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    padding: var(--space-5);
    margin-bottom: var(--space-5);
}

.detail-row {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-border-light);
}

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

.detail-row-label {
    min-width: 140px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-muted);
    flex-shrink: 0;
}

.detail-row-value {
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

/* === Schedule Grid === */
.schedule-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

.schedule-item {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--color-border-light);
    padding: var(--space-3) var(--space-4);
    display: flex;
    gap: var(--space-4);
    align-items: center;
    min-width: 200px;
}

.schedule-day {
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.schedule-time {
    font-size: var(--font-size-sm);
    color: var(--color-primary);
    font-weight: var(--font-weight-medium);
}

/* === Action Links === */
.action-links {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-top: var(--space-5);
}

/* === Attendance Summary === */
.attendance-summary {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
    padding: var(--space-4);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    margin-bottom: var(--space-5);
}

.summary-item {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.summary-item strong {
    color: var(--color-text);
}

/* === Card Actions === */
.card-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border-light);
}

/* === KPI Card Links (whole card is one anchor) === */
a.stat-card-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

a.stat-card-link:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary-light);
    transform: translateY(-2px);
}

a.stat-card-link:active {
    transform: translateY(0);
}

a.stat-card-link:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

a.stat-card-link .stat-card-header,
a.stat-card-link .stat-card-value,
a.stat-card-link .stat-card-sub {
    color: inherit;
}

a.stat-card-link .stat-card-label {
    color: var(--color-muted);
}

@media (prefers-reduced-motion: reduce) {
    a.stat-card-link:hover {
        transform: none;
    }

    .stat-card {
        transition: none;
    }
}

/* Grid items default to min-width:auto, letting wide content (scrollable
   chart wrappers, tables) force tracks wider than the viewport. Constrain
   them; inner scroll containers then handle overflow locally. */
.dashboard-grid > * {
    min-width: 0;
}

/* KPI grid uses minmax(0, 1fr) tracks so long unbreakable values
   (large monetary figures) wrap inside cards instead of forcing the
   tracks wider than narrow viewports. */
.dashboard-grid-4.kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
.quick-actions {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* Flex-item min-width fix: wide dashboard tables must scroll inside
   .table-scroll instead of forcing .main-content (a flex item with the
   default min-width:auto) wider than the viewport on mobile. */
.main-content {
    min-width: 0;
}

.stat-card-sub {
    font-size: var(--font-size-xs);
    color: var(--color-muted);
}

/* === Section Heading Link === */
.dashboard-section-title .section-link,
.subsection-title .section-link {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-primary);
    margin-inline-start: var(--space-3);
}

.subsection-title {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin-bottom: var(--space-3);
    margin-top: var(--space-5);
}

.section-footer {
    margin-top: var(--space-3);
    font-size: var(--font-size-sm);
}

/* === Attention List === */
.attention-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.attention-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: 0;
}

/* === SVG Charts === */
.chart-legend {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-2);
    font-size: var(--font-size-xs);
    color: var(--color-muted);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: var(--radius-sm);
    display: inline-block;
}

.legend-swatch.primary { background: var(--color-primary); }
.legend-swatch.info { background: var(--color-info); }

.legend-swatch.secondary-line {
    width: 22px;
    height: 0;
    border-top: 3px solid var(--color-success);
    border-radius: 0;
}

.chart-svg {
    width: 100%;
    height: auto;
    display: block;
    font-family: inherit;
}

/* Wide 12-month charts scroll horizontally on narrow screens instead of
   shrinking labels into illegibility. The wrapper is keyboard-focusable
   with a visible focus indicator. */
.chart-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
}

.chart-scroll:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

@media (max-width: 640px) {
    .chart-scroll .chart-svg {
        min-width: 560px;
    }
}

.chart-gridline {
    stroke: var(--color-border-light);
    stroke-width: 1;
}

.chart-tick {
    font-size: 12px;
    fill: var(--color-muted);
}

.chart-label {
    font-size: 12px;
    fill: var(--color-text-secondary);
}

.chart-label-year {
    font-size: 10px;
    fill: var(--color-muted);
}

.chart-value {
    font-size: 12px;
    font-weight: var(--font-weight-semibold);
    fill: var(--color-text);
}

.chart-bar-primary { fill: var(--color-primary); }
.chart-bar-info { fill: var(--color-info); }

.chart-line-secondary {
    fill: none;
    stroke: var(--color-success);
    stroke-width: 2.5;
}

.chart-dot-secondary { fill: var(--color-success); }

.chart-bar-empty {
    fill: transparent;
    stroke: var(--color-border);
    stroke-dasharray: 5 4;
    stroke-width: 1.5;
}

.chart-empty-mark {
    font-size: 16px;
    fill: var(--color-muted);
}

.chart-sub {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-normal);
    color: var(--color-muted);
}

/* === Capacity Meter === */
.capacity-meter {
    display: inline-block;
    width: 72px;
    height: 8px;
    border-radius: var(--radius-sm);
    background: var(--color-border-light);
    overflow: hidden;
    vertical-align: middle;
    margin-inline-end: var(--space-1);
}

.capacity-fill {
    display: block;
    height: 100%;
    background: var(--color-primary);
    border-radius: var(--radius-sm);
}

/* === Chart Data Table Toggle === */
.chart-data {
    margin-top: var(--space-3);
    font-size: var(--font-size-sm);
}

.chart-data summary {
    cursor: pointer;
    color: var(--color-primary);
    font-weight: var(--font-weight-medium);
}

/* === Responsive === */
@media (max-width: 1024px) {
    .dashboard-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .page-header-actions {
        width: 100%;
    }

    .page-header-actions .btn {
        flex: 1;
    }

    .dashboard-grid,
    .dashboard-grid-2,
    .dashboard-grid-3,
    .dashboard-grid-4 {
        grid-template-columns: 1fr;
    }

    /* KPI cards stay two-up on phones: compact values remain readable and
       tap targets stay large; other grids collapse to one column. */
    .dashboard-grid-4.kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chart-svg .tick-alt {
        display: none;
    }

    .detail-row {
        flex-direction: column;
        gap: var(--space-1);
    }

    .detail-row-label {
        min-width: auto;
    }

    .attendance-summary {
        flex-direction: column;
        gap: var(--space-2);
    }

    .schedule-grid {
        flex-direction: column;
    }

    .schedule-item {
        min-width: auto;
        width: 100%;
    }

    .attention-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .quick-actions .btn {
        flex: 1 1 auto;
    }
}

@media (max-width: 420px) {
    .kpi-grid .stat-card-value {
        font-size: var(--font-size-lg);
        overflow-wrap: anywhere;
    }

    .kpi-grid .stat-card {
        padding: var(--space-4);
    }
}
