/* Responsive Styles */

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

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

    .col-span-4,
    .col-span-6,
    .col-span-8 {
        grid-column: span 6;
    }
}

@media (max-width: 768px) {
    :root {
        --font-size-4xl: 2rem;
        --font-size-3xl: 1.5rem;
        --font-size-2xl: 1.25rem;
    }

    /* Global guard: nothing should cause horizontal scroll on a phone. */
    html, body {
        overflow-x: hidden;
    }

    .header-content {
        padding: 0 var(--space-md);
    }

    .progress-container {
        display: none;
    }

    .page {
        padding: var(--space-lg);
    }

    .container {
        padding: var(--space-md);
    }

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

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .col-span-4,
    .col-span-6,
    .col-span-8,
    .col-span-12 {
        grid-column: span 1;
    }

    .status-cards-grid,
    .status-cards-grid.single-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 0 16px;
        max-width: 100%;
        box-sizing: border-box;
    }

    .status-cards-grid .status-card {
        padding: 14px 6px;
        min-height: 150px;
        aspect-ratio: auto;
    }

    .status-cards-grid .status-card-title {
        font-size: 0.62rem;
        letter-spacing: 0.01em;
        word-break: normal;
        white-space: normal;
        text-align: center;
    }

    .status-cards-grid .status-card-value {
        font-size: 1.35rem;
        margin: 4px 0;
    }

    .status-cards-grid .status-card-label {
        font-size: 0.55rem;
        line-height: 1.2;
        letter-spacing: 0;
        white-space: nowrap;
        text-align: center;
        max-width: 100%;
        padding: 0 2px;
    }

    .status-cards-grid .status-icon {
        font-size: 1.1rem;
        margin-bottom: 4px;
    }

    .status-cards-grid .status-card-content {
        gap: 2px;
    }

    /* The practice screen nests the card grid inside a padded .card, which makes
       those cards narrower than the real task screen and clipped the label.
       Trim that wrapper's padding on phones so practice matches the task view. */
    .card {
        padding: 16px;
    }

    /* Keep the task card within the viewport so its border doesn't get pushed
       off-screen (which showed as a stray vertical line down the left edge). */
    .task-container {
        max-width: 100%;
        box-sizing: border-box;
        padding: var(--space-md);
        min-height: 0;
    }

    /* Chart Interpretation: the legend moves BELOW the chart on phones (set in
       renderChart), so give the wrapper extra height for chart + legend and let
       it use the full width. Without this the bars are squashed into ~150px. */
    .chart-task-layout {
        gap: 12px;
    }

    .chart-wrapper {
        height: 360px;
        max-width: 100%;
        flex: 1 1 100%;
    }

    .chart-buttons {
        min-width: 0;
        width: 100%;
        max-width: 340px;
    }

    /* Dashboard status rows: force a centered, full-width single column on phones
       so the block can't be pushed to a screen edge by flex-wrap + centering. */
    .status-indicators {
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        width: 100%;
        max-width: 360px;
        margin: 0 auto;
    }

    .status-indicators .status-indicator {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .status-card {
        padding: 12px 6px;
        aspect-ratio: auto;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
    }

    .status-card-content {
        align-items: center;
        gap: 2px;
        width: 100%;
        padding: 0 4px;
    }

    .status-card-title {
        font-size: 0.7rem;
        line-height: 1.2;
        word-break: normal;
        white-space: normal;
        margin-bottom: 2px;
        text-align: center;
    }

    .status-card-value {
        font-size: 1.4rem;
        margin: 4px 0;
        line-height: 1;
        font-weight: 700;
    }

    .status-card-label {
        font-size: 0.65rem;
        display: block;
        opacity: 1;
        white-space: normal;
        line-height: 1.2;
        width: 100%;
        margin-top: 2px;
        text-align: center;
    }

    .status-icon {
        display: none;
    }

    .adaptive .status-icon {
        display: block;
        font-size: 1rem;
        margin-bottom: 4px;
        line-height: 1;
    }

    .adaptive .status-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 2px;
        padding-top: 10px;
        /* Slight top padding for icon */
    }

    .form-buttons {
        grid-template-columns: 1fr;
        /* Keep buttons stacked or make 2 cols if needed */
    }

    .form-buttons .btn {
        width: 100%;
    }

    .likert-scale {
        flex-direction: column;
    }

    /* Keep the number buttons as a single compact tappable row on phones
       (do NOT stack them vertically — that caused excessive scrolling on
       the most-used screen). Buttons shrink to share the viewport width. */
    .likert-row {
        gap: 5px;
    }

    .likert-option {
        padding: 10px 2px;
        min-height: 46px;
        gap: 0;
    }

    .likert-value {
        font-size: 1rem;
    }

    .likert-anchors {
        font-size: 0.65rem;
    }

    .plate-wrapper {
        max-width: 300px;
    }

    .number-input input {
        width: 120px;
        height: 50px;
        font-size: var(--font-size-2xl);
    }

    .settings-panel {
        width: 100%;
        right: -100%;
    }

    .task-actions {
        flex-direction: column;
    }

    .task-actions .btn {
        width: 100%;
    }

    .cvd-select-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .cvd-type-card {
        padding: 14px 10px;
    }

    /* Results-summary paired cards stack on phones (inline grid is 1fr 1fr) */
    .results-duo {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .app-header {
        height: 56px;
    }

    .main-content {
        padding-top: 56px;
    }

    .logo span {
        display: none;
    }

    .btn-large {
        padding: var(--space-md) var(--space-lg);
        font-size: var(--font-size-base);
    }

    .result-icon {
        width: 80px;
        height: 80px;
        font-size: 2.5rem;
    }

    .intro-icon {
        width: 70px;
        height: 70px;
        font-size: 2rem;
    }

    .plate-wrapper {
        max-width: 260px;
    }

    .plate-timer {
        top: var(--space-sm);
        right: var(--space-sm);
        padding: var(--space-xs) var(--space-sm);
        font-size: var(--font-size-base);
    }
}

/* Touch-friendly targets */
@media (pointer: coarse) {

    .btn,
    .status-card,
    .alert,
    .notification-item,
    .radio-option,
    .checkbox-option {
        min-height: 48px;
    }

    .sortable-item {
        min-height: 56px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print styles */
@media print {

    .app-header,
    .settings-panel,
    .settings-btn {
        display: none;
    }

    .main-content {
        padding-top: 0;
    }

    body {
        background: white;
        color: black;
    }
}