/* OpenSpec Orchestrator Web Monitor Styles */
/* Mobile-first responsive design */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0a0;
    --accent-blue: #4cc9f0;
    --accent-green: #06d6a0;
    --accent-yellow: #ffd166;
    --accent-red: #ef476f;
    --border-color: #2a3a5e;

    /* Spacing scale */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;

    /* Touch target minimum */
    --touch-target: 44px;

    /* Safe area insets for notched devices */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh;
    touch-action: pan-y;
    overscroll-behavior-y: contain;
    text-wrap: pretty;
}

/* Container - Mobile first */
.container {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--space-md);
    padding-top: calc(var(--space-md) + var(--safe-area-top));
    padding-bottom: calc(var(--space-md) + var(--safe-area-bottom));
    padding-left: calc(var(--space-md) + var(--safe-area-left));
    padding-right: calc(var(--space-md) + var(--safe-area-right));
    display: flex;
    flex-direction: column;
}

/* Header - Mobile */
header {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    text-wrap: balance;
}

/* Connection Status - Mobile sticky */
.connection-status {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.875rem;
    min-height: var(--touch-target);
    padding: var(--space-sm) var(--space-md);
    background-color: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--accent-yellow);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

.connection-status.connected .status-dot {
    background-color: var(--accent-green);
    animation: none;
}

.connection-status.disconnected .status-dot {
    background-color: var(--accent-red);
    animation: none;
}

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

/* Overall Progress Section */
.overall-progress {
    margin-bottom: var(--space-md);
    padding: var(--space-lg);
    background-color: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.overall-progress-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
    text-wrap: balance;
}

.overall-progress-bar-container {
    width: 100%;
}

.overall-progress-bar {
    height: 20px;
    background-color: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: var(--space-sm);
}

.overall-progress-fill {
    height: 100%;
    background-color: var(--accent-blue);
    border-radius: 10px;
    transition: width 0.2s ease-out;
}

.overall-progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Toast Container */
.toast-container {
    position: fixed;
    top: calc(var(--space-md) + var(--safe-area-top));
    left: var(--space-md);
    right: var(--space-md);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
}

.toast {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: var(--space-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.2s ease-out;
    pointer-events: auto;
}

.toast.success {
    border-left: 4px solid var(--accent-green);
}

.toast.error {
    border-left: 4px solid var(--accent-red);
}

.toast.warning {
    border-left: 4px solid var(--accent-yellow);
}

@keyframes slideIn {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(-100%);
        opacity: 0;
    }
}

/* Stats Bar - Mobile (2x2 grid) */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding: var(--space-md);
    background-color: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.stat {
    text-align: center;
    padding: var(--space-sm);
    min-height: var(--touch-target);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-blue);
    line-height: 1.2;
}

.stat-label {
    display: block;
    font-size: 0.6875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-top: var(--space-xs);
}

/* Control Bar - Mobile (stacked buttons) */
.control-bar {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding: var(--space-md);
    background-color: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    min-height: var(--touch-target);
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
    font-family: inherit;
}

.control-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.control-btn:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.control-btn:not(:disabled):active {
    transform: translateY(0);
}

.control-btn-primary {
    background-color: var(--accent-blue);
    color: var(--bg-primary);
}

.control-btn-warning {
    background-color: var(--accent-yellow);
    color: var(--bg-primary);
}

.control-btn-info {
    background-color: var(--accent-blue);
    color: var(--bg-primary);
}

.control-btn-danger {
    background-color: var(--accent-red);
    color: var(--text-primary);
}

.control-btn-success {
    background-color: var(--accent-green);
    color: var(--bg-primary);
}

.btn-icon {
    font-size: 1.125rem;
    line-height: 1;
}

.btn-text {
    line-height: 1;
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    color: var(--text-secondary);
    flex: 1;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: var(--space-md);
}

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

/* Empty State */
.empty-state {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-secondary);
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Changes List */
.changes-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* Change Card - Touch optimized */
.change-card {
    background-color: var(--bg-card);
    border-radius: 8px;
    padding: var(--space-md);
    border: 1px solid var(--border-color);
    transition: border-color 0.15s ease-out, transform 0.1s ease-out;
    touch-action: pan-y;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.change-card:active {
    border-color: var(--accent-blue);
    transform: scale(0.98);
}

.change-card.expanded {
    border-color: var(--accent-blue);
}

.change-card.swiping {
    transition: none;
}

/* Swipe indicator */
.change-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: var(--accent-blue);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.2s ease-out;
}

