:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --ink: #15202b;
  --muted: #5b6b7a;
  --line: #d5dde5;
  --accent: #0f4c81;
  --accent-2: #163a5f;
  --up: #1b7f45;
  --up-bg: #e6f6ec;
  --down: #b42318;
  --down-bg: #fdecea;
  --unk: #5c6770;
  --unk-bg: #eef0f2;
  --warn: #9a6700;
  --warn-bg: #fff6d8;
  --partial: #c69000;
  --partial-bg: #fff6d8;
  --ok: #0d6b3a;
  --ok-bg: #e7f6ee;
  --err: #9b1c1c;
  --err-bg: #fde8e8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  background: var(--accent-2);
  color: #fff;
  padding: .85rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header .brand { font-weight: 700; letter-spacing: .02em; color: #fff; text-decoration: none; }
.app-header nav { display: flex; flex-wrap: wrap; gap: .4rem .7rem; }
.app-header nav a { color: #d7e6f4; text-decoration: none; font-size: .92rem; padding: .25rem .15rem; }
.app-header nav a.active, .app-header nav a:hover { color: #fff; text-decoration: none; }
.nav-toggle { display: none; background: transparent; border: 1px solid #8aa4bf; color: #fff; border-radius: 8px; padding: .35rem .6rem; }

.wrap { width: min(1120px, calc(100% - 1.6rem)); margin: 1.1rem auto 2rem; }
.wrap-wide { width: min(1280px, calc(100% - 1.6rem)); }
.auth-wrap { width: min(480px, calc(100% - 1.6rem)); margin: 3rem auto; }

h1 { font-size: 1.45rem; margin: 0 0 .8rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
.sub { color: var(--muted); margin-top: -.4rem; margin-bottom: 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.grid { display: grid; gap: .8rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat { padding: .9rem 1rem; }
.stat .lbl { color: var(--muted); font-size: .82rem; }
.stat .val { font-size: 1.45rem; font-weight: 700; }

.flash { border-radius: 10px; padding: .7rem .9rem; margin-bottom: .8rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }

.agent-line {
  margin: .4rem 0;
  padding: .4rem .6rem;
  border-radius: 8px;
  border-left: 4px solid transparent;
}
.agent-line.warn { background: var(--warn-bg); border-left-color: var(--warn); }
.agent-line.late { background: var(--down-bg); border-left-color: var(--down); }
.agent-line.inactive { background: var(--unk-bg); border-left-color: var(--unk); }

.pill { display: inline-block; border-radius: 999px; padding: .15rem .55rem; font-size: .78rem; font-weight: 700; letter-spacing: .02em; }
.pill.up { background: var(--up-bg); color: var(--up); }
.pill.down { background: var(--down-bg); color: var(--down); }
.pill.partial { background: var(--partial-bg); color: var(--partial); }
.pill.unknown { background: var(--unk-bg); color: var(--unk); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }

.dots { display: flex; gap: .28rem; align-items: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #c5ced6; }
.dot.up { background: var(--up); }
.dot.down { background: var(--down); }
.dot.partial { background: var(--partial); }

table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .55rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; }
.table-scroll { overflow-x: auto; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: .8rem; margin-bottom: .6rem; }
.section-head h2 { margin: 0; }
.nowrap { white-space: nowrap; }
.incidents-table td.incident-monitor { min-width: 12rem; }
.incidents-table td.incident-reason { color: var(--muted); }

.btn {
  display: inline-block;
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 9px;
  padding: .5rem .85rem;
  font-weight: 600;
  cursor: pointer;
  font-size: .92rem;
}
.btn:hover { background: #0c3d68; text-decoration: none; color: #fff; }
.btn.secondary { background: #e8eef4; color: var(--ink); }
.btn.secondary:hover { background: #d7e1ea; color: var(--ink); }
.btn.danger { background: var(--down); }
.btn.small { padding: .3rem .55rem; font-size: .82rem; }
.btn:disabled,
.btn.is-busy {
  opacity: .7;
  cursor: wait;
  pointer-events: none;
}
.btn-row { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; }
.btn-row form { margin: 0; display: inline-flex; }
.settings-actions { margin-top: .75rem; }

label { display: block; font-size: .85rem; font-weight: 600; margin: .55rem 0 .25rem; }
label.with-hint { display: flex; align-items: center; gap: .4rem; }
.hint {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  background: #eef4fa;
  font-size: .72rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  flex-shrink: 0;
}
.hint-tip {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  width: min(300px, 72vw);
  background: #142433;
  color: #fff;
  font-size: .78rem;
  font-weight: 500;
  line-height: 1.4;
  padding: .55rem .7rem;
  border-radius: 8px;
  z-index: 30;
  box-shadow: var(--shadow);
  transition: opacity .12s ease;
}
.hint-tip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 8px;
  border: 6px solid transparent;
  border-top-color: #142433;
}
.hint:hover .hint-tip,
.hint:focus .hint-tip,
.hint:focus-visible .hint-tip {
  visibility: visible;
  opacity: 1;
}
input, select, textarea {
  width: 100%;
  border: 1px solid #c5d0da;
  border-radius: 8px;
  padding: .5rem .6rem;
  font: inherit;
  background: #fff;
}
textarea { min-height: 90px; }
.help { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.check { display: flex; align-items: center; gap: .45rem; font-weight: 500; }
.check input { width: auto; }
.smtp-box {
  margin: .65rem 0 1rem;
  padding: .75rem .9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7fafc;
}

.monitors-card { padding: .35rem 1.1rem; }
.monitor-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto auto;
  gap: .75rem 1rem;
  align-items: center;
  padding: .7rem 0;
  border-bottom: 1px solid var(--line);
}
.monitor-row:last-child { border-bottom: 0; }
.monitor-row-main { min-width: 0; }
.monitor-row-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.monitor-row-main strong a { color: inherit; text-decoration: none; }
.monitor-row-main strong a:hover { color: var(--accent); text-decoration: underline; }
.status-mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: .68rem;
  line-height: 1;
  flex-shrink: 0;
  background: var(--unk);
}
.status-mark.up { background: var(--up); }
.status-mark.down { background: var(--down); }
.status-mark.partial { background: var(--partial); }
.status-mark::after { content: "▲"; }
.status-mark.down::after { content: "▼"; }
.status-mark.partial::after { content: "◆"; }
.status-mark.unknown::after { content: "-"; }
.monitor-row-hist { text-align: right; }
.hour-bars {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 2px;
  height: 20px;
}
.hour-bar {
  width: 4px;
  height: 18px;
  border-radius: 1px;
  background: #d5dde5;
}
.hour-bar.up { background: var(--up); }
.hour-bar.down { background: var(--down); }
.hour-bar.partial { background: var(--partial); }
.uptime-stats {
  display: flex;
  justify-content: flex-end;
  gap: .85rem;
  margin-top: .25rem;
  font-size: .82rem;
  white-space: nowrap;
}
.monitor-row-actions { justify-content: flex-end; }

.period-form {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem 1rem;
  align-items: flex-end;
}
.period-form label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
.presets a.active-preset { border-color: var(--accent); color: var(--accent); }
.day-bars {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 3px;
  margin: .35rem 0 .15rem;
}
.day-bar {
  display: grid;
  grid-template-rows: repeat(24, 2px);
  flex: 0 0 10px;
  width: 10px;
  min-width: 10px;
  height: 48px;
  border-radius: 2px;
  overflow: hidden;
  background: #d5dde5;
}
.day-hour {
  display: block;
  width: 100%;
  height: 2px;
  margin: 0;
  padding: 0;
  line-height: 0;
  font-size: 0;
  background: #d5dde5;
}
.day-hour.up { background: var(--up); }
.day-hour.down { background: var(--down); }
.day-hour.partial { background: var(--partial); }
.day-hour.empty { background: #d5dde5; }
.day-legend { margin: .5rem 0 0; font-size: .86rem; }
.day-legend strong { font-weight: 700; }
.legend-ok { color: #3bd671; }
.legend-partial { color: #c69000; }
.legend-down { color: #df484a; }
.legend-empty { color: #5c6770; }
.agent-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .8rem;
  margin-bottom: .65rem;
}
.agent-kpis {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem 1.1rem;
  margin: .65rem 0 0;
  font-size: .92rem;
}

.monitor-card {
  display: flex;
  justify-content: space-between;
  gap: .8rem;
  cursor: pointer;
  border: 1px solid var(--line);
  border-left: 5px solid #c5ced6;
}
.monitor-card.up { border-left-color: var(--up); }
.monitor-card.down { border-left-color: var(--down); }
.monitor-card.partial { border-left-color: var(--partial); }
.monitor-card:hover { box-shadow: var(--shadow); }
.muted { color: var(--muted); font-size: .86rem; }
.secret { background: #142433; color: #d7f3c8; padding: .7rem .8rem; border-radius: 8px; word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }

.banner { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.banner.warn { background: var(--warn-bg); color: #5c4300; }
.banner.err { background: var(--err-bg); color: var(--err); }

.modal-bg {
  display: none;
  position: fixed; inset: 0;
  background: rgba(12, 20, 28, .45);
  z-index: 40;
  padding: 1rem;
  overflow: auto;
}
.modal-bg.open { display: block; }
.modal {
  width: min(860px, 100%);
  margin: 1.2rem auto;
  background: #fff;
  border-radius: 14px;
  padding: 1rem 1.1rem 1.2rem;
}
.footer { color: var(--muted); font-size: .8rem; text-align: center; padding: 1.5rem; }

@media (max-width: 900px) {
  .monitor-row {
    grid-template-columns: 28px minmax(0, 1fr);
  }
  .monitor-row-hist,
  .monitor-row-actions {
    grid-column: 2;
    justify-content: flex-start;
  }
  .hour-bars { justify-content: flex-start; }
  .uptime-stats { justify-content: flex-start; }
}
@media (max-width: 800px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-block; }
  .app-header nav { display: none; width: 100%; flex-direction: column; }
  .app-header nav.open { display: flex; }
  .app-header { flex-wrap: wrap; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  td { border-bottom: 0; padding: .25rem 0; }
  tr { border-bottom: 1px solid var(--line); padding: .55rem 0; }
}
