/* ========================================
   Supervisor Restart Web - Mobile-First Responsive CSS
   ======================================== */

:root {
    --color-bg: #f0f2f5;
    --color-card: #ffffff;
    --color-primary: #4a6cf7;
    --color-primary-dark: #3b5bdb;
    --color-success: #22c55e;
    --color-success-dark: #16a34a;
    --color-warning: #f59e0b;
    --color-warning-dark: #d97706;
    --color-danger: #ef4444;
    --color-danger-dark: #dc2626;
    --color-text: #1f2937;
    --color-text-secondary: #6b7280;
    --color-border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --header-height: 56px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 1.5;
}

.app {
    max-width: 680px;
    margin: 0 auto;
    padding: var(--space-md);
    min-height: 100vh;
}

/* ========================================
   Header
   ======================================== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    margin-bottom: var(--space-md);
    padding: 0 var(--space-sm);
    position: sticky;
    top: 0;
    background: var(--color-bg);
    z-index: 50;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--color-card);
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
    font-size: 1.1rem;
    text-decoration: none;
}

.icon-btn:active {
    transform: scale(0.92);
    background: var(--color-border);
}

/* ========================================
   Cards
   ======================================== */
.card {
    background: var(--color-card);
    border-radius: var(--radius);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-sm);
}

/* ========================================
   Status Card
   ======================================== */
.status-card {
    background: var(--color-card);
    border-radius: var(--radius);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    box-shadow: var(--shadow);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.status-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--color-text-secondary);
    transition: background 0.3s;
}

.status-card.idle::before     { background: #9ca3af; }
.status-card.stopping::before { background: var(--color-warning); }
.status-card.stopped::before  { background: #f97316; }
.status-card.clearing::before { background: #ec4899; }
.status-card.starting::before { background: #06b6d4; }
.status-card.started::before  { background: var(--color-success); }
.status-card.pipeline::before { background: var(--color-primary); }
.status-card.error::before    { background: var(--color-danger); }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    border-radius: 999px;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
    background: #f3f4f6;
    color: var(--color-text-secondary);
}

.status-card.started .status-badge { background: #dcfce7; color: #166534; }
.status-card.stopped .status-badge { background: #ffedd5; color: #9a3412; }
.status-card.error .status-badge   { background: #fee2e2; color: #991b1b; }
.status-card.pipeline .status-badge { background: #e0e7ff; color: #3730a3; }
.status-card.stopping .status-badge { background: #fef3c7; color: #92400e; }
.status-card.starting .status-badge { background: #cffafe; color: #155e75; }

.status-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: var(--space-sm);
}

.status-message {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-xs);
    word-break: break-word;
}

.status-detail {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    opacity: 0.8;
    margin-bottom: var(--space-sm);
}

.status-time {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    opacity: 0.6;
}

.operation-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    background: #fef3c7;
    color: #92400e;
    font-size: 0.8125rem;
    font-weight: 500;
}

.operation-banner.hidden {
    display: none;
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px var(--space-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
    min-height: 48px;
    width: 100%;
}

.btn:active:not(:disabled) {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}
.btn-primary:active:not(:disabled) {
    background: var(--color-primary-dark);
}

.btn-success {
    background: var(--color-success);
    color: #fff;
}
.btn-success:active:not(:disabled) {
    background: var(--color-success-dark);
}

.btn-warning {
    background: var(--color-warning);
    color: #fff;
}
.btn-warning:active:not(:disabled) {
    background: var(--color-warning-dark);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}
.btn-danger:active:not(:disabled) {
    background: var(--color-danger-dark);
}

.btn-secondary {
    background: #e5e7eb;
    color: var(--color-text);
}
.btn-secondary:active:not(:disabled) {
    background: #d1d5db;
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
    box-shadow: inset 0 0 0 1px var(--color-border);
}

.btn-sm {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    min-height: 36px;
}

/* ========================================
   Action Grid
   ======================================== */
.action-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.action-grid .btn {
    flex-direction: column;
    padding: var(--space-md) var(--space-sm);
    font-size: 0.875rem;
    gap: var(--space-xs);
}

.action-grid .btn .icon {
    font-size: 1.5rem;
}

.pipeline-section {
    margin-bottom: var(--space-md);
}

.pipeline-section .btn {
    padding: var(--space-lg) var(--space-md);
    font-size: 1.05rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.pipeline-section .btn .icon {
    font-size: 1.5rem;
}

/* ========================================
   Log Panel
   ======================================== */
.log-panel {
    background: var(--color-card);
    border-radius: var(--radius);
    padding: var(--space-md);
    box-shadow: var(--shadow);
}

.log-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
}

.log-panel-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-text);
}

#log-output {
    background: #111827;
    color: #e5e7eb;
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    font-family: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
    font-size: 0.8125rem;
    line-height: 1.6;
    max-height: 320px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   Modal (Bottom Sheet on mobile)
   ======================================== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal-overlay.active {
    display: flex;
}

.modal-sheet {
    background: var(--color-card);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: var(--space-lg);
    width: 100%;
    max-width: 680px;
    animation: slideUp 0.25s ease-out;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: var(--space-lg);
    text-align: center;
}

.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-xs);
}

.form-group input {
    width: 100%;
    padding: 12px var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: #fff;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.modal-error {
    color: var(--color-danger);
    font-size: 0.875rem;
    text-align: center;
    min-height: 24px;
    margin-bottom: var(--space-sm);
}

.modal-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

/* ========================================
   Settings Page
   ======================================== */
.settings-section {
    background: var(--color-card);
    border-radius: var(--radius);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    box-shadow: var(--shadow);
}

.settings-section-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: var(--space-xs);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.settings-desc {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-md);
}

.form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--color-border);
    gap: var(--space-md);
    flex-wrap: wrap;
}

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

