/* ============================================================================
   CSS Variables
   ============================================================================ */
:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-secondary: #64748b;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;

    --color-bg: #f8fafc;
    --color-bg-card: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-text-light: #94a3b8;

    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-family-mono: "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", monospace;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

    --radius: 6px;
    --radius-lg: 8px;
}

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

body {
    margin: 0;
    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-bg);
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1, h2, h3 {
    margin: 0;
    font-weight: 600;
}

code, pre {
    font-family: var(--font-family-mono);
    font-size: 13px;
}

code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
}

/* ============================================================================
   Layout
   ============================================================================ */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

.header {
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text);
}

.logo:hover {
    text-decoration: none;
}

.nav {
    display: flex;
    gap: 24px;
}

.nav-link {
    color: var(--color-text-muted);
    font-weight: 500;
}

.nav-link:hover {
    color: var(--color-primary);
    text-decoration: none;
}

.main {
    min-height: calc(100vh - 140px);
    padding: 32px 0;
}

.footer {
    background: var(--color-bg-card);
    border-top: 1px solid var(--color-border);
    padding: 24px 0;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 13px;
}

/* ============================================================================
   Page Header
   ============================================================================ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
}

.breadcrumb {
    font-size: 14px;
    color: var(--color-text-muted);
}

.breadcrumb a {
    color: var(--color-text-muted);
}

.breadcrumb a:hover {
    color: var(--color-primary);
}

/* ============================================================================
   Buttons
   ============================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none !important;
}

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

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

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

.btn-secondary:hover {
    background: #cbd5e1;
}

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

.btn-warning:hover {
    background: #d97706;
}

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

.btn-danger:hover {
    background: #dc2626;
}

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
}

/* ============================================================================
   Filters
   ============================================================================ */
.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text-muted);
    font-weight: 500;
    transition: all 0.15s ease;
}

.filter-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    text-decoration: none;
}

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

.filter-btn.active .badge {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #e2e8f0;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

.badge-green {
    background: #dcfce7;
    color: #166534;
}

.badge-yellow {
    background: #fef3c7;
    color: #92400e;
}

.badge-red {
    background: #fee2e2;
    color: #991b1b;
}

/* ============================================================================
   Table
   ============================================================================ */
.table-container {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

.table tbody tr:hover {
    background: #f8fafc;
}

.col-status {
    width: 60px;
}

.col-id {
    width: 200px;
}

.col-author {
    width: 150px;
}

.col-command {
    min-width: 200px;
}

.col-branch {
    width: 180px;
    font-size: 13px;
    color: var(--color-text-muted);
}

.col-created,
.col-duration {
    width: 120px;
}

.col-actions {
    width: 100px;
    text-align: right;
}

.task-link {
    font-family: var(--font-family-mono);
    font-size: 13px;
}

/* ============================================================================
   Status Indicators
   ============================================================================ */
.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-secondary);
}

.status-indicator.large {
    width: 14px;
    height: 14px;
}

.status-in-queue {
    background: var(--color-primary);
    animation: pulse 2s infinite;
}

.status-in-process {
    background: var(--color-warning);
    animation: pulse 1s infinite;
}

.status-done {
    background: var(--color-success);
}

.status-fail,
.status-error {
    background: var(--color-danger);
}

.status-cancelled {
    background: var(--color-secondary);
}

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

.status-text {
    font-weight: 600;
    text-transform: capitalize;
}

/* ============================================================================
   Commit & Branch Styles
   ============================================================================ */
.commit-link {
    color: var(--color-primary);
    font-weight: 500;
}

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

.commit-subject {
    margin-left: 8px;
    font-size: 0.9em;
}

.branch-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.branch-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    font-size: 0.85em;
    font-family: var(--font-mono);
}

.branch-badge.branch-master {
    background: var(--color-success);
    border-color: var(--color-success);
    color: white;
    font-weight: 600;
}

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

.page-link {
    padding: 8px 16px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-weight: 500;
}

