/* =============================================================================
   Pannello Deploy — foglio di stile unico.
   Nessuna risorsa esterna (font, icone, CDN): la CSP consente solo 'self' e il
   pannello deve funzionare anche quando la rete del server fa i capricci.
   ============================================================================= */

:root {
    color-scheme: light dark;

    --bg: #f4f5f7;
    --bg-card: #ffffff;
    --bg-sunken: #eceef1;
    --border: #d8dbe0;
    --text: #1b1f24;
    --text-muted: #6b7280;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --warn: #a16207;
    --warn-bg: #fef3c7;
    --error: #b91c1c;
    --error-bg: #fee2e2;

    --log-bg: #10151c;
    --log-text: #d6deeb;

    --radius: 10px;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171c;
        --bg-card: #1c2027;
        --bg-sunken: #23282f;
        --border: #333a44;
        --text: #e6e9ee;
        --text-muted: #9aa3af;

        --accent: #3b82f6;
        --accent-hover: #60a5fa;
        --ok: #4ade80;
        --ok-bg: #14321f;
        --warn: #fbbf24;
        --warn-bg: #3a2e0c;
        --error: #f87171;
        --error-bg: #3d1616;
    }
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.error { color: var(--error); }

/* ─── Login ───────────────────────────────────────────────────────────────── */

#view-login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: 0 4px 24px rgb(0 0 0 / 8%);
}

.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p { margin: 0 0 20px; font-size: 14px; }

.login-card label {
    display: block;
    margin: 14px 0 6px;
    font-size: 13px;
    font-weight: 600;
}

.login-card input {
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.login-card input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.login-card button {
    width: 100%;
    margin-top: 22px;
    padding: 11px;
    font: inherit;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.login-card button:hover:not(:disabled) { background: var(--accent-hover); }
.login-card button:disabled { opacity: .6; cursor: progress; }
#login-error { margin: 14px 0 0; font-size: 13px; }

/* ─── Barra superiore ─────────────────────────────────────────────────────── */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.topbar-title { display: flex; align-items: center; gap: 10px; }
.topbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

main {
    max-width: 1180px;
    margin: 0 auto;
    padding: 20px 20px 60px;
}

.section-title {
    margin: 30px 0 12px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ─── Bottoni ─────────────────────────────────────────────────────────────── */

button { font: inherit; }

.btn-ghost, .btn-primary, .btn-danger {
    padding: 7px 13px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
}

.btn-ghost:hover { background: var(--bg-sunken); }

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

.btn-danger {
    background: var(--error-bg);
    border-color: var(--error);
    color: var(--error);
}

button:disabled { opacity: .55; cursor: not-allowed; }

button:focus-visible, select:focus-visible, input:focus-visible, pre:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* ─── Pillole di stato ────────────────────────────────────────────────────── */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.pill-ok    { background: var(--ok-bg);    color: var(--ok); }
.pill-warn  { background: var(--warn-bg);  color: var(--warn); }
.pill-error { background: var(--error-bg); color: var(--error); }
.pill-muted { background: var(--bg-sunken); color: var(--text-muted); }

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

/* ─── Schede dei progetti ─────────────────────────────────────────────────── */

.projects {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.card {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px 18px;
}

.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.card-head h3 { margin: 0; font-size: 17px; }
.card-desc { margin: 4px 0 14px; font-size: 13px; color: var(--text-muted); }

.card-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}
.card-link:hover { text-decoration: underline; }

.git-box {
    background: var(--bg-sunken);
    border-radius: 8px;
    padding: 11px 13px;
    font-size: 13px;
}

.git-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

code, .mono {
    font-family: var(--mono);
    font-size: 12.5px;
}

.commit-subject {
    margin: 7px 0 0;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
}

.git-note { margin: 8px 0 0; font-size: 12.5px; }

.infra {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 12px 0 0;
}

.infra-item {
    font-family: var(--mono);
    font-size: 11.5px;
    padding: 2px 7px;
    border-radius: 6px;
    background: var(--bg-sunken);
    color: var(--text-muted);
    border: 1px solid transparent;
}
.infra-item.level-ok    { color: var(--ok); }
.infra-item.level-warn  { color: var(--warn);  border-color: var(--warn); }
.infra-item.level-error { color: var(--error); border-color: var(--error); }

.card-actions {
    display: flex;
    gap: 9px;
    align-items: stretch;
    margin-top: auto;
    padding-top: 16px;
}

.card-actions select {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font: inherit;
    font-size: 13px;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.card-actions .btn-primary { white-space: nowrap; }

.variant-note {
    margin: 9px 0 0;
    font-size: 12.5px;
    color: var(--text-muted);
}

/* ─── Pannello del job ────────────────────────────────────────────────────── */

.job-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px 16px;
    margin-bottom: 24px;
}

.job-head {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.job-head-actions { display: flex; align-items: center; gap: 12px; }
.job-head strong { margin-right: 8px; }

.follow {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 7px;
    vertical-align: -1px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Rispetta chi ha chiesto meno animazioni a livello di sistema. */
@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 3s; }
}

.banner {
    margin: 0 0 12px;
    padding: 10px 13px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 500;
}

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

.log {
    margin: 0;
    padding: 13px 15px;
    max-height: 460px;
    overflow: auto;
    background: var(--log-bg);
    color: var(--log-text);
    border-radius: 8px;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    /* Sempre scuro: un log è più leggibile su fondo scuro anche in tema chiaro. */
    color-scheme: dark;
}

/* ─── Storico ─────────────────────────────────────────────────────────────── */

.history {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.history-row {
    display: grid;
    grid-template-columns: 150px 1fr auto auto;
    gap: 12px;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
}

.history-row:last-child { border-bottom: 0; }
.history-row:hover { background: var(--bg-sunken); }

.history-empty { padding: 22px 15px; color: var(--text-muted); font-size: 14px; }

.history-when { color: var(--text-muted); font-size: 12.5px; font-family: var(--mono); }
.history-what strong { font-weight: 600; }

@media (max-width: 640px) {
    .history-row { grid-template-columns: 1fr auto; }
    .history-when { grid-column: 1 / -1; }
}

/* ─── Finestre modali ─────────────────────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgb(0 0 0 / 55%);
}

.modal-box {
    width: 100%;
    max-width: 980px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.modal-small { max-width: 460px; }

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-body { padding: 16px; }
.modal-body p { margin: 0 0 8px; }

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    padding: 13px 16px;
    border-top: 1px solid var(--border);
}

.modal-box .log {
    max-height: none;
    flex: 1;
    border-radius: 0;
}