.form-row label {
    font-size: 0.9375rem;
    font-weight: 500;
    flex: 1;
    min-width: 120px;
}

.form-row select,
.form-row input[type="time"],
.form-row input[type="number"] {
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    min-width: 140px;
    background: #fff;
}

.form-row select:focus,
.form-row input:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Switch */
.switch-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-weight: 500;
}

.switch-label input {
    display: none;
}

.switch-slider {
    position: relative;
    width: 48px;
    height: 28px;
    background: #d1d5db;
    border-radius: 14px;
    transition: background 0.3s;
    flex-shrink: 0;
}

.switch-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.switch-label input:checked + .switch-slider {
    background: var(--color-success);
}

.switch-label input:checked + .switch-slider::after {
    transform: translateX(20px);
}

.preview-box {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 500;
    text-align: center;
    margin-top: var(--space-sm);
}

.preview-box.active {
    background: #dcfce7;
    color: #166534;
}

.preview-box.disabled {
    background: #fee2e2;
    color: #991b1b;
}

.save-actions {
    position: sticky;
    bottom: var(--space-md);
    background: var(--color-bg);
    padding: var(--space-sm) 0;
    margin-top: var(--space-lg);
}

.save-message {
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
    min-height: 24px;
    margin-top: var(--space-sm);
}

.save-message.success { color: var(--color-success); }
.save-message.error   { color: var(--color-danger); }

/* ========================================
   Login Page
   ======================================== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-md);
}

.login-card {
    background: var(--color-card);
    border-radius: var(--radius);
    padding: var(--space-xl);
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: var(--space-lg);
    color: var(--color-text);
}

.login-card .form-group {
    text-align: left;
}

.login-card .btn {
    margin-top: var(--space-sm);
}

/* ========================================
   Responsive adjustments (desktop)
   ======================================== */
@media (min-width: 640px) {
    .app {
        padding: var(--space-xl);
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .status-value {
        font-size: 1.75rem;
    }

    .action-grid .btn {
        flex-direction: row;
        font-size: 1rem;
        padding: 14px var(--space-md);
    }

    .modal-sheet {
        border-radius: var(--radius);
        margin: auto;
        animation: fadeIn 0.2s ease-out;
    }

    @keyframes fadeIn {
        from { opacity: 0; transform: scale(0.96); }
        to { opacity: 1; transform: scale(1); }
    }

    .modal-overlay {
        align-items: center;
    }
}

/* ========================================
   Utilities
   ======================================== */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-md { margin-top: var(--space-md); }
.mb-md { margin-bottom: var(--space-md); }