.page-link:hover:not(.disabled) {
    border-color: var(--color-primary);
    color: var(--color-primary);
    text-decoration: none;
}

.page-link.disabled {
    color: var(--color-text-light);
    cursor: not-allowed;
}

.page-info {
    color: var(--color-text-muted);
}

/* ============================================================================
   Cards
   ============================================================================ */
.card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.card-header h2 {
    font-size: 16px;
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--color-border);
    background: #f8fafc;
}

/* ============================================================================
   Task Info Card
   ============================================================================ */
.task-info-card .card-header {
    padding: 20px;
}

.task-status {
    display: flex;
    align-items: center;
    gap: 10px;
}

.task-actions {
    display: flex;
    gap: 12px;
}

.info-sections {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0 !important;
}

.info-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.info-section:last-child {
    border-bottom: none;
}

.info-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 12px;
}

.info-section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-item.full-width {
    grid-column: 1 / -1;
}

.info-item label {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.info-item span,
.info-item code {
    font-size: 14px;
}

.download-buttons {
    display: flex;
    gap: 12px;
}

/* ============================================================================
   Log Viewer
   ============================================================================ */
.log-card .card-header {
    flex-wrap: wrap;
    gap: 12px;
}

.log-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.log-info {
    font-size: 13px;
    color: var(--color-text-muted);
}

.auto-refresh-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
}

.auto-refresh-toggle input {
    cursor: pointer;
}

.log-body {
    padding: 0;
}

.log-viewer {
    max-height: 600px;
    overflow: auto;
    background: #1e293b;
}

.log-viewer pre {
    margin: 0;
    padding: 20px;
    color: #e2e8f0;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.empty-log {
    padding: 40px;
    text-align: center;
    color: var(--color-text-muted);
}

/* ============================================================================
   Empty State
   ============================================================================ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.empty-state h2 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--color-text-muted);
}

.empty-state p {
    color: var(--color-text-muted);
    margin: 0;
}

/* ============================================================================
   Error Page
   ============================================================================ */
.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

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

.error-code {
    font-size: 72px;
    font-weight: 700;
    color: var(--color-text-light);
    margin-bottom: 8px;
}

.error-message {
    font-size: 18px;
    color: var(--color-text-muted);
    margin-bottom: 24px;
}

/* ============================================================================
   Forms
   ============================================================================ */
.task-form {
    max-width: 600px;
}

.form-group {
    margin-bottom: 24px;
}

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

.form-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-card);
    color: var(--color-text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder {
    color: var(--color-text-light);
}

.form-help {
    margin-top: 6px;
    font-size: 13px;
    color: var(--color-text-muted);
    line-height: 1.5;
}

.form-help code {
    font-size: 12px;
    padding: 1px 4px;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--color-border);
}

.form-message {
    margin-top: 20px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
}

.form-message.success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}

.form-message.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.form-message a {
    color: inherit;
    font-weight: 600;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Dialect grid */
.dialect-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.dialect-item {
    font-size: 13px;
    padding: 6px 10px;
    background: #f1f5f9;
    border-radius: var(--radius);
}

.dialect-item code {
    font-weight: 600;
    margin-right: 4px;
}

.example-table {
    width: 100%;
    border-collapse: collapse;
}

.example-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
    font-size: 13px;
}

.example-table td:first-child {
    width: 150px;
}

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

/* ============================================================================
   System Stats Panel
   ============================================================================ */
.system-stats-panel {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1.5fr;
    gap: 20px;
}

.stat-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.cpu-icon {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
}

.cpu-icon::before {
    content: "";
    width: 20px;
    height: 20px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='white' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a2 2 0 012 2v1h2a2 2 0 012 2v2h1a2 2 0 110 4h-1v2a2 2 0 01-2 2h-2v1a2 2 0 11-4 0v-1H8a2 2 0 01-2-2v-2H5a2 2 0 110-4h1V7a2 2 0 012-2h2V4a2 2 0 012-2zm0 6a4 4 0 100 8 4 4 0 000-8z'/%3E%3C/svg%3E") no-repeat center;
}

