:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --danger-color: #dc2626;
    --danger-hover: #b91c1c;
    --success-color: #16a34a;
    --warning-color: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.5;
    color: var(--gray-900);
    background: var(--gray-50);
}

.screen {
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* Login Screen */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-container h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    color: var(--gray-900);
}

.login-container p {
    font-size: 1.125rem;
    color: var(--gray-600);
    margin-bottom: 2rem;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-small {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

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

.btn-secondary {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-50);
}

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

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

.btn-small {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    background: white;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}

.btn-small:hover {
    background: var(--gray-50);
}

/* Header */
header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem 2rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1600px;
    margin: 0 auto;
}

header h1 {
    font-size: 1.5rem;
    color: var(--gray-900);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info span {
    color: var(--gray-600);
    font-size: 0.875rem;
}

/* Main Content */
main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
}

.controls {
    margin-bottom: 1.5rem;
}

.filters {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

#search-input,
#repo-filter,
#status-filter,
#cloud-filter,
#gpu-filter {
    padding: 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

#search-input,
#repo-filter {
    width: 160px;
}

#status-filter,
#cloud-filter,
#gpu-filter {
    min-width: 120px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-700);
    cursor: pointer;
    white-space: nowrap;
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.job-list-container,
.details-container {
    background: white;
    border-radius: 0.5rem;
    border: 1px solid var(--gray-200);
    padding: 1.5rem;
    max-height: calc(100vh - 200px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.job-list-container h2,
.details-container h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--gray-900);
}

/* Table wrapper for scroll with sticky header */
.table-wrapper {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* Job Table */
#jobs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    table-layout: fixed;
}

.col-id { width: 50px; }
.col-name { width: auto; }
.col-status { width: 100px; }
.col-gpus { width: 90px; }
.col-cloud { width: 90px; }
.col-submitted { width: 80px; }
.col-repo { width: 100px; }

#jobs-table th {
    text-align: left;
    padding: 0.75rem 0.5rem;
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 1;
}

#jobs-table td {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid var(--gray-100);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#jobs-table tbody tr {
    cursor: pointer;
    transition: background 0.2s;
}

#jobs-table tbody tr:hover {
    background: var(--gray-50);
}

#jobs-table tbody tr.selected {
    background: var(--primary-color);
    color: white;
}

#jobs-table tbody tr.selected .status-badge {
    border-color: white;
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    border: 1px solid transparent;
}

.status-pending,
.status-submitting {
    background: var(--gray-100);
    color: var(--gray-700);
    border-color: var(--gray-300);
}

.status-running {
    background: #dbeafe;
    color: #1e40af;
    border-color: #93c5fd;
}

.status-completed {
    background: #dcfce7;
    color: #166534;
    border-color: #86efac;
}

.status-failed,
.status-failed_setup {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}

.status-cancelled {
    background: var(--gray-100);
    color: var(--gray-600);
    border-color: var(--gray-300);
}

/* Job Details */
.details-container {
    overflow-y: auto;
}

.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: var(--gray-600);
    font-size: 1rem;
}

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

.detail-section {
    margin-bottom: 2rem;
}

.detail-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--gray-900);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.detail-item.full-width {
    margin-bottom: 1rem;
}

.detail-item .label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--gray-600);
}

.detail-item code,
.detail-item pre {
    background: var(--gray-50);
    padding: 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-family: 'Monaco', 'Courier New', monospace;
    overflow-x: auto;
}

.detail-item pre {
    white-space: pre-wrap;
    color: var(--danger-color);
}

/* Inline links in details */
.inline-link {
    color: var(--primary-color);
    text-decoration: none;
}

.inline-link:hover {
    text-decoration: underline;
}

.inline-link.mono {
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 0.85em;
}

.links-grid {
    display: flex;
    gap: 1rem;
}

.link-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    color: var(--gray-700);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.link-btn:hover {
    background: var(--gray-100);
    border-color: var(--gray-400);
}

/* Logs */
.logs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.logs-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logs-controls label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.logs-wrapper {
    position: relative;
}

.logs-scroll-hint {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 0.375rem;
    font-size: 0.75rem;
    color: #e5e7eb;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 0.375rem 0.375rem 0 0;
    z-index: 1;
}

.logs-content {
    background: var(--gray-900);
    color: #e5e7eb;
    padding: 1rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-family: 'Monaco', 'Courier New', monospace;
    height: 400px;
    overflow-y: scroll;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.live-tail-separator {
    color: var(--gray-600);
    text-align: center;
    padding: 0.25rem 0;
    font-style: italic;
    font-size: 0.7rem;
}

.logs-content:empty::before {
    content: 'No logs available';
    color: var(--gray-600);
}

/* Load More */
.load-more {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.75rem;
    border-top: 1px solid var(--gray-200);
    font-size: 0.875rem;
    color: var(--gray-600);
}

/* Loading & Error States */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--gray-600);
}

.error {
    background: #fee2e2;
    color: #991b1b;
    padding: 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 1024px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

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