:root {
    --c-bg: #f4f6fb;
    --c-surface: #ffffff;
    --c-text: #1f2937;
    --c-text-muted: #6b7280;
    --c-text-faint: #9ca3af;
    --c-border: #e5e7eb;
    --c-primary: #2563eb;
    --c-primary-hover: #1d4ed8;
    --c-success: #16a34a;
    --c-success-hover: #15803d;
    --c-danger: #dc2626;
    --c-danger-hover: #b91c1c;
    --c-warning: #d97706;
    --c-warning-hover: #b45309;
    --c-nav: #0f172a;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.12), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
    --radius: 10px;
    --radius-sm: 6px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    line-height: 1.55;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

/* --- navbar --- */
.navbar {
    background: var(--c-nav);
    color: white;
    padding: 0.85rem 1.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}
.navbar-brand a {
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.01em;
}
.navbar-user { display: flex; align-items: center; gap: 1rem; }
.navbar-link { color: white; opacity: 0.85; text-decoration: none; font-size: 0.85rem; }
.navbar-link:hover { opacity: 1; text-decoration: underline; }
.user-name { font-size: 0.85rem; opacity: 0.75; }
.logout-form { display: inline; }
.logout-form .btn { background: rgba(255,255,255,0.1); color: white; }
.logout-form .btn:hover { background: rgba(255,255,255,0.2); }

/* --- layout --- */
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem 1.75rem; }
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; color: var(--c-text); }
.page-subtitle { color: var(--c-text-muted); font-size: 0.9rem; margin-top: 0.15rem; }

h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 1rem; color: var(--c-text); }

/* --- stats --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.stat-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.stat-number { font-size: 1.85rem; font-weight: 700; color: var(--c-nav); line-height: 1.15; }
.stat-label { font-size: 0.78rem; color: var(--c-text-muted); margin-top: 0.2rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.stat-error .stat-number { color: var(--c-danger); }

/* --- sections --- */
.section {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}

/* --- table --- */
.table-wrap { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}
.table th, .table td {
    padding: 0.7rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}