.memory-icon {
    background: linear-gradient(135deg, #22c55e, #16a34a);
}

.memory-icon::before {
    content: "";
    width: 20px;
    height: 20px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='white' viewBox='0 0 24 24'%3E%3Cpath d='M4 5h16a1 1 0 011 1v12a1 1 0 01-1 1H4a1 1 0 01-1-1V6a1 1 0 011-1zm1 2v10h14V7H5zm2 2h2v6H7V9zm4 0h2v6h-2V9zm4 0h2v6h-2V9z'/%3E%3C/svg%3E") no-repeat center;
}

.java-icon {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.java-icon::before {
    content: "";
    width: 20px;
    height: 20px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='white' viewBox='0 0 24 24'%3E%3Cpath d='M8.851 18.56s-.917.534.653.714c1.902.218 2.874.187 4.969-.211 0 0 .552.346 1.321.646-4.699 2.013-10.633-.118-6.943-1.149zm-.575-2.627s-1.028.761.542.924c2.032.209 3.636.227 6.413-.308 0 0 .384.389.987.602-5.679 1.661-12.007.13-7.942-1.218zm4.84-4.458c1.158 1.333-.304 2.533-.304 2.533s2.939-1.518 1.589-3.418c-1.261-1.772-2.228-2.652 3.007-5.688 0 0-8.216 2.051-4.292 6.573z'/%3E%3C/svg%3E") no-repeat center;
}

.stat-content {
    flex: 1;
    min-width: 0;
}

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.stat-usage {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-left: auto;
}

.stat-bar {
    height: 6px;
    background: var(--color-border);
    border-radius: 3px;
    margin-top: 8px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.cpu-bar {
    background: linear-gradient(90deg, #3b82f6, #1d4ed8);
}

.memory-bar {
    background: linear-gradient(90deg, #22c55e, #16a34a);
}

.bar-warning {
    background: linear-gradient(90deg, #f59e0b, #d97706) !important;
}

.bar-danger {
    background: linear-gradient(90deg, #ef4444, #dc2626) !important;
}

.java-processes-card {
    border-left: 1px solid var(--color-border);
    padding-left: 20px;
}

.java-processes-list {
    margin-top: 8px;
    max-height: 80px;
    overflow-y: auto;
}

.java-process-item {
    display: flex;
    gap: 12px;
    font-size: 12px;
    padding: 4px 0;
    border-bottom: 1px solid var(--color-border);
}

.java-process-item:last-child {
    border-bottom: none;
}

.java-pid {
    color: var(--color-text-muted);
    font-family: var(--font-family-mono);
    min-width: 60px;
}

.java-cpu {
    color: var(--color-primary);
    font-weight: 500;
    min-width: 70px;
}

.java-mem {
    color: var(--color-success);
    font-weight: 500;
}

@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .java-processes-card {
        grid-column: span 2;
        border-left: none;
        border-top: 1px solid var(--color-border);
        padding-left: 0;
        padding-top: 16px;
    }
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .java-processes-card {
        grid-column: span 1;
    }
}

/* ============================================================================
   Charts
   ============================================================================ */
.chart-wrapper {
    position: relative;
    height: 400px;
}

.chart-wrapper-medium {
    height: 300px;
}

.stats-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 24px;
}

.chart-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

#duration-chart {
    cursor: pointer;
}

.toast-notification {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--color-text);
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 1000;
    pointer-events: none;
}

.toast-notification.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 768px) {
    .stats-summary-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================================
   Utilities
   ============================================================================ */
.text-muted {
    color: var(--color-text-muted);
}

.text-success {
    color: var(--color-success);
}

.text-danger {
    color: var(--color-danger);
}

.monospace {
    font-family: var(--font-family-mono);
}

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

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .filters {
        flex-wrap: wrap;
    }

    .table-container {
        overflow-x: auto;
    }

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

    .log-controls {
        flex-wrap: wrap;
    }

    .download-buttons {
        flex-wrap: wrap;
    }
}
