/* Consilio System Management — dashboard styling. Self-contained, no CDN. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --brand: #f29400;
  --brand-dark: #d98500;
  --navy: #242e5d;
  --navy-hover: rgba(255, 255, 255, .09);
  --teal: #019688;
  --link: #b5650a;
  --on-navy: #e9ebf4;
  --on-navy-muted: #a3abca;
  --ok: #1b9e5a;
  --ok-bg: #e6f6ec;
  --warn: #c77800;
  --warn-bg: #fdf3e2;
  --crit: #d23b3b;
  --crit-bg: #fbe8e8;
  --unknown: #7b8794;
  --unknown-bg: #eef1f4;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141b;
    --surface: #172029;
    --surface-2: #1e2a35;
    --border: #2a3846;
    --text: #e6edf3;
    --text-muted: #8b98a5;
    --brand: #f7a827;
    --brand-dark: #f29400;
    --link: #f4a83a;
    --ok: #38c172;
    --ok-bg: #12301f;
    --warn: #e0a030;
    --warn-bg: #33280f;
    --crit: #f26d6d;
    --crit-bg: #331616;
    --unknown: #8b98a5;
    --unknown-bg: #202b35;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout shell */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--navy);
  border-right: none; padding: 20px 0; position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
}
.brand { padding: 0 20px 18px; display: flex; align-items: center; gap: 10px; }
/* The sidebar brand is a link home; it should not look like body copy that got underlined. */
a.brand { color: inherit; }
a.brand:hover { text-decoration: none; }
a.brand:hover .logo { filter: brightness(1.1); }
.brand .logo {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 19px;
  line-height: 1;
}
.brand .title { font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand .sub { font-size: 11px; color: var(--text-muted); }
/* On the navy sidebar the brand text is light; on the (light) login page it stays default. */
.sidebar .brand .title { color: #fff; }
.sidebar .brand .sub { color: var(--on-navy-muted); }
.nav { list-style: none; margin: 0; padding: 8px 12px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--on-navy); font-weight: 500;
}
.nav a:hover { background: var(--navy-hover); text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav .ico { width: 18px; text-align: center; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--on-navy-muted); padding: 14px 24px 4px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 5;
}
.content { padding: 24px; max-width: 1400px; width: 100%; }

/* Topbar user menu */
.usermenu { position: relative; }
.usermenu-trigger {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--text);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.usermenu-trigger:hover { background: var(--surface-2); }
.usermenu.open .usermenu-trigger { background: var(--surface-2); border-color: var(--border); }
.usermenu .avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand); color: #fff;
}
.usermenu .avatar svg { width: 16px; height: 16px; }
.usermenu-caret { width: 12px; height: 12px; color: var(--text-muted); transition: transform .15s ease; }
.usermenu.open .usermenu-caret { transform: rotate(180deg); }

