:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --border: #e3e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --up: #16a34a;
  --up-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --down: #dc2626;
  --down-bg: #fee2e2;
  --paused: #64748b;
  --paused-bg: #e2e8f0;
  --pending: #6366f1;
  --pending-bg: #e0e7ff;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .04);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111a2e;
    --surface-2: #17223a;
    --border: #23304a;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --up: #22c55e;
    --up-bg: rgba(34, 197, 94, .15);
    --warn: #f59e0b;
    --warn-bg: rgba(245, 158, 11, .15);
    --down: #f87171;
    --down-bg: rgba(248, 113, 113, .15);
    --paused: #94a3b8;
    --paused-bg: rgba(148, 163, 184, .15);
    --pending: #a5b4fc;
    --pending-bg: rgba(129, 140, 248, .15);
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .92em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand-lg { font-size: 22px; justify-content: center; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M5 17h5l3-7 5 13 3-6h6' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat;
}

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: var(--down); border-color: var(--down); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  position: relative; border: 0; background: transparent; cursor: pointer; border-radius: 8px;
  width: 34px; height: 34px; display: inline-grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.login-card p { text-align: center; margin: -4px 0 6px; }

/* ---------- forms ---------- */
label { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }
label .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 8px 10px; font-weight: 400; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 60px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid > label { align-content: end; }
.form-error { color: var(--down); font-size: 13px; min-height: 1em; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 0; }
legend { font-weight: 700; padding: 0 6px; font-size: 13px; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-search { flex: 1; max-width: 480px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.live { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; margin-right: 8px; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--up); box-shadow: 0 0 0 3px var(--up-bg); }
.live.stale::before { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.badge {
  position: absolute; top: 1px; right: 0; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--down); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 40px; min-width: 230px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 6px; display: grid;
}
.menu button { border: 0; background: transparent; text-align: left; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.menu-user { padding: 6px 10px 8px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }

/* ---------- layout ---------- */
.container { max-width: 1320px; margin: 0 auto; padding: 20px 24px 60px; display: grid; gap: 18px; }
.banner { border-radius: 10px; padding: 12px 16px; font-weight: 500; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.danger { background: var(--down-bg); color: var(--down); display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.banner.danger strong { margin-right: 4px; }
.banner.danger a { color: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; }

.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.tile .k { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile.up .v { color: var(--up); }
.tile.failing .v { color: var(--warn); }
.tile.down .v { color: var(--down); }
.tile.paused .v { color: var(--paused); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px;
  cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted);
}
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .n { opacity: .7; margin-left: 4px; font-weight: 500; }

/* ---------- customer card ---------- */
#customers { display: grid; gap: 16px; }
.customer {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.customer.has-down { border-color: var(--down); }
.customer-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.customer-head h3 { margin: 0; font-size: 16px; }
.customer-meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 14px; flex-wrap: wrap; }
.customer-head .spacer { flex: 1; }
.counts { display: flex; gap: 6px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 600; padding: 8px 12px; background: var(--surface-2); white-space: nowrap;
}
td { padding: 10px 12px; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--surface-2); }
tr.row-down td { background: color-mix(in srgb, var(--down-bg) 50%, transparent); }
td.ep-name { min-width: 220px; }
td.ep-name .n { font-weight: 600; }
td.ep-name .u { color: var(--muted); font-size: 12px; word-break: break-all; }
td.ep-name .err { color: var(--down); font-size: 12px; margin-top: 2px; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .icon-btn { width: 30px; height: 30px; }
.empty { padding: 22px 18px; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.Up { color: var(--up); background: var(--up-bg); }
.pill.Failing { color: var(--warn); background: var(--warn-bg); }
.pill.Down { color: var(--down); background: var(--down-bg); }
.pill.Down::before { animation: pulse 1.4s ease-in-out infinite; }
.pill.Paused { color: var(--paused); background: var(--paused-bg); }
.pill.Pending { color: var(--pending); background: var(--pending-bg); }
@keyframes pulse { 50% { opacity: .25; } }
.mini { font-size: 11.5px; font-weight: 700; border-radius: 6px; padding: 1px 7px; }
.mini.Up { color: var(--up); background: var(--up-bg); }
.mini.Failing { color: var(--warn); background: var(--warn-bg); }
.mini.Down { color: var(--down); background: var(--down-bg); }
.mini.Paused { color: var(--paused); background: var(--paused-bg); }

.spark { display: flex; gap: 2px; align-items: flex-end; height: 22px; }
.spark i { display: block; width: 4px; border-radius: 1px; background: var(--up); opacity: .85; }
.spark i.bad { background: var(--down); height: 22px !important; }
.spark.empty-spark { color: var(--muted); font-size: 12px; align-items: center; }

.fails { font-variant-numeric: tabular-nums; }
.fails.hot { color: var(--down); font-weight: 700; }
.fails.warm { color: var(--warn); font-weight: 700; }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--surface);
  border-left: 1px solid var(--border); z-index: 50; display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 16px; }
.notif-list { overflow-y: auto; flex: 1; }
.notif { display: grid; grid-template-columns: 10px 1fr; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif:hover { background: var(--surface-2); }
.notif .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; }
.notif.down .dot { background: var(--down); }
.notif.recovered .dot { background: var(--up); }
.notif.email-failed .dot { background: var(--warn); }
.notif .t { font-weight: 600; }
.notif.read { opacity: .62; }
.notif.read .t { font-weight: 500; }
.notif .m { color: var(--muted); font-size: 12.5px; word-break: break-word; }
.notif .time { color: var(--muted); font-size: 11.5px; margin-top: 3px; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); border: 1px solid var(--border);
}
.modal.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px 20px; overflow-y: auto; }

.hist-chart { display: flex; gap: 2px; align-items: flex-end; height: 90px; padding: 8px 0; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.hist-chart i { flex: 1 1 0; min-width: 2px; max-width: 10px; background: var(--up); border-radius: 2px 2px 0 0; opacity: .85; }
.hist-chart i.bad { background: var(--down); }
.kv { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.kv div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.kv .k { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kv .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.hist-table td { padding: 6px 10px; font-size: 13px; cursor: default; }
.hist-table tbody tr:hover td { background: transparent; }
.ok-txt { color: var(--up); font-weight: 700; }
.bad-txt { color: var(--down); font-weight: 700; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: grid; gap: 10px; width: min(380px, calc(100vw - 36px)); }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 10px;
  padding: 12px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.18); animation: slidein .25s ease-out;
}
.toast.down { border-left-color: var(--down); }
.toast.recovered { border-left-color: var(--up); }
.toast.email-failed, .toast.warn { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--down); }
.toast .t { font-weight: 700; }
.toast .m { color: var(--muted); font-size: 12.5px; word-break: break-word; }
@keyframes slidein { from { transform: translateY(12px); opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .col-spark, .col-uptime { display: none; }
}
@media (max-width: 680px) {
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .topbar-search { order: 3; max-width: none; flex-basis: 100%; }
  .container { padding: 16px 16px 60px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .col-interval, .col-code, .col-last { display: none; }
  .live { display: none; }
}
