/* Checkmk Multi-Site Dashboard */

:root {
  --bg: #0e1117;
  --surface: #161a22;
  --surface-2: #1d222c;
  --border: #272d39;
  --text: #e7eaf0;
  --muted: #8d95a8;
  --accent: #4c8dff;

  --ok: #2fbf71;
  --warn: #f2c94c;
  --crit: #ef4b55;
  --unknown: #f2913d;
  --pending: #8d95a8;

  --ok-bg: rgba(47, 191, 113, .12);
  --warn-bg: rgba(242, 201, 76, .13);
  --crit-bg: rgba(239, 75, 85, .15);
  --unknown-bg: rgba(242, 145, 61, .14);
  --pending-bg: rgba(141, 149, 168, .14);

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f6f7fa;
    --border: #dde1e8;
    --text: #1a1f2b;
    --muted: #5e6678;
    --accent: #2563eb;
    --ok: #138a4f;
    --warn: #a77a00;
    --crit: #cf2632;
    --unknown: #c9600d;
    --pending: #6b7385;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .9em; }
td.mono { white-space: nowrap; }
h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn-text { color: var(--warn); }

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .7rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; font-weight: 650; letter-spacing: .01em; }
.brand-mark { width: 14px; height: 14px; border-radius: 4px; background: linear-gradient(135deg, var(--ok), var(--accent)); }
.nav { display: flex; align-items: center; gap: .25rem; }
.nav a, .linklike {
  color: var(--muted); text-decoration: none; padding: .35rem .65rem; border-radius: 6px;
  font: inherit; background: none; border: 0; cursor: pointer;
}
.nav a:hover, .linklike:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface-2); }
.nav-logout { margin: 0; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .9rem; }

.pill {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .3rem .8rem; border-radius: 999px; font-weight: 600; font-size: .85rem;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-ok { color: var(--ok); background: var(--ok-bg); }
.pill-warn { color: var(--warn); background: var(--warn-bg); }
.pill-crit { color: var(--crit); background: var(--crit-bg); }
.pill-crit::before { animation: pulse 1.6s ease-in-out infinite; }
.pill-notreporting { color: var(--unknown); background: var(--unknown-bg); }
.pill-nodata { color: var(--pending); background: var(--pending-bg); }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .pill-crit::before { animation: none; } }

/* ------------------------------------------------------------------ main */

