/* Custode — interfaccia. Un solo carattere (system UI), palette navy. */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --navy-950: #081226;
  --navy-900: #0b1830;
  --navy-800: #122447;
  --navy-700: #1b3260;
  --primary: #1e40af;
  --primary-hover: #1e3a8a;
  --primary-soft: #e8eefc;
  --ok: #15803d;      --ok-soft: #e7f6ec;
  --warn: #b45309;    --warn-soft: #fdf3e3;
  --err: #b91c1c;     --err-soft: #fdecec;
  --info: #0369a1;    --info-soft: #e6f3fa;
  --muted: #64748b;   --muted-soft: #eef1f5;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 30px rgba(8, 18, 38, .18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar: 236px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070f1f; --surface: #0e1a31; --surface-2: #0b1629; --border: #1d2c49; --border-strong: #2a3d61;
    --text: #e6ebf5; --text-2: #aab6cc; --text-3: #8392ad;
    --primary: #5b8def; --primary-hover: #7aa3f3; --primary-soft: #16264a;
    --ok: #4ade80; --ok-soft: #10281c; --warn: #fbbf24; --warn-soft: #2d2410; --err: #f87171; --err-soft: #321618;
    --info: #38bdf8; --info-soft: #0c2536; --muted: #8392ad; --muted-soft: #16223a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── Shell ── */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--navy-900); color: #c6d2ea; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: #fff; font-weight: 700; font-size: 16px; letter-spacing: .01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: #fff; display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; stroke: var(--navy-900); stroke-width: 2.2; fill: none; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: #8ea0c4; letter-spacing: .04em; text-transform: uppercase; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6f82a8; padding: 16px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; color: #c6d2ea; font-weight: 500; }