.change-card.expanded::before {
    transform: scaleX(1);
}

.change-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.change-id {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
    word-break: break-all;
}

.change-status-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    align-items: center;
}

.change-iteration {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.change-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.badge {
    font-size: 0.625rem;
    padding: var(--space-xs) var(--space-sm);
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 600;
    min-height: calc(var(--touch-target) / 2);
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
}

.status-icon {
    font-size: 0.875rem;
    line-height: 1;
}

.badge-status {
    background-color: var(--accent-yellow);
    color: var(--bg-primary);
}

/* TUI-aligned queue status colors */
.badge-status.not-queued {
    background-color: var(--text-secondary);
}

.badge-status.queued {
    background-color: var(--accent-yellow);
}

.badge-status.blocked {
    background-color: #808080; /* Gray - matches TUI Gray */
    color: var(--text-primary);
}

.badge-status.applying {
    background-color: #00ffff; /* Cyan - matches TUI Cyan */
    color: var(--bg-primary);
}

.badge-status.processing {
    background-color: var(--accent-blue);
}

.badge-status.completed {
    background-color: var(--accent-green);
}

.badge-status.accepting {
    background-color: #90ee90; /* Light Green - matches TUI LightGreen */
    color: var(--bg-primary);
}

.badge-status.archiving {
    background-color: #c77dff; /* Magenta */
}

.badge-status.archived {
    background-color: #4361ee; /* Blue */
}

.badge-status.merged {
    background-color: #87ceeb; /* Light Blue */
}

.badge-status.merge-wait {
    background-color: #dda0dd; /* Light Magenta */
}

.badge-status.resolving {
    background-color: #00ced1; /* Light Cyan */
}

.badge-status.error {
    background-color: var(--accent-red);
}

/* Progress Bar - Touch optimized */
.progress-container {
    margin-bottom: var(--space-sm);
}

.progress-bar {
    height: 12px;
    background-color: var(--bg-secondary);
    border-radius: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--accent-blue);
    border-radius: 6px;
    transition: width 0.2s ease-out;
}

.progress-fill.complete {
    background-color: var(--accent-green);
}

.progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: var(--space-sm);
    min-height: var(--touch-target);
    align-items: center;
}

