:root {
  --ink: #111827;
  --muted: #4B5563;
  --ground: #F4F5F7;
  --card: #FFFFFF;
  --line: #DDE1E7;
  --line-soft: #EEF0F3;
  --field: #C9CFD8;
  --nav: #0F1B2D;
  --nav-active: #22324D;
  --nav-text: #C7D2E3;
  --accent: #1F4FD1;
  --accent-dark: #163A9C;
  --accent-soft: #F2F5FE;
  --notif: #C2570C;
  --notif-soft: #FBF3EC;
  --ok: #14613A; --ok-bg: #E3F4EA;
  --ko: #912018; --ko-bg: #FCE8E6; --danger: #B42318;
  --run: #163A9C; --run-bg: #E6EEFF;
  --stop: #374151; --stop-bg: #EEF0F3;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--ground); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
h1 { margin: 0; font-size: 26px; font-weight: 600; }
h2 { margin: 0; font-size: 17px; font-weight: 600; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Header */
.topbar { height: 64px; display: flex; align-items: center; gap: 32px; padding: 0 32px; background: var(--nav); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; color: #fff; text-decoration: none; white-space: nowrap; }
.brand:hover { color: #fff; }
.topnav { display: flex; gap: 6px; flex-grow: 1; }
.topnav a { color: var(--nav-text); text-decoration: none; padding: 10px 14px; border-radius: 6px; font-size: 15px; }
.topnav a:hover { color: #fff; }
.topnav a.active { color: #fff; background: var(--nav-active); }
.userbox { display: flex; align-items: center; gap: 16px; font-size: 14px; color: var(--nav-text); }
.userbox a, .linkbtn { color: var(--nav-text); background: none; border: 0; font: inherit; font-size: 14px; cursor: pointer; text-decoration: underline; padding: 0; }

main.page { padding: 28px 32px 48px; max-width: 1440px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head .grow { flex-grow: 1; }

/* Cards & forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 500; }
.field .hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=email], select {
  height: 44px; padding: 0 12px; border: 1px solid var(--field); border-radius: 6px; font: inherit; font-size: 15px; background: #fff; color: var(--ink); width: 100%;
}
input.mono, select.mono { font-family: var(--mono); font-size: 14px; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-validation-error, .validation-summary-errors, .text-danger { color: var(--danger); font-size: 13px; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }
.input-validation-error { border-color: var(--danger) !important; }

.btn { height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 18px; border-radius: 6px; font: inherit; font-size: 15px; font-weight: 600; text-decoration: none; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink); white-space: nowrap; }
.btn:hover { background: #F7F8FA; color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-go { height: 52px; font-size: 17px; font-weight: 700; letter-spacing: .5px; width: 100%; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--ko-bg); color: var(--danger); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; font-weight: 500; }

.flash { padding: 12px 16px; border-radius: 6px; background: var(--ok-bg); color: var(--ok); font-size: 14px; }
.flash.error { background: var(--ko-bg); color: var(--ko); }
.flash.info { background: var(--stop-bg); color: var(--stop); }

/* Status pills */
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 3px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st-pending { background: var(--stop-bg); color: var(--stop); }
.st-running { background: var(--run-bg); color: var(--run); }
.st-running .dot { animation: pulse 1.4s infinite; }
.st-ok { background: var(--ok-bg); color: var(--ok); }
.st-ko { background: var(--ko-bg); color: var(--ko); }
.st-stopped { background: var(--stop-bg); color: var(--stop); }
.st-wait { background: var(--run-bg); color: var(--run); }
.st-notif-ko { background: var(--notif-soft); color: #8A3C08; }
@keyframes pulse { 50% { opacity: .3; } }

/* Tables */
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; color: var(--muted); font-weight: 500; padding: 12px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 11px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data td.mono { font-size: 13px; }
table.data tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Login */
.login { min-height: 100vh; display: flex; }
.login-side { width: 44%; max-width: 560px; padding: 64px; background: var(--nav); color: #fff; display: flex; flex-direction: column; justify-content: space-between; }
.login-side h1 { font-size: 40px; line-height: 1.12; }
.login-side p { color: var(--nav-text); font-size: 17px; line-height: 1.6; }
.login-main { flex-grow: 1; display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.login-form { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 18px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: #374151; }

/* Create */
.create-layout { display: flex; gap: 24px; align-items: flex-start; }
.create-layout .main-col { flex-grow: 1; display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.create-layout aside { width: 320px; flex-shrink: 0; display: flex; flex-direction: column; gap: 16px; position: sticky; top: 16px; }
.profiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.profile-card { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 14px; min-height: 140px; text-align: left; font: inherit; color: var(--ink); cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.profile-card svg { width: 100%; height: 48px; }
.profile-card polyline { stroke: #6B7280; }
.profile-card.selected { border: 2px solid var(--accent); background: var(--accent-soft); padding: 13px; }
.profile-card.selected polyline { stroke: var(--accent); }
.profile-card strong { font-size: 15px; }
.profile-card span { font-size: 13px; color: var(--muted); line-height: 1.4; }
.preview { display: flex; gap: 24px; align-items: stretch; }
.preview .chart { flex-grow: 1; border: 1px solid #E5E8ED; border-radius: 6px; padding: 12px 12px 4px; min-width: 0; }
.preview .params { width: 280px; display: flex; flex-direction: column; gap: 12px; }
.note { background: #F4F6FB; border-radius: 6px; padding: 14px; font-size: 14px; line-height: 1.5; color: #374151; }
.dashed { border: 1px dashed var(--field); border-radius: 8px; padding: 16px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.summary-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.summary-row span:first-child { color: var(--muted); }
.sep { height: 1px; background: #E5E8ED; }
.radio-row { display: flex; gap: 16px; flex-wrap: wrap; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 400; }

/* Details */
.progress-card { padding: 16px 20px; gap: 10px; }
.bar { height: 10px; border-radius: 5px; background: #E5E8ED; overflow: hidden; display: flex; }
.bar > div { background: var(--accent); transition: width .5s; }
.bar > div.wait { background: var(--notif); }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-family: var(--mono); font-size: 26px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { font-size: 13px; color: var(--muted); }
.v-ok { color: var(--ok); } .v-ko { color: var(--danger); } .v-notif { color: var(--notif); }
.row2 { display: flex; gap: 16px; align-items: stretch; }
.row2 > .grow { flex-grow: 1; min-width: 0; }
.row2 > .side { width: 420px; flex-shrink: 0; }
.legend { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #374151; }
.legend i { width: 16px; height: 3px; display: inline-block; }
.legend i.dash { height: 0; border-top: 2px dashed #9CA3AF; }
.lat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.lat { background: #F4F6FB; border-radius: 6px; padding: 10px; }
.lat.notif { background: var(--notif-soft); }
.lat .k { font-size: 12px; color: var(--muted); }
.lat .v { font-family: var(--mono); font-size: 17px; white-space: nowrap; }
.histo { display: flex; align-items: flex-end; gap: 6px; height: 110px; border-bottom: 1px solid var(--field); }
.histo div { flex: 1 1 0; background: var(--notif); border-radius: 3px 3px 0 0; min-height: 0; position: relative; }
.histo-labels { display: flex; gap: 6px; }
.histo-labels div { flex: 1 1 0; font-size: 10px; color: var(--muted); text-align: center; font-family: var(--mono); }
.meta { font-size: 14px; color: var(--muted); }
svg text { font-family: var(--mono); }
.chart-svg { width: 100%; height: 280px; display: block; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .row2, .create-layout, .preview { flex-direction: column; }
  .row2 > .side, .create-layout aside, .preview .params { width: 100%; position: static; }
  .profiles, .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .topbar { padding: 0 16px; gap: 12px; height: auto; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  main.page { padding: 20px 16px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-side { display: none; }
}

/* Endpoint / auth */
.target-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.target-fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.target-fieldset.locked input, .target-fieldset.locked select { background: #F7F8FA; color: var(--muted); }
.target-fields { display: flex; flex-direction: column; gap: 14px; }
.hidden-note { display: none; }
.conn-result { border-radius: 6px; padding: 12px 14px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; background: var(--stop-bg); }
.conn-result.ok { background: var(--ok-bg); }
.conn-result.ko { background: var(--ko-bg); }
.conn-result .pill { font-size: 11px; padding: 1px 8px; margin-right: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
