/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    min-height: 100vh;
}

a {
    color: #0ea5e9;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
}

button {
    cursor: pointer;
    font-family: inherit;
}

input,
select,
textarea,
button {
    font-size: inherit;
}

/* ===== Color Variables ===== */
:root {
    --color-header: #1a1a2e;
    --color-header-secondary: #16213e;
    --color-sidebar: #0f3460;
    --color-bg: #f5f5f5;
    --color-surface: #ffffff;
    --color-accent: #0ea5e9;
    --color-accent-hover: #0284c7;
    --color-text: #333333;
    --color-text-light: #6b7280;
    --color-text-inverse: #ffffff;
    --color-border: #e5e7eb;
    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    --color-warning: #f59e0b;
    --color-success: #22c55e;
    --color-gray: #6b7280;
    --color-log-bg: #1e1e1e;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 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: 8px;
    --radius-sm: 4px;
    --transition: 0.2s ease;
}

/* ===== Header ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 60px;
    background: var(--color-header);
    color: var(--color-text-inverse);
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-right {
    display: flex;
    align-items: center;
}

/* ===== Session Status Indicator ===== */
.session-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
    transition: background-color var(--transition);
}

.status-dot.connected {
    background-color: var(--color-success);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
}

.status-dot.disconnected {
    background-color: var(--color-danger);
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
}

.status-text {
    color: var(--color-text-light);
    font-size: 0.85rem;
}

/* ===== Navigation Tabs ===== */
.nav-tabs {
    display: flex;
    background: var(--color-header-secondary);
    padding: 0 24px;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    padding: 12px 24px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9375rem;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: color var(--transition), border-color var(--transition);
    white-space: nowrap;
}

.tab-btn:hover {
    color: rgba(255, 255, 255, 0.85);
}

.tab-btn.active {
    color: #ffffff;
    border-bottom-color: var(--color-accent);
}

/* ===== Main Content ===== */
.main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== Tab Panels ===== */
.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.panel-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background-color var(--transition), box-shadow var(--transition);
    line-height: 1.4;
}

.btn-primary {
    background-color: var(--color-accent);
    color: #fff;
}

.btn-primary:hover {
    background-color: var(--color-accent-hover);
    box-shadow: var(--shadow-sm);
}

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

.btn-secondary:hover {
    background-color: #d1d5db;
}

.btn-danger {
    background-color: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background-color: var(--color-danger-hover);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.8125rem;
}

.btn-icon {
    padding: 6px 10px;
    font-size: 0.8125rem;
}

/* ===== Inputs ===== */
.input {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--color-text);
    background: #fff;
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
}

.input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.textarea {
    resize: vertical;
    min-height: 80px;
}

/* ===== Status Badges ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-pending {
    background-color: #e5e7eb;
    color: #4b5563;
}

.badge-running {
    background-color: rgba(14, 165, 233, 0.15);
    color: #0284c7;
    animation: pulse-badge 2s ease-in-out infinite;
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.6; }
}

.badge-paused {
    background-color: rgba(245, 158, 11, 0.15);
    color: #d97706;
}

.badge-done {
    background-color: rgba(34, 197, 94, 0.15);
    color: #16a34a;
}

.badge-failed {
    background-color: rgba(239, 68, 68, 0.15);
    color: #dc2626;
}

/* Running indicator */
.running-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    font-size: 12px;
    color: #0284c7;
    font-weight: 500;
}

.running-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #0284c7;
    animation: running-pulse 1.5s ease-in-out infinite;
}

@keyframes running-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.4); opacity: 0.5; }
}

/* ===== Task Cards ===== */
.task-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.task-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    transition: box-shadow var(--transition);
    border: 1px solid var(--color-border);
}

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

.task-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 8px;
}

.task-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    word-break: break-word;
}

.task-card-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 12px;
    font-size: 0.8125rem;
    color: var(--color-text-light);
}

.task-card-stats .stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.task-card-stats .stat-value {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--color-text);
}

.task-card-stats .stat-label {
    font-size: 0.75rem;
    color: var(--color-text-light);
}

.task-card-date {
    font-size: 0.75rem;
    color: var(--color-text-light);
    margin-bottom: 14px;
}

.task-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--color-text-light);
    grid-column: 1 / -1;
}

.empty-state p {
    font-size: 0.9375rem;
}