.table th {
    background: #fafbfc;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--c-text-muted);
    white-space: nowrap;
}
.table tbody tr:hover { background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table a { color: var(--c-primary); text-decoration: none; font-weight: 500; }
.table a:hover { text-decoration: underline; }

.col-ticket { white-space: nowrap; font-weight: 600; }
.col-actions { text-align: right; white-space: nowrap; }
.col-actions.col-actions { padding-right: 1rem; }
.col-date { white-space: nowrap; color: var(--c-text-muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.col-title { max-width: 480px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.table-narrow { max-width: 700px; }
.table-narrow td:first-child { font-weight: 600; width: 170px; color: var(--c-text-muted); }

.code-inline {
    background: #f3f4f6;
    color: #1f2937;
    padding: 0.18rem 0.45rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    white-space: nowrap;
}

/* --- badges --- */
.badge {
    display: inline-block;
    padding: 0.22rem 0.55rem;
    border-radius: 999px;
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.02em;
    line-height: 1.4;
}
.bg-gray-500 { background: #6b7280; }
.bg-gray-600 { background: #4b5563; }
.bg-blue-500 { background: #3b82f6; }
.bg-blue-600 { background: #2563eb; }
.bg-purple-500 { background: #8b5cf6; }
.bg-yellow-500 { background: #ca8a04; }
.bg-orange-500 { background: #ea580c; }
.bg-orange-600 { background: #c2410c; }
.bg-green-500 { background: #22c55e; }
.bg-green-600 { background: #16a34a; }
.bg-teal-500 { background: #0d9488; }
.bg-red-500 { background: #ef4444; }
.bg-red-600 { background: #dc2626; }
.bg-red-700 { background: #b91c1c; }
.bg-red-800 { background: #991b1b; }

/* --- buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.5rem 0.9rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
    font-family: inherit;
    white-space: nowrap;
}
.btn:hover { box-shadow: var(--shadow-sm); }
.btn:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-block { display: flex; width: 100%; }

.btn-primary { background: var(--c-primary); color: white; }
.btn-primary:hover { background: var(--c-primary-hover); }
.btn-success { background: var(--c-success); color: white; }
.btn-success:hover { background: var(--c-success-hover); }
.btn-danger { background: var(--c-danger); color: white; }
.btn-danger:hover { background: var(--c-danger-hover); }
.btn-warning { background: var(--c-warning); color: white; }
.btn-warning:hover { background: var(--c-warning-hover); }

/* --- actions row (used in conflict + QA cells) --- */
.actions-row {
    display: inline-flex;
    gap: 0.4rem;
    flex-wrap: nowrap;
    justify-content: flex-end;
}

/* --- retry dropdown menu (action-menu) --- */
.action-menu {
    display: inline-block;
    position: relative;
}
.action-menu > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
}
.action-menu > summary::-webkit-details-marker { display: none; }

.action-menu-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 320px;
    max-width: 380px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.35rem;
    z-index: 50;
    text-align: left;
}

/* Each direct child item in the menu */
.action-menu-item {
    display: block;
    margin: 0;
}
.action-menu-btn {
    display: block;
    width: 100%;
    padding: 0.55rem 0.7rem;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    color: var(--c-text);
    transition: background 0.1s;
    list-style: none;
}
.action-menu-btn::-webkit-details-marker { display: none; }
.action-menu-btn:hover { background: #f3f4f6; }
.action-menu-btn strong { display: block; font-size: 0.85rem; font-weight: 600; }
.action-menu-btn small { display: block; font-size: 0.75rem; color: var(--c-text-muted); margin-top: 0.1rem; line-height: 1.35; font-weight: 400; }

/* Sub-menus for hint forms */
.action-submenu { margin: 0; }
.action-submenu[open] > .action-menu-btn { background: #eff6ff; }
.action-submenu[open] > .action-menu-btn strong { color: var(--c-primary); }

.hint-form {
    padding: 0.6rem 0.7rem 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-top: 1px solid var(--c-border);
    margin-top: 0.2rem;
}
.hint-form textarea {
    width: 100%;
    padding: 0.55rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    resize: vertical;
    min-height: 60px;
    background: #fafbfc;
}
.hint-form textarea:focus { outline: none; border-color: var(--c-primary); background: white; }
.hint-template {
    width: 100%;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.8rem;
    background: #fafbfc;
    color: var(--c-text);
}
.hint-template:focus { outline: none; border-color: var(--c-primary); }

/* --- diff view on job detail --- */
.diff-wrap > summary { cursor: pointer; user-select: none; list-style: none; }
.diff-wrap > summary::-webkit-details-marker { display: none; }
.diff-file { border: 1px solid var(--c-border); border-radius: var(--radius-sm); margin: 0.6rem 0; background: #fafbfc; }
.diff-file > summary {
    padding: 0.5rem 0.75rem; cursor: pointer; user-select: none;
    font-size: 0.85rem; font-weight: 500; background: #f3f4f6;
    border-bottom: 1px solid var(--c-border);
}
.diff-file > summary::-webkit-details-marker { display: none; }
.diff-file > summary::before { content: "▸ "; color: var(--c-text-muted); }
.diff-file[open] > summary::before { content: "▾ "; }
.diff-body {
    margin: 0; padding: 0.5rem 0.75rem;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px; line-height: 1.5;
    overflow-x: auto;
    background: white;
}
.diff-body span { display: block; white-space: pre; min-height: 1.5em; }
.diff-add  { background: #ecfdf5; color: #166534; }
.diff-del  { background: #fef2f2; color: #991b1b; }
.diff-hunk { background: #eff6ff; color: #1d4ed8; font-weight: 500; }
.diff-ctx  { color: var(--c-text); }

/* --- today summary row --- */
.today-summary {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 1rem 1.5rem;
    padding: 0.6rem 1rem; margin-bottom: 1.2rem;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    font-size: 0.88rem;
}
.today-summary-label {
    color: var(--c-text-muted); font-weight: 600; font-size: 0.78rem;
    text-transform: uppercase; letter-spacing: 0.05em;
}
.today-summary-item { color: var(--c-text); }
.today-summary-item strong { color: var(--c-nav); font-variant-numeric: tabular-nums; }
.today-summary--ok strong { color: var(--c-success); }
.today-summary--err strong { color: var(--c-danger); }
.today-summary--neutral strong { color: var(--c-warning); }

/* --- job detail page --- */
.back-link {
    display: inline-block;
    margin-bottom: 0.85rem;
    color: var(--c-primary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
}
.back-link:hover { text-decoration: underline; }

.job-header {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1.5rem 1.75rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}
.job-header h1 { font-size: 1.5rem; }
.job-header > p { color: var(--c-text-muted); margin-top: 0.2rem; }
.job-meta { margin-top: 1rem; display: flex; align-items: center; gap: 0.85rem; flex-wrap: wrap; }
.mr-link {
    color: var(--c-primary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    background: #eff6ff;
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius-sm);
}
.mr-link:hover { background: #dbeafe; }

.description {
    white-space: pre-wrap;
    background: #fafbfc;
    border: 1px solid var(--c-border);
    padding: 1rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    color: var(--c-text);
}

.timeline { padding-left: 0.3rem; }
.timeline-item {
    position: relative;
    padding: 0.75rem 0 0.75rem 1.25rem;
    border-left: 2px solid var(--c-border);
    margin-left: 0.5rem;
}
.timeline-item::before {
    content: "";
    position: absolute;
    left: -6px;
    top: 1.1rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--c-primary);
    border: 2px solid white;
}
.timeline-time { font-size: 0.75rem; color: var(--c-text-faint); font-variant-numeric: tabular-nums; }
.timeline-event { font-weight: 600; font-size: 0.9rem; color: var(--c-text); margin-top: 0.1rem; }
.timeline-details { font-size: 0.83rem; color: var(--c-text-muted); margin-top: 0.25rem; white-space: pre-wrap; word-break: break-word; }
.timeline-item--check::before { background: #14b8a6; }
.timeline-item--pre::before { background: #6366f1; }
.timeline-item--fixer::before { background: #8b5cf6; }
.timeline-item--pushed::before, .timeline-item--mr::before { background: var(--c-success); }
.timeline-item--push::before { background: var(--c-warning); }
.timeline-item--fix::before, .timeline-item--review::before { background: var(--c-warning); }
.timeline-item--stopped::before { background: var(--c-danger); }

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

/* --- live log panel --- */
.live-log-panel {
    background: #0b1020;
    color: #cbd5e1;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    max-height: 520px;
    overflow: auto;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    border: 1px solid #1e293b;
}

/* --- login --- */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--c-bg);
}
.login-card {
    background: var(--c-surface);
    padding: 2.25rem 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--c-border);
}
.login-card h1 { text-align: center; color: var(--c-nav); }
.subtitle { text-align: center; color: var(--c-text-muted); margin-bottom: 1.5rem; font-size: 0.85rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.3rem; font-weight: 600; font-size: 0.85rem; color: var(--c-text); }
.form-group input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.12s;
}
.form-group input:focus { outline: none; border-color: var(--c-primary); }

/* --- alerts --- */
.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.88rem;
    border: 1px solid transparent;
}
.alert-error { background: #fef2f2; color: var(--c-danger-hover); border-color: #fecaca; }
.alert-danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    padding: 1rem 1.1rem;
    margin-bottom: 1.25rem;
}
.alert-warning {
    background: #fefce8;
    color: #854d0e;
    border: 1px solid #fef08a;
    padding: 1rem 1.1rem;
    margin-bottom: 1.25rem;
}
.alert-danger .table, .alert-warning .table { margin-top: 0.5rem; background: rgba(255,255,255,0.65); border-radius: var(--radius-sm); }
.alert-danger code, .alert-warning code { background: rgba(0,0,0,0.05); padding: 0.1rem 0.35rem; border-radius: 3px; font-size: 0.82rem; }

/* Small-screen polish */
@media (max-width: 900px) {
    .container { padding: 1rem; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
    .col-title { max-width: 240px; }
    .action-menu-panel { right: -8px; min-width: 280px; }
}

/* ---- Admin settings page ---- */
.muted { color: var(--c-text-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.banner { padding: 0.6rem 0.9rem; border-radius: 6px; margin: 0.75rem 0 1rem; font-size: 0.9rem; }
.banner-success { background: #ecfdf5; color: #065f46; border: 1px solid #6ee7b7; }
.banner-error { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }
.settings-form { max-width: 720px; }
.settings-row { display: flex; flex-direction: column; gap: 0.35rem; padding: 1rem 0; border-bottom: 1px solid var(--c-border, #e5e7eb); }
.settings-row label { display: flex; flex-direction: column; gap: 0.2rem; }
.settings-row label strong { font-size: 0.95rem; }
.settings-row label small { color: var(--c-text-muted); font-size: 0.82rem; line-height: 1.45; font-weight: 400; }
.settings-row input[type=number] { padding: 0.45rem 0.6rem; border: 1px solid var(--c-border, #d1d5db); border-radius: 6px; font-size: 0.95rem; max-width: 200px; }
.settings-row .hint { color: var(--c-text-muted); font-size: 0.78rem; }
.settings-actions { display: flex; gap: 0.75rem; margin-top: 1rem; }
