/**
 * Screen Recorder
 */

/* ========================================
   App Page Layout
   ======================================== */

.app-page {
    padding: var(--space-4);
    padding-top: calc(var(--header-height) + var(--space-4));
    min-height: calc(100vh - var(--header-height));
}

/* ========================================
   App Container Centering (REQUIRED)
   ======================================== */

.screen-recorder-container {
    width: 100%;
    max-width: var(--app-container-max);
    margin: 0 auto;
}

/* ========================================
   Tool
   ======================================== */

.screen-recorder-tool {
    display: grid;
    gap: var(--space-6);
}

.screen-recorder-tool:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-lg);
}

.screen-recorder-note {
    margin: 0;
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
}

.screen-recorder-panel {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-lg);
    display: grid;
    gap: var(--space-5);
}

.screen-recorder-panel-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
}

.screen-recorder-panel-header h2 {
    margin: 0;
    font-size: var(--font-size-lg);
}

.screen-recorder-status {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    white-space: nowrap;
}

.screen-recorder-status.is-recording {
    border-color: color-mix(in srgb, var(--color-error) 55%, var(--color-border));
    background: color-mix(in srgb, var(--color-error) 12%, transparent);
}

.screen-recorder-status.is-paused {
    border-color: color-mix(in srgb, var(--color-warning) 55%, var(--color-border));
    background: color-mix(in srgb, var(--color-warning) 12%, transparent);
}

.screen-recorder-status.is-error {
    border-color: color-mix(in srgb, var(--color-error) 55%, var(--color-border));
    background: color-mix(in srgb, var(--color-error) 12%, transparent);
}

/* The grid display above would override the UA [hidden] rule, so the
   hidden state must win explicitly (scoped, per codebase convention). */

.screen-recorder-state {
    display: grid;
    gap: var(--space-5);
}

.screen-recorder-state[hidden] {
    display: none;
}

.screen-recorder-enable-card {
    display: grid;
    gap: var(--space-3);
    justify-items: center;
    text-align: center;
    padding: var(--space-6);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-bg);
}

.screen-recorder-enable-text {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    max-width: var(--help-panel-max-width);
}

.screen-recorder-state-error {
    display: grid;
    gap: var(--space-4);
    justify-items: start;
    padding: var(--space-5);
    border-radius: var(--radius-lg);
    border: 1px solid color-mix(in srgb, var(--color-error) 45%, var(--color-border));
    /* 4% (not 8%): keeps the tint subtle while letting --color-error-text
       clear WCAG 2.1 AA 4.5:1 in light theme and dark theme. */
    background: color-mix(in srgb, var(--color-error) 4%, transparent);
}

.screen-recorder-error-message {
    margin: 0;
    color: var(--color-error-text);
    font-weight: 700;
    line-height: var(--line-height-normal);
}

/* ========================================
   Capture options
   ======================================== */

.screen-recorder-field {
    display: grid;
    gap: var(--space-2);
    width: 100%;
    max-width: var(--help-panel-max-width);
}

.screen-recorder-field[hidden] {
    display: none;
}

.screen-recorder-label {
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-text);
}

.screen-recorder-select {
    width: 100%;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: var(--font-size-base);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.screen-recorder-select:hover {
    border-color: var(--color-border-dark);
}

.screen-recorder-select:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: var(--color-primary);
}

.screen-recorder-select[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Webcam PiP toggle tile (compact variant of the export-panel toggle —
   boxed so the option group reads as one control). */

.screen-recorder-toggle {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-bg-alt);
    padding: var(--space-4);
    display: grid;
    gap: var(--space-2);
    width: 100%;
    max-width: var(--help-panel-max-width);
}

.screen-recorder-checkbox {
    display: inline-flex;
    gap: var(--space-3);
    align-items: center;
    font-weight: 700;
    color: var(--color-text);
    text-align: left;
}

.screen-recorder-checkbox input {
    flex: 0 0 auto;
    width: calc(var(--space-4) + var(--space-1));
    height: calc(var(--space-4) + var(--space-1));
    accent-color: var(--color-primary);
}

.screen-recorder-checkbox input:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.screen-recorder-cancel-notice {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
}

.screen-recorder-cancel-notice[hidden] {
    display: none;
}

/* ========================================
   Live preview
   ======================================== */

.screen-recorder-video-wrap {
    position: relative;
    width: 100%;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.screen-recorder-video {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    background: var(--color-bg-alt);
}

/* PiP bubble: bottom-right overlay of the preview (the recorded file
   gets the same bubble composited on the canvas side). */

.screen-recorder-pip {
    position: absolute;
    right: var(--space-3);
    bottom: var(--space-3);
    width: min(24%, 160px);
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border: 2px solid var(--color-bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    background: var(--color-bg-alt);
}

.screen-recorder-pip[hidden] {
    display: none;
}

/* Status row: indicator + timer */

.screen-recorder-status-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.screen-recorder-indicator {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-text);
}

.screen-recorder-indicator-dot {
    flex: 0 0 auto;
    width: var(--space-3);
    height: var(--space-3);
    border-radius: var(--radius-full);
    background: var(--color-border-dark);
}

/* Pulse applies to the DOT only — the text always carries the state. */

.screen-recorder-indicator.is-recording .screen-recorder-indicator-dot {
    background: var(--color-error);
    animation: screen-recorder-pulse 1.1s ease-in-out infinite;
}

.screen-recorder-indicator.is-paused .screen-recorder-indicator-dot {
    background: var(--color-warning);
}

@keyframes screen-recorder-pulse {
    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.35);
        opacity: 0.55;
    }
}

.screen-recorder-timer {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-bg-alt);
}