/* ===== Filter Bar ===== */
.filter-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    align-items: center;
}

.filter-bar .input {
    width: auto;
    min-width: 160px;
    flex: 1;
    max-width: 220px;
}

.filter-bar select.input {
    min-width: 140px;
}

/* ===== Table ===== */
.table-container {
    overflow-x: auto;
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    background: #f9fafb;
    color: var(--color-text-light);
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
}

.data-table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
}

.data-table tbody tr:nth-child(even) {
    background-color: #f9fafb;
}

.data-table tbody tr:hover {
    background-color: #f0f7ff;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}

.page-info {
    font-size: 0.875rem;
    color: var(--color-text-light);
}

/* ===== Log Container ===== */
.log-container {
    background: var(--color-log-bg);
    border-radius: var(--radius);
    padding: 16px;
    max-height: 500px;
    overflow-y: auto;
    font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
    font-size: 0.8125rem;
    line-height: 1.7;
    border: 1px solid #333;
}

.log-entry {
    display: flex;
    gap: 10px;
    padding: 2px 0;
    word-break: break-word;
}

.log-time {
    color: #6b7280;
    flex-shrink: 0;
    font-size: 0.75rem;
    padding-top: 1px;
}

.log-message {
    flex: 1;
}

.log-entry.info .log-message {
    color: #e5e7eb;
}

.log-entry.warning .log-message {
    color: #fbbf24;
}

.log-entry.error .log-message {
    color: #f87171;
}

.ws-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    color: var(--color-text-light);
}

/* ===== VNC Toolbar ===== */
.vnc-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.vnc-zoom-level {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text);
    min-width: 40px;
    text-align: center;
}

/* ===== noVNC Container ===== */
.novnc-container {
    position: relative;
    width: 100%;
    height: 600px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #fafafa;
}

.novnc-container:fullscreen {
    height: 100vh;
    border: none;
    border-radius: 0;
}

.novnc-container.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border: none;
    border-radius: 0;
}

.novnc-container iframe {
    width: 100%;
    height: 100%;
    min-height: 600px;
    border: none;
    display: block;
}

.novnc-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafafa;
    color: var(--color-text-light);
    font-size: 1rem;
}

.novnc-placeholder.hidden {
    display: none;
}

.browser-actions {
    display: flex;
    gap: 8px;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    padding: 24px;
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(20px) scale(0.97);
    transition: transform 0.25s ease;
}

.modal-overlay.open .modal {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-text-light);
    padding: 4px;
    line-height: 1;
    transition: color var(--transition);
}

.modal-close:hover {
    color: var(--color-text);
}

.modal-body {
    padding: 20px 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
    margin-top: 8px;
}

/* ===== Form ===== */
.form-group {
    margin-bottom: 16px;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
}

.form-row {
    display: flex;
    gap: 14px;
}

.radio-group {
    display: flex;
    gap: 16px;
    padding-top: 4px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
    color: var(--color-text);
    cursor: pointer;
}

.radio-label input[type="radio"] {
    accent-color: var(--color-accent);
}

/* ===== Scrollbar (for log container) ===== */
.log-container::-webkit-scrollbar {
    width: 8px;
}

.log-container::-webkit-scrollbar-track {
    background: #2a2a2a;
    border-radius: 4px;
}

.log-container::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

.log-container::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .header {
        padding: 0 16px;
        height: 54px;
    }

    .logo-text {
        font-size: 1.05rem;
    }

    .logo svg {
        width: 26px;
        height: 26px;
    }

    .nav-tabs {
        padding: 0 12px;
    }

    .tab-btn {
        padding: 10px 16px;
        font-size: 0.875rem;
    }

    .main-content {
        padding: 16px;
    }

    .task-list {
        grid-template-columns: 1fr;
    }

    .filter-bar {
        flex-direction: column;
    }

    .filter-bar .input {
        max-width: 100%;
        width: 100%;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .panel-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .data-table {
        font-size: 0.8125rem;
    }

    .data-table th,
    .data-table td {
        padding: 8px 10px;
    }

    .novnc-container {
        height: 400px;
    }

    .novnc-container iframe {
        min-height: 400px;
    }

    .browser-actions {
        width: 100%;
    }

    .browser-actions .btn {
        flex: 1;
    }

    .modal {
        max-width: 100%;
    }
}