.nav a:hover { background: var(--navy-800); text-decoration: none; color: #fff; }
.nav a.active { background: var(--navy-700); color: #fff; }
.nav a .count { margin-left: auto; font-size: 11px; background: var(--err); color: #fff; border-radius: 99px; padding: 0 7px; font-weight: 600; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--navy-800); padding: 12px 10px 0; font-size: 12px; color: #8ea0c4; }
.sidebar-foot .sched { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.sidebar-foot button { background: none; border: 0; color: #c6d2ea; padding: 0; cursor: pointer; font: inherit; display: flex; gap: 8px; align-items: center; }
.main { min-width: 0; }
.topbar { display: none; }
.page { max-width: 1240px; margin: 0 auto; padding: 28px 32px 80px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.crumbs { font-size: 13px; color: var(--text-3); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.crumbs a { color: var(--text-3); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.offline-bar { background: var(--warn-soft); color: var(--warn); text-align: center; padding: 6px; font-size: 13px; font-weight: 500; }

/* ── Mobile ── */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { display: flex; align-items: center; gap: 10px; background: var(--navy-900); color: #fff; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 20; font-weight: 700; }
  .topbar .brand-mark { width: 26px; height: 26px; }
  .topbar .spacer { flex: 1; }
  .topbar button { background: none; border: 0; color: #fff; padding: 4px; }
  .page { padding: 18px 14px 96px; }
  .bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 11px; color: var(--text-3); font-weight: 500; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav a:hover { text-decoration: none; }
  h1 { font-size: 19px; }
}
@media (min-width: 901px) { .bottom-nav { display: none; } }

/* ── Cards & grid ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 14px; }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-main { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .g-3, .g-2 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }

.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12px; color: var(--text-3); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ── Status ── */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; line-height: 18px; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.s-ok, .s-success { color: var(--ok); background: var(--ok-soft); }
.s-warning, .s-stale { color: var(--warn); background: var(--warn-soft); }
.s-failed, .s-error { color: var(--err); background: var(--err-soft); }
.s-running, .s-queued, .s-info { color: var(--info); background: var(--info-soft); }
.s-pending, .s-disabled, .s-paused, .s-cancelled, .s-muted, .s-empty { color: var(--muted); background: var(--muted-soft); }
.s-running::before { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--ok); } .dot.err { background: var(--err); } .dot.warn { background: var(--warn); }

.health-bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: var(--muted-soft); }
.health-bar span { display: block; }

/* ── Tables / lists ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3); padding: 10px 18px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
td { padding: 11px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 360px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
a.list-item { color: inherit; }
a.list-item:hover { background: var(--surface-2); text-decoration: none; }
.empty { text-align: center; color: var(--text-3); padding: 36px 18px; }
.empty svg.i { width: 30px; height: 30px; stroke-width: 1.4; margin-bottom: 8px; }

/* ── Project cards ── */
.project-card { display: block; color: inherit; padding: 16px 18px; border-left: 4px solid var(--c, var(--primary)); }
.project-card:hover { text-decoration: none; border-color: var(--border-strong); border-left-color: var(--c, var(--primary)); }
.project-card .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.project-card .meta { display: flex; gap: 14px; margin-top: 12px; font-size: 12px; color: var(--text-3); flex-wrap: wrap; }

.job-card { padding: 16px 18px; display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center; }
.job-card .name { font-weight: 650; font-size: 15px; color: var(--text); }
.job-card .facts { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 6px; }
.job-card .fact .k { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.job-card .fact .v { font-weight: 500; font-variant-numeric: tabular-nums; }
@media (max-width: 700px) { .job-card .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 500 14px var(--font); cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 35%, var(--border)); }
.btn.danger.solid { background: var(--err); color: #fff; border-color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--muted-soft); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 30px; }
.btn .spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); min-width: 210px; padding: 4px; z-index: 30; display: none; }
.menu.open .menu-list { display: block; }
.menu-list button { display: flex; width: 100%; gap: 9px; align-items: center; padding: 8px 10px; border: 0; background: none; font: 14px var(--font); color: var(--text); border-radius: 5px; cursor: pointer; text-align: left; }
.menu-list button:hover { background: var(--surface-2); }
.menu-list button.danger { color: var(--err); }
.menu-list hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Forms ── */
.form-section { padding: 20px 22px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 240px 1fr; gap: 24px; }
.form-section:last-child { border-bottom: 0; }
.form-section > .intro h2 { font-size: 15px; }
.form-section > .intro p { color: var(--text-3); font-size: 13px; margin: 6px 0 0; }
@media (max-width: 800px) { .form-section { grid-template-columns: 1fr; gap: 12px; padding: 16px; } }
.fields { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px 14px; }
.f { grid-column: span 6; display: flex; flex-direction: column; gap: 5px; }
.f.s3 { grid-column: span 3; } .f.s2 { grid-column: span 2; } .f.s4 { grid-column: span 4; }
@media (max-width: 600px) { .f.s3, .f.s2, .f.s4 { grid-column: span 6; } }
label.l { font-size: 13px; font-weight: 550; color: var(--text); }
.help { font-size: 12px; color: var(--text-3); }
.err-msg { font-size: 12px; color: var(--err); font-weight: 500; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=url], input[type=time], input:not([type]), select, textarea {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: 14px var(--font);
}
textarea { height: auto; min-height: 76px; padding: 9px 11px; resize: vertical; font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 30%, transparent); border-color: var(--primary); }
.invalid input, .invalid select, .invalid textarea { border-color: var(--err); }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 3px 0; }
.check input { margin: 2px 0 0; width: 16px; height: 16px; accent-color: var(--primary); flex: none; }
.check small { display: block; color: var(--text-3); font-size: 12px; }
.seg { display: inline-flex; background: var(--muted-soft); border-radius: 8px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; font: 500 13px var(--font); color: var(--text-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.input-group { display: flex; gap: 8px; }
.input-group > input { flex: 1; }
.callout { border-radius: 8px; padding: 11px 14px; font-size: 13px; display: flex; gap: 10px; align-items: flex-start; }
.callout.ok { background: var(--ok-soft); color: var(--ok); }
.callout.warn { background: var(--warn-soft); color: var(--warn); }
.callout.err { background: var(--err-soft); color: var(--err); }
.callout.info { background: var(--info-soft); color: var(--info); }
.callout ul { margin: 4px 0 0; padding-left: 18px; }
.callout .t { font-weight: 600; }
.retention-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.retention-grid .f { grid-column: span 1; }
@media (max-width: 700px) { .retention-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.form-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; background: var(--surface-2); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); position: sticky; bottom: 0; }
@media (max-width: 900px) { .form-foot { bottom: 58px; } }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

/* ── Log ── */
.log { background: var(--navy-950); color: #cfd8ea; font: 12.5px/1.6 var(--mono); padding: 14px 16px; border-radius: 0 0 var(--radius) var(--radius); max-height: 520px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.log .WARN { color: #fbbf24; } .log .ERROR { color: #f87171; } .log .ts { color: #6f82a8; }

/* ── Charts ── */
.chart { width: 100%; height: 150px; display: block; }
.chart .bar-ok { fill: var(--ok); } .chart .bar-warn { fill: var(--warn); } .chart .bar-err { fill: var(--err); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart-max { font-size: 11px; color: var(--text-3); margin-bottom: 4px; }
.chart .axis { fill: var(--text-3); font-size: 10px; font-family: var(--font); }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 2; }
.chart .area { fill: color-mix(in srgb, var(--primary) 12%, transparent); }
.chart .pt-failed { fill: var(--err); } .chart .pt-warning { fill: var(--warn); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-3); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ── Tabs ── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--primary); border-bottom-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ── Modal & toast ── */
.overlay { position: fixed; inset: 0; background: rgba(8, 18, 38, .55); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
.modal.wide { max-width: 720px; }
.modal-head { padding: 18px 22px 0; }
.modal-head p { color: var(--text-2); margin: 6px 0 0; }
.modal-body { padding: 18px 22px; }
.modal-foot { padding: 14px 22px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
@media (max-width: 900px) { #toasts { left: 12px; right: 12px; bottom: 76px; } }
.toast { background: var(--navy-900); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); font-size: 14px; max-width: 420px; display: flex; gap: 10px; align-items: center; animation: fade .2s; }
.toast.err { background: var(--err); }
.toast.ok svg { stroke: #4ade80; }

/* ── Login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--navy-900); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { color: var(--text); padding: 0 0 20px; }
.login .brand-mark { background: var(--navy-900); }
.login .brand-mark svg { stroke: #fff; }
.login form > * + * { margin-top: 14px; }

.skeleton { background: linear-gradient(90deg, var(--muted-soft), var(--surface-2), var(--muted-soft)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }
.pin { color: var(--primary); }
.sep { color: var(--border-strong); }
.card:has(> .log) { display: flex; flex-direction: column; } .card > .log { flex: 1; }
