/* https://alpinejs.dev/directives/cloak */
[x-cloak] {
    display: none !important;
}

:root {
    --bg: #f5f6f8;
    --card: #fff;
    --border: #dfe3e8;
    --muted: #6b7280;
    --accent: #2563eb;
    --danger: #dc2626;
    --text: #111;
    --label-text: #374151;
    --surface-alt: #f9fafb;
    --row-hover: #f9fbff;
    --ghost-bg: #e5e7eb;
    --pill-hunteka-bg: #dbeafe;
    --pill-hunteka-fg: #1e40af;
    --pill-corvina-bg: #fef3c7;
    --pill-corvina-fg: #92400e;
    --pill-idle-bg: #f3f4f6;
    --pill-idle-fg: #4b5563;
    --pill-running-bg: #e0e7ff;
    --pill-running-fg: #3730a3;
    --pill-rebuilding-bg: #ffedd5;
    --pill-rebuilding-fg: #9a3412;
    --banner-error-bg: #fee2e2;
    --banner-error-fg: #991b1b;
    --banner-success-bg: #dcfce7;
    --banner-success-fg: #166534;
    --on-accent: #fff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.wrap {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

header h1 {
    font-size: 1.4rem;
    margin: 0 0 4px;
}

/* Header: title on the left, logged-in user + logout on the right. */
.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.topbar .actions {
    margin-top: 0;
    align-items: center;
}

.muted {
    color: var(--muted);
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0;
}

button {
    background: var(--accent);
    color: var(--on-accent);
    border: 0;
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}

button:hover {
    filter: brightness(1.05);
}

button:disabled {
    opacity: .5;
    cursor: default;
}

button.ghost {
    background: var(--ghost-bg);
    color: var(--text);
}

button.link {
    background: none;
    color: var(--accent);
    padding: 4px 6px;
    font-size: 13px;
}

button.link.danger {
    color: var(--danger);
}

/*
 * Only the selected tab renders and only it polls, so the selection has to be unmistakable: everything
 * below the bar, header included, belongs to one pipeline at a time.
 */
.tabs {
    display: flex;
    gap: 4px;
    margin-top: 20px;
    border-bottom: 1px solid var(--border);
}

.tabs button {
    background: none;
    color: var(--muted);
    border-radius: 8px 8px 0 0;
    padding: 10px 18px;
    font-size: 14px;
    border-bottom: 2px solid transparent;
}

.tabs button:hover {
    background: var(--ghost-bg);
    color: var(--text);
}

.tabs button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/*
 * What the engine is doing, above the table. The schedule belongs here too: switched off, it is
 * indistinguishable from a stuck service unless the header says so.
 */
.statusbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 32px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    margin-top: 20px;
    font-size: 13px;
}

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

.statusbar .item .label {
    color: var(--muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .03em;
}

.table-wrap {
    overflow-x: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
}

table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
}

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    background: var(--surface-alt);
    color: var(--muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .03em;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover {
    background: var(--row-hover);
}

td.wrap-cell {
    white-space: normal;
    max-width: 300px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

td.wrap-cell code.mono {
    overflow-wrap: anywhere;
    word-break: break-all;
}

.actions-col {
    text-align: right;
}

td.actions-col {
    text-align: right;
}

/* Second line of a table cell: the timestamp under a status pill, the hint under a record count. */
.sub {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
}

/* A sub-line reporting something wrong rather than extra; muted grey would hide the number that matters. */
.sub.danger-text {
    color: var(--danger);
}

.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
}

.pill.HUNTEKA {
    background: var(--pill-hunteka-bg);
    color: var(--pill-hunteka-fg);
}

.pill.CORVINA {
    background: var(--pill-corvina-bg);
    color: var(--pill-corvina-fg);
}

.pill.NEVER_RUN {
    background: var(--pill-idle-bg);
    color: var(--pill-idle-fg);
}

.pill.RUNNING {
    background: var(--pill-running-bg);
    color: var(--pill-running-fg);
}

.pill.REBUILDING {
    background: var(--pill-rebuilding-bg);
    color: var(--pill-rebuilding-fg);
}

/* A finished and a failed round mean the same as a success and an error banner, so they share the colour. */
.pill.COMPLETED {
    background: var(--banner-success-bg);
    color: var(--banner-success-fg);
}

.pill.FAILED {
    background: var(--banner-error-bg);
    color: var(--banner-error-fg);
}

/* A target's lastError, expanded on demand. English, like every other operator diagnostic. */
.error-detail {
    margin-top: 6px;
    padding: 8px 10px;
    max-width: 320px;
    border-radius: 8px;
    background: var(--banner-error-bg);
    color: var(--banner-error-fg);
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 12px;
}

code.mono {
    font-family: ui-monospace, Menlo, monospace;
    font-size: 12px;
}

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

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px 22px;
    margin-top: 20px;
}

.panel h2 {
    margin: 0 0 16px;
    font-size: 1.1rem;
}

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 18px;
}

.grid label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 13px;
    color: var(--label-text);
}

.grid label.full {
    grid-column: 1 / -1;
}

.grid input {
    font-size: 14px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
}

.grid input:focus {
    outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
    border-color: var(--accent);
}

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

.actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.banner {
    padding: 12px 16px;
    border-radius: 10px;
    margin: 12px 0;
    font-size: 14px;
}

.banner.error {
    background: var(--banner-error-bg);
    color: var(--banner-error-fg);
}

.banner.success {
    background: var(--banner-success-bg);
    color: var(--banner-success-fg);
}

/* Login page: narrow, centered card, reusing the .panel style. */
.login {
    max-width: 380px;
    margin: 12vh auto 0;
}

.login h1 {
    font-size: 1.2rem;
    margin: 0 0 4px;
}

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

.login .actions button {
    width: 100%;
}