/* Change Details - Collapsible on mobile */
.change-details {
    opacity: 0;
    transform: scaleY(0);
    transform-origin: top;
    overflow: hidden;
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

.change-card.expanded .change-details {
    opacity: 1;
    transform: scaleY(1);
}

/* Dependencies */
.change-dependencies {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.dependencies-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.dependencies-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.dependency-tag {
    font-size: 0.75rem;
    padding: var(--space-xs) var(--space-sm);
    background-color: var(--bg-secondary);
    border-radius: 4px;
    color: var(--text-secondary);
    font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
    min-height: calc(var(--touch-target) / 2);
    display: inline-flex;
    align-items: center;
}

/* Expand hint for mobile */
.expand-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: var(--space-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    gap: var(--space-xs);
}

.expand-hint-icon {
    transition: transform 0.2s ease-out;
}

.change-card.expanded .expand-hint-icon {
    transform: rotate(180deg);
}

/* Footer */
footer {
    margin-top: var(--space-lg);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================
   Tablet Breakpoint (768px+)
   ========================================== */
@media (min-width: 768px) {
    .container {
        max-width: 768px;
        margin: 0 auto;
        padding: var(--space-lg);
    }

    header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: var(--space-md);
    }

    header h1 {
        font-size: 1.5rem;
    }

    .connection-status {
        background-color: transparent;
        border: none;
        padding: var(--space-sm);
    }

    .stats-bar {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--space-md);
        padding: var(--space-lg);
    }

    .stat-value {
        font-size: 2rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    .control-bar {
        flex-direction: row;
        flex-wrap: wrap;
        gap: var(--space-md);
        padding: var(--space-lg);
    }

    .control-btn {
        flex: 1;
        min-width: 120px;
    }

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

    .change-card:hover {
        border-color: var(--accent-blue);
    }

    .change-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }

    .change-id {
        font-size: 1rem;
    }

    .progress-bar {
        height: 8px;
    }

    .progress-text {
        font-size: 0.75rem;
        min-height: auto;
    }

    .expand-hint {
        display: none;
    }

    .change-details {
        opacity: 1;
        transform: scaleY(1);
    }

    .toast-container {
        left: auto;
        right: var(--space-lg);
        max-width: 400px;
    }
}

/* ==========================================
   Desktop Breakpoint (1024px+)
   ========================================== */
@media (min-width: 1024px) {
    .container {
        max-width: 1200px;
        padding: var(--space-xl);
    }

    header {
        margin-bottom: var(--space-lg);
        padding-bottom: var(--space-lg);
    }

    .stats-bar {
        margin-bottom: var(--space-lg);
    }

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

    .stat-value {
        font-size: 2.5rem;
    }

    .changes-list {
        gap: var(--space-md);
    }

    footer {
        margin-top: var(--space-xl);
    }
}

/* ==========================================
   Landscape orientation adjustments
   ========================================== */
@media (orientation: landscape) and (max-height: 500px) {
    .container {
        padding-top: var(--space-sm);
        padding-bottom: var(--space-sm);
    }

    header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        margin-bottom: var(--space-sm);
        padding-bottom: var(--space-sm);
    }

    header h1 {
        font-size: 1rem;
    }

    .stats-bar {
        grid-template-columns: repeat(4, 1fr);
        padding: var(--space-sm);
        margin-bottom: var(--space-sm);
        gap: var(--space-sm);
    }

    .stat {
        padding: var(--space-xs);
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .stat-label {
        font-size: 0.625rem;
    }

    .change-card {
        padding: var(--space-sm);
    }

    .changes-list {
        gap: var(--space-sm);
    }

    footer {
        margin-top: var(--space-sm);
        padding-top: var(--space-sm);
    }
}

/* ==========================================
   Reduced motion preference
   ========================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .spinner {
        animation: none;
        border-top-color: var(--accent-blue);
    }
}

/* ==========================================
   High contrast mode
   ========================================== */
@media (prefers-contrast: high) {
    :root {
        --border-color: #4a5a7e;
    }

    .badge {
        border: 1px solid currentColor;
    }

    .change-card {
        border-width: 2px;
    }
}

/* ==========================================
   Dark mode (default, but explicit)
   ========================================== */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}

/* ==========================================
   Pull-to-refresh indicator
   ========================================== */
.pull-to-refresh-indicator {
    position: fixed;
    top: calc(var(--safe-area-top) + var(--space-sm));
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    padding: var(--space-sm) var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease-out;
    z-index: 1001;
    pointer-events: none;
}

.pull-to-refresh-indicator.visible {
    transform: translateX(-50%) translateY(0);
}

.pull-to-refresh-indicator.refreshing .ptr-icon {
    animation: spin 1s linear infinite;
}

.ptr-icon {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    transition: transform 0.15s ease-out;
}

.ptr-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Hide pull-to-refresh on tablet and desktop */
@media (min-width: 768px) {
    .pull-to-refresh-indicator {
        display: none;
    }
}

/* ===== Tabs ===== */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--bg-secondary);
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
    bottom: -2px;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: block;
}

/* ===== Worktrees List ===== */
.worktrees-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.worktree-card {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--bg-tertiary);
    transition: all 0.2s ease;
}

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

.worktree-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.worktree-branch {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.worktree-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.worktree-badge.main {
    background: var(--success-bg);
    color: var(--success);
}

.worktree-badge.ahead {
    background: var(--warning-bg);
    color: var(--warning);
}

.worktree-badge.conflict {
    background: var(--error-bg);
    color: var(--error);
}

.worktree-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.worktree-actions {
    display: flex;
    gap: 0.5rem;
}

.worktree-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.worktree-btn.merge {
    background: var(--success-bg);
    color: var(--success);
}

.worktree-btn.merge:hover:not(:disabled) {
    background: var(--success);
    color: white;
}

.worktree-btn.delete {
    background: var(--error-bg);
    color: var(--error);
}

.worktree-btn.delete:hover:not(:disabled) {
    background: var(--error);
    color: white;
}

.worktree-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Confirmation dialog */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.dialog {
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 1.5rem;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.dialog-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.dialog-message {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

.dialog-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.dialog-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
}

.dialog-btn.cancel {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.dialog-btn.confirm {
    background: var(--error);
    color: white;
}