.screen-recorder-timer-label {
    font-weight: 700;
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.screen-recorder-timer-value {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--font-size-base);
    font-weight: 700;
    color: var(--color-text);
}

/* ========================================
   Controls
   ======================================== */

.screen-recorder-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
}

.screen-recorder-actions .btn[hidden] {
    display: none;
}

.screen-recorder-actions .btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

.screen-recorder-actions-inline {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    justify-content: flex-end;
}

.screen-recorder-actions-inline .btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ========================================
   Clips
   ======================================== */

.screen-recorder-clips {
    display: grid;
    gap: var(--space-4);
}

.screen-recorder-clips:empty {
    display: none;
}

.screen-recorder-clip {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
    display: grid;
    gap: var(--space-3);
}

.screen-recorder-clip:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.screen-recorder-clip-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
}

.screen-recorder-clip-header h3 {
    margin: 0;
    font-size: var(--font-size-base);
    font-weight: 700;
    min-width: 0;
}

.screen-recorder-clip-duration {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.screen-recorder-clip video {
    width: 100%;
    display: block;
    border-radius: var(--radius-md);
    background: var(--color-bg-alt);
}

.screen-recorder-clip-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
}

.screen-recorder-clip-actions .btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Armed (first-click) state of the two-step confirm buttons. The label
   text changes too — this styling is a secondary cue, never the only one. */

/* The armed background stays the neutral secondary surface: a red-tinted
   background would drop --color-error-text below WCAG 2.1 AA 4.5:1 in the
   light theme (3.95:1) and on hover in the dark theme. The armed state is
   carried by the border + error text + the button's label change, so color
   is never the only cue. */
.btn.is-confirm-armed {
    border-color: color-mix(in srgb, var(--color-error) 55%, var(--color-border));
    background: var(--color-bg-alt);
    color: var(--color-error-text);
}

.btn.is-confirm-armed:hover {
    border-color: var(--color-error);
}

/* ========================================
   Trim & export
   ======================================== */

.screen-recorder-trim {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-bg-alt);
}

.screen-recorder-trim[hidden] {
    display: none;
}

.screen-recorder-trim-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}

.screen-recorder-time-input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: var(--font-size-base);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.screen-recorder-time-input:hover {
    border-color: var(--color-border-dark);
}

.screen-recorder-time-input:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: var(--color-primary);
}

.screen-recorder-time-input[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

.screen-recorder-trim-error {
    margin: 0;
    color: var(--color-error-text);
    font-size: var(--font-size-sm);
    font-weight: 700;
    line-height: var(--line-height-normal);
}

.screen-recorder-trim-error[hidden] {
    display: none;
}

.screen-recorder-export-btn.is-busy {
    color: var(--color-text-muted);
}

.screen-recorder-export-status {
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: 700;
    line-height: var(--line-height-normal);
}

.screen-recorder-export-status[hidden] {
    display: none;
}

.screen-recorder-export-status.is-busy {
    color: var(--color-text);
}

.screen-recorder-export-status.is-success {
    color: var(--color-success-text);
}

.screen-recorder-export-status.is-error {
    color: var(--color-error-text);
}

.screen-recorder-export-status.is-busy::before {
    content: "";
    flex: 0 0 auto;
    width: calc(var(--space-3) + var(--space-1));
    height: calc(var(--space-3) + var(--space-1));
    border-radius: var(--radius-full);
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    animation: screen-recorder-spin 1.5s linear infinite;
}

@keyframes screen-recorder-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Muted empty state */

.screen-recorder-muted {
    margin: 0;
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    border: 1px dashed var(--color-border);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    background: var(--color-bg);
    display: grid;
    gap: var(--space-2);
}

.screen-recorder-muted[hidden] {
    display: none;
}

/* No opacity dimming: var(--color-text-muted) at 100% is already the weakest
   token that meets WCAG 2.1 AA (4.5:1) on var(--color-bg) in both themes. */

.screen-recorder-muted-hint {
    font-size: var(--font-size-sm);
}

/* ========================================
   Help Button (per-app pattern — not in main.css)
   ======================================== */

.nav-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.btn-icon {
    width: calc(var(--space-10) + var(--space-1));
    height: calc(var(--space-10) + var(--space-1));
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    color: var(--color-text-muted);
    font-size: var(--font-size-lg);
    font-weight: 600;
    cursor: pointer;
    transition:
        background var(--transition-fast),
        border-color var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast);
}

.btn-icon:hover {
    background: var(--color-border);
    border-color: var(--color-border-dark);
    color: var(--color-text);
}

.btn-icon:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.btn-icon:active {
    transform: scale(0.98);
}

/* ========================================
   Reduced Motion
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .screen-recorder-indicator.is-recording .screen-recorder-indicator-dot {
        animation: none;
    }

    .screen-recorder-export-status.is-busy::before {
        animation: none;
    }

    .btn-icon,
    .btn,
    .screen-recorder-select,
    .screen-recorder-time-input {
        transition: none;
    }

    .btn-icon:active {
        transform: none;
    }
}

/* ========================================
   Mobile
   ======================================== */

@media (max-width: 640px) {
    .screen-recorder-panel {
        padding: var(--space-5);
    }

    .screen-recorder-panel-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .screen-recorder-actions .btn,
    .screen-recorder-clip-actions .btn {
        width: 100%;
    }

    .screen-recorder-trim-row {
        grid-template-columns: 1fr;
    }

    .screen-recorder-status-row {
        flex-direction: column;
        align-items: flex-start;
    }
}

.help-body h3 {
    margin-top: var(--space-4);
}

.help-steps,
.help-features {
    padding-inline-start: var(--space-5);
}