.main { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
.main.wide { max-width: none; }
.block { margin-top: 1.75rem; }
.block-head { display: flex; align-items: baseline; gap: 1rem; margin-bottom: .75rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1.25rem;
}
.card.narrow { max-width: 420px; margin: 3rem auto; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.flash-success { background: var(--ok-bg); border-color: var(--ok); }
.flash-error { background: var(--crit-bg); border-color: var(--crit); }

/* --------------------------------------------------------------- summary */

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; min-height: 116px;
}
.stat.skeleton { opacity: .5; }
.stat-title { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat-main { font-size: 2.1rem; font-weight: 700; line-height: 1.2; margin: .2rem 0 .45rem; }
.stat-parts { display: flex; flex-wrap: wrap; gap: .25rem .9rem; font-size: .88rem; }
.part.zero { color: var(--muted); opacity: .7; }

.st-ok { color: var(--ok); }
.st-warn { color: var(--warn); }
.st-crit { color: var(--crit); }
.st-unknown { color: var(--unknown); }
.st-pending { color: var(--pending); }

/* ----------------------------------------------------------------- sites */

.site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: .9rem; }
.site {
  all: unset; box-sizing: border-box; cursor: pointer;
  display: flex; flex-direction: column; gap: .55rem;
  background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--pending);
  border-radius: var(--radius); padding: .85rem 1rem;
  transition: border-color .15s, transform .15s;
}
.site:hover { transform: translateY(-1px); border-color: var(--muted); }
.site:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.site.selected { box-shadow: 0 0 0 2px var(--accent); }
.site-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.site-name { font-weight: 650; font-size: 1.02rem; min-width: 0; overflow-wrap: anywhere; }
.site-badge { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: .15rem .5rem; border-radius: 5px; white-space: nowrap; flex-shrink: 0; margin-top: .15rem; }
.site-counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: .35rem; }
.cnt { display: flex; flex-direction: column; align-items: flex-start; }
.cnt b { font-size: 1.45rem; line-height: 1.1; }
.cnt small { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.cnt.zero b { color: var(--muted); opacity: .45; }
.site-sub, .site-msg { margin: 0; font-size: .85rem; color: var(--muted); }
.site-msg { color: var(--text); }
.site-foot { font-size: .76rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: .45rem; margin-top: auto; }

.site-ok { border-left-color: var(--ok); }
.site-ok .site-badge { color: var(--ok); background: var(--ok-bg); }
.site-warn { border-left-color: var(--warn); }
.site-warn .site-badge { color: var(--warn); background: var(--warn-bg); }
.site-crit { border-left-color: var(--crit); background: linear-gradient(90deg, var(--crit-bg), var(--surface) 60%); }
.site-crit .site-badge { color: var(--crit); background: var(--crit-bg); }
.site-error, .site-stale { border-left-color: var(--unknown); background: repeating-linear-gradient(135deg, var(--surface), var(--surface) 12px, var(--surface-2) 12px, var(--surface-2) 24px); }
.site-error .site-badge, .site-stale .site-badge { color: var(--unknown); background: var(--unknown-bg); }
.site-nodata .site-badge { color: var(--pending); background: var(--pending-bg); }

/* -------------------------------------------------------------- problems */

.count-badge { display: inline-block; min-width: 1.8em; text-align: center; font-size: .8rem; padding: .1rem .45rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); vertical-align: middle; margin-left: .3rem; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; margin-bottom: .8rem; }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
  padding: .3rem .7rem; border-radius: 999px;
  background: transparent; border: 1px solid var(--border); color: var(--muted);
}
.chip.on.st-crit { color: var(--crit); background: var(--crit-bg); border-color: transparent; }
.chip.on.st-warn { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.chip.on.st-unknown { color: var(--unknown); background: var(--unknown-bg); border-color: transparent; }
.chip:not(.on) { text-decoration: line-through; opacity: .7; }
.toggle { display: inline-flex; align-items: center; gap: .35rem; font-size: .88rem; color: var(--muted); cursor: pointer; }
#f-search { flex: 1 1 220px; max-width: 360px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 7px; padding: .45rem .6rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type="checkbox"] { padding: 0; width: auto; accent-color: var(--accent); }
.input-num { width: 5em; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.handled td { opacity: .55; }

.problems .state-cell { white-space: nowrap; }
.problems .site-cell { white-space: nowrap; color: var(--muted); }
.problems .host-cell { font-weight: 600; white-space: nowrap; }
.problems .svc-cell { word-break: break-word; }
.problems .output-cell { color: var(--muted); font-family: var(--mono); font-size: .82rem; max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-block; min-width: 4.6em; text-align: center;
  font-size: .72rem; font-weight: 700; letter-spacing: .05em;
  padding: .2rem .45rem; border-radius: 5px;
}
.badge.st-ok { background: var(--ok-bg); }
.badge.st-warn { background: var(--warn-bg); }
.badge.st-crit { background: var(--crit-bg); }
.badge.st-unknown { background: var(--unknown-bg); }
.badge.st-pending { background: var(--pending-bg); }
.tag { display: inline-block; margin-left: .35rem; font-size: .7rem; padding: .05rem .4rem; border-radius: 4px; border: 1px solid var(--border); color: var(--muted); vertical-align: 1px; }
.tag-ack { border-color: var(--accent); color: var(--accent); }
.tag-dt { border-color: var(--pending); }

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

.conn-error {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%);
  background: var(--crit); color: #fff; padding: .6rem 1rem; border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.35); font-weight: 600; max-width: calc(100% - 2rem);
}

/* ----------------------------------------------------------------- forms */

.form { display: flex; flex-direction: column; gap: .85rem; }
.form label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--muted); }
.form-inline { display: flex; flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: .75rem; }
.form-inline label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--muted); }
.form-inline.tight { gap: .4rem; align-items: center; flex-wrap: nowrap; }
.btn {
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  padding: .5rem .9rem; border-radius: 7px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); border-color: var(--accent); }
.btn-danger { color: var(--crit); }
.btn-small { padding: .3rem .6rem; font-size: .8rem; }
td.actions { min-width: 200px; }
td.actions form { display: flex; gap: .35rem; flex-wrap: wrap; margin: 0; }
table.admin input[name="name"] { width: 100%; min-width: 160px; }
.card > h2 { margin-bottom: .8rem; }

.keybox { border: 1px solid var(--accent); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.25rem; background: var(--surface-2); }
.keybox p { margin: .4rem 0 .8rem; }
.keybox pre { background: var(--bg); padding: .8rem; border-radius: 7px; overflow-x: auto; font-family: var(--mono); font-size: .82rem; }

/* --------------------------------------------------------------- kiosk */

.is-kiosk .main { padding: 1rem 1.25rem; }

@media (max-width: 640px) {
  .main { padding: 1rem; }
  .topbar { gap: .6rem; padding: .6rem 1rem; }
  .topbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
  .problems .output-cell { max-width: 220px; }
  .stat-main { font-size: 1.7rem; }
}