.usermenu-panel {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; z-index: 20;
  display: none;
}
.usermenu.open .usermenu-panel { display: block; }
.usermenu-panel form { margin: 0; }
.usermenu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: 7px; border: 0; background: transparent;
  color: var(--text); font-size: 13px; font-weight: 500; text-align: left;
  cursor: pointer; text-decoration: none;
}
.usermenu-item:hover { background: var(--surface-2); text-decoration: none; }
.usermenu-item svg { width: 16px; height: 16px; color: var(--text-muted); flex: none; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; }
.muted { color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--crit); border-color: var(--crit); background: transparent; }
.btn-danger:hover { background: var(--crit-bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Segmented filter chips (job type on the backup lists) */
.filter-bar { display: inline-flex; gap: 4px; padding: 3px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 7px;
  color: var(--text-muted); font-size: 12.5px; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.filter-chip:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.filter-chip.active { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--brand); }
.filter-chip .n { font-weight: 500; font-size: 11.5px; color: var(--text-muted); }

/* Summary stat row */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .n { font-size: 28px; font-weight: 700; line-height: 1; }
.stat .l { font-size: 12px; color: var(--text-muted); margin-top: 6px; text-transform: uppercase; letter-spacing: .04em; }
.stat.ok .n { color: var(--ok); }
.stat.warn .n { color: var(--warn); }
.stat.crit .n { color: var(--crit); }

/* Status tiles that double as toggle filters */
.stat-filter {
  font: inherit; text-align: left; color: inherit; width: 100%;
  cursor: pointer; transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}
.stat-filter:hover { border-color: var(--text-muted); }
.stat-filter:focus-visible { outline: none; border-color: var(--text-muted); }
.stat-filter[aria-pressed="true"] { background: var(--surface-2, rgba(255,255,255,.04)); }
.stat-filter.ok[aria-pressed="true"] { border-color: var(--ok); box-shadow: inset 0 0 0 1px var(--ok); }
.stat-filter.warn[aria-pressed="true"] { border-color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.stat-filter.crit[aria-pressed="true"] { border-color: var(--crit); box-shadow: inset 0 0 0 1px var(--crit); }

/* Agent cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; border-left: 4px solid var(--unknown);
  position: relative; cursor: pointer; transition: box-shadow .12s ease, border-color .12s ease;
}
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.28); border-color: var(--text-muted); }
.card.filtered-out { display: none; }
.card.ok { border-left-color: var(--ok); }
.card.warn { border-left-color: var(--warn); }
.card.crit { border-left-color: var(--crit); }
.card.unknown { border-left-color: var(--unknown); }
.card-head { padding: 14px 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-head .name { font-weight: 600; font-size: 15px; }
.card-head .name a { color: var(--text); }
/* Stretch the agent link across the whole tile so the entire card is clickable. */
.card-head .name a.card-link::after { content: ""; position: absolute; inset: 0; z-index: 1; }
.card-head .name a.card-link:hover { text-decoration: none; }
.card-head .meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.card-body { padding: 0 16px 14px; }
.card-reason { font-size: 12.5px; color: var(--text-muted); margin-bottom: 10px; }
/* Make the health reason pop in the status colour when something is wrong. */
.card-reason.warn { color: var(--warn); font-weight: 600; }
.card-reason.crit { color: var(--crit); font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12.5px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; text-align: right; }

/* Status pills / dots */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; 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.crit { background: var(--crit-bg); color: var(--crit); }
.pill.unknown { background: var(--unknown-bg); color: var(--unknown); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* Tables */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.grid th { background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; }
table.grid tr:last-child td { border-bottom: none; }
table.grid tr:hover td { background: var(--surface-2); }

/* Metric detail (e.g. top processes) nested under a metric row */
table.grid tr.detail-row td { background: var(--bg); padding: 10px 14px 14px; }
table.grid tr.detail-row:hover td { background: var(--bg); }
.detail-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
table.grid.subgrid { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
table.grid.subgrid th, table.grid.subgrid td { padding: 6px 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Disk bars */
.meter { background: var(--surface-2); border-radius: 6px; height: 10px; overflow: hidden; min-width: 120px; }
.meter > span { display: block; height: 100%; background: var(--ok); border-radius: 6px; }
.meter.warn > span { background: var(--warn); }
.meter.crit > span { background: var(--crit); }
.disk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.disk { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.disk .top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.disk .vol { font-weight: 600; }
.disk .pct { font-weight: 700; font-size: 18px; }
.disk .foot { font-size: 12px; color: var(--text-muted); margin-top: 8px; display: flex; justify-content: space-between; }

/* Database cards (SQL-backup agents) */
.db-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.db { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.db .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; }
.db .vol { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db .db-pct { display: flex; align-items: baseline; gap: 6px; margin-bottom: 6px; }
.db .db-pct .pct { font-weight: 700; font-size: 16px; }
.db .foot { font-size: 12px; color: var(--text-muted); margin-top: 8px; display: flex; justify-content: space-between; gap: 8px; }
.db .db-kv { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--border); }
.db .frag.ok { color: var(--ok); font-weight: 600; }
.db .frag.warn { color: var(--warn); font-weight: 600; }
.db .frag.crit { color: var(--crit); font-weight: 600; }

/* Forms */
.form { max-width: 520px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.form .field { margin-bottom: 16px; }
.form label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 13px; }
.form input, .form select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 14px;
}
.form input:focus, .form select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.field-error, .validation-summary-errors { color: var(--crit); font-size: 12.5px; margin-top: 4px; }
.field-hint { display: block; color: var(--text-muted); font-size: 12.5px; margin-top: 4px; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }

/* Password reveal toggle */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 7px;
  background: transparent; border: 0; padding: 0; cursor: pointer;
  color: var(--text-muted);
}
.pw-toggle:hover { background: var(--surface-2); color: var(--text); }
.pw-toggle svg { width: 17px; height: 17px; }
.pw-toggle .pw-eye-off { display: none; }
.pw-toggle.revealed .pw-eye { display: none; }
.pw-toggle.revealed .pw-eye-off { display: inline; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 13.5px; }
.alert.info { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }

/* Key reveal */
.keybox { font-family: "Cascadia Code", Consolas, monospace; background: var(--surface-2);
  border: 1px dashed var(--brand); padding: 14px; border-radius: 8px; word-break: break-all;
  font-size: 14px; user-select: all; }

/* Login */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; padding-bottom: 22px; }

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

@media (max-width: 820px) {
  .sidebar { position: fixed; transform: translateX(-100%); z-index: 20; transition: transform .2s; }
  .sidebar.open { transform: none; }
  .content { padding: 16px; }
}

/* ---------------------------------------------------------------------------
   Dialogs
   A <dialog> has no surface of its own: unstyled it renders on the browser's
   white default with no backdrop, which on a dark page reads as the content
   behind bleeding through. Styling it once here means a dialog never has to
   carry inline styles again.
   --------------------------------------------------------------------------- */
dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 24px 60px rgb(0 0 0 / .55);
  padding: 0; max-width: min(560px, 92vw); width: 100%;
}
dialog::backdrop { background: rgb(0 0 0 / .55); }
dialog .form { max-width: none; border: 0; box-shadow: none; background: transparent; }
dialog h2 { font-size: 16px; margin: 0 0 16px; }
dialog select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 14px;
}
dialog select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.dialog-actions { display: flex; gap: 8px; margin-top: 20px; }

/* ---------------------------------------------------------------------------
   Customers: one row per setting
   --------------------------------------------------------------------------- */
.add-customer { margin-bottom: 18px; padding: 16px; }

/* A form laid out along a row. Fields size themselves; only .grow takes the slack. */
.row-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row-form .row-field { display: flex; flex-direction: column; gap: 4px; }
.row-form .row-field.grow { flex: 1; min-width: 180px; }
.row-form label { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }
.row-form input {
  padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 13.5px;
}
.row-form input:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

.customer { margin-bottom: 14px; }
.customer-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.customer-head h2 { font-size: 15px; margin: 0; }
.customer-head .slug { font-weight: 400; font-size: 12px; margin-left: 6px; }
.customer-actions { display: flex; align-items: center; gap: 8px; }
.customer-actions .muted { font-size: 12px; margin-right: 4px; }
form.inline { display: inline; margin: 0; }

.settings { display: flex; flex-direction: column; }

/* key | value | remove — the key column is wide enough for the longest of them
   (private-connection-host) so the values line up down the page. */
.setting-row {
  display: grid; grid-template-columns: 210px 1fr auto;
  gap: 12px; align-items: center;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-row:hover { background: var(--surface-2); }
.setting-key {
  font-family: "Cascadia Code", Consolas, monospace; font-size: 12.5px;
  color: var(--text-muted); display: flex; align-items: center; gap: 8px;
}
.setting-row .pill { font-size: 10px; padding: 1px 6px; }
.setting-value { display: flex; gap: 8px; align-items: center; margin: 0; }
.setting-value input {
  flex: 1; min-width: 0;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg); color: var(--text); font-size: 13px;
}
.setting-value input:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.setting-value .pw-wrap { flex: 1; display: flex; }
.setting-value .pw-wrap input { padding-right: 60px; }
.setting-value-ro { font-size: 13px; }
.pw-toggle .pw-eye, .pw-toggle .pw-eye-off { font-size: 11px; }

@media (max-width: 820px) {
  .setting-row { grid-template-columns: 1fr; gap: 6px; }
  .customer-head { flex-wrap: wrap; }
}

/* A settings row whose value has been edited but not yet saved. The brand orange rather than a
   warning colour: nothing is wrong, there is just something outstanding — and after the save the
   page reloads, so it goes back on its own. */
.btn.unsaved {
  background: var(--brand); border-color: var(--brand); color: #fff;
}
.btn.unsaved:hover { background: var(--brand-dark); }

/* The Refresh-lists strip above the Customers page */
.lookup-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.lookup-bar .muted { font-size: 12.5px; }

/* Customer disclosure: shut by default, so the page reads as a list of customers */
.disclose {
  background: transparent; border: 0; padding: 2px 4px; cursor: pointer;
  color: var(--text-muted); line-height: 1; font-size: 13px;
}
.disclose:hover { color: var(--text); }
.disclose .chev { display: block; transition: transform .15s ease; }
.disclose.open .chev { transform: rotate(90deg); }
.customer-head h2.clickable { cursor: pointer; }
.customer-head h2.clickable:hover { color: var(--brand); }
.customer-body { border-top: 0; }

@media (prefers-reduced-motion: reduce) {
  .disclose .chev { transition: none; }
}

/* The Add-setting dialog's value select, sized like the inputs beside it */
dialog #a-value-select { width: 100%; }
