:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --border: #e4e7ec;
  --text: #101828;
  --muted: #667085;
  --accent: #1d4ed8;
  --brand: #1d4ed8;
  --up: #16a34a;
  --up-soft: #dcfce7;
  --partial: #f59e0b;
  --partial-soft: #fef3c7;
  --down: #dc2626;
  --down-soft: #fee2e2;
  --maint: #2563eb;
  --maint-soft: #dbeafe;
  --nodata: #e4e7ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1424;
    --surface: #0f1d33;
    --surface-2: #15253f;
    --border: #1f3252;
    --text: #e6edf7;
    --muted: #8da0bd;
    --accent: #38bdf8;
    --brand: #2dd4bf;
    --up: #22c55e;
    --up-soft: rgba(34, 197, 94, .14);
    --partial: #fbbf24;
    --partial-soft: rgba(251, 191, 36, .14);
    --down: #f87171;
    --down-soft: rgba(248, 113, 113, .14);
    --maint: #60a5fa;
    --maint-soft: rgba(96, 165, 250, .14);
    --nodata: #2a3342;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

.wrap { width: 100%; max-width: 860px; margin: 0 auto; padding: 0 16px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- header ---------- */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; text-decoration: none; }
.brand img { height: 40px; width: 40px; border-radius: 10px; object-fit: cover; display: block; }
.banner { display: block; width: 100%; height: auto; aspect-ratio: 2000 / 968; object-fit: cover; border-radius: var(--radius); margin-bottom: 28px; box-shadow: 0 8px 30px rgba(29, 78, 216, .25); }
.hero h1 { background: linear-gradient(90deg, var(--text), var(--brand)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--up); display: grid; place-items: center; }
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav a { text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-weight: 500; font-size: 14px; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); }
.nav .btn { margin-left: 6px; }
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-left: 6px; }
.lang-switch button { font: inherit; font-size: 12px; font-weight: 700; letter-spacing: .04em; padding: 6px 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.lang-switch button + button { border-left: 1px solid var(--border); }
.lang-switch button:hover { color: var(--text); background: var(--surface-2); }
.lang-switch button.active { background: var(--surface-2); color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 8px; font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--text); color: var(--surface); border-color: var(--text); }
.btn-primary:hover { background: var(--text); opacity: .88; }
.btn-danger { color: var(--down); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.nav a.btn { color: var(--text); padding: 7px 14px; }
.nav a.btn-primary { color: var(--surface); }

/* ---------- hero ---------- */

main { flex: 1; padding-top: 40px; padding-bottom: 48px; }

.hero { text-align: center; margin-bottom: 36px; }
.hero-icon { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; }
.hero-icon svg { width: 32px; height: 32px; }
.hero h1 { font-size: 30px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.02em; }
.hero p { margin: 0; }
.hero-up .hero-icon { background: var(--up-soft); color: var(--up); }
.hero-partial .hero-icon, .hero-incident .hero-icon { background: var(--partial-soft); color: var(--partial); }
.hero-major .hero-icon { background: var(--down-soft); color: var(--down); }
.hero-maintenance .hero-icon { background: var(--maint-soft); color: var(--maint); }
.hero-unknown .hero-icon { background: var(--surface-2); color: var(--muted); }

/* ---------- cards ---------- */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stack > * + * { margin-top: 16px; }
.section-title { font-size: 18px; margin: 40px 0 14px; letter-spacing: -.01em; }
.page-title { font-size: 26px; margin: 0 0 24px; letter-spacing: -.02em; }

.notice { padding: 16px 18px; border-left: 4px solid var(--partial); margin-bottom: 16px; display: block; text-decoration: none; }
.notice.notice-maint { border-left-color: var(--maint); }
.notice.notice-down { border-left-color: var(--down); }
.notice-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.notice-title { font-weight: 600; }
.notice p { margin: 6px 0 0; }

/* ---------- groups / services ---------- */

.group { margin-bottom: 16px; overflow: hidden; }
.group > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 14px 18px; font-weight: 600; user-select: none; }
.group > summary::-webkit-details-marker { display: none; }
.group > summary:hover { background: var(--surface-2); }
.chev { width: 16px; height: 16px; color: var(--muted); transition: transform .15s; flex: none; }
.group[open] .chev { transform: rotate(90deg); }
.group-name { flex: 1; min-width: 0; }

.service { padding: 16px 18px 14px; border-top: 1px solid var(--border); }
.service-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.service-name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.service-link { color: var(--muted); display: inline-flex; }
.service-link svg { width: 14px; height: 14px; }
.service-link:hover { color: var(--text); }
.service-uptime { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.service-desc { margin: -6px 0 10px; font-size: 13px; color: var(--muted); }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--nodata); flex: none; display: inline-block; }
.dot-up { background: var(--up); box-shadow: 0 0 0 3px var(--up-soft); }
.dot-down { background: var(--down); box-shadow: 0 0 0 3px var(--down-soft); animation: pulse 1.6s infinite; }
.dot-maintenance { background: var(--maint); box-shadow: 0 0 0 3px var(--maint-soft); }
.dot-partial { background: var(--partial); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px transparent; } }

.bars { display: flex; gap: 3px; height: 34px; }
.bar { flex: 1 1 0; min-width: 2px; border-radius: 3px; background: var(--nodata); cursor: pointer; transition: opacity .1s; outline: none; }
.bar:hover, .bar:focus-visible { opacity: .7; }
.bar:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.bar-up { background: var(--up); }
.bar-partial { background: var(--partial); }
.bar-down { background: var(--down); }
.bar-maint { background: var(--maint); }
.bars-legend { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge-up, .badge-resolved, .badge-completed { background: var(--up-soft); color: var(--up); }
.badge-down, .badge-investigating { background: var(--down-soft); color: var(--down); }
.badge-identified, .badge-monitoring, .badge-partial { background: var(--partial-soft); color: var(--partial); }
.badge-maintenance, .badge-active, .badge-upcoming { background: var(--maint-soft); color: var(--maint); }

/* ---------- tooltip ---------- */

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; width: max-content; max-width: 260px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .16);
}
.tt-date { font-weight: 600; margin-bottom: 6px; }
.tt-row { display: flex; align-items: center; gap: 8px; }
.tt-row + .tt-row { margin-top: 4px; }
.tt-inc { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.tt-inc div + div { margin-top: 4px; }

/* ---------- incidents ---------- */

.day-label { font-size: 13px; font-weight: 600; color: var(--muted); margin: 22px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.day-label:first-child { margin-top: 0; }
.incident-item { display: block; padding: 16px 18px; text-decoration: none; margin-bottom: 10px; }
.incident-item:hover { border-color: var(--muted); }
.incident-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.incident-title { font-weight: 600; }
.incident-item p { margin: 8px 0 4px; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }
.more-link { display: inline-block; margin-top: 4px; color: var(--accent); font-weight: 600; text-decoration: none; font-size: 14px; }
.more-link:hover { text-decoration: underline; }

.back { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); text-decoration: none; font-size: 14px; margin-bottom: 18px; }
.back:hover { color: var(--text); }
.detail-head { padding: 20px 22px; }
.detail-head h1 { font-size: 22px; margin: 0 0 10px; letter-spacing: -.01em; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 13px; color: var(--muted); margin-top: 12px; }
.meta b { color: var(--text); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { font-size: 12px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }

.timeline { list-style: none; margin: 0; padding: 6px 22px 20px; }
.timeline li { position: relative; padding: 14px 0 14px 26px; border-top: 1px solid var(--border); }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 22px; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.timeline li.tl-resolved::before { background: var(--up); }
.timeline li.tl-investigating::before { background: var(--down); }
.timeline li.tl-identified::before, .timeline li.tl-monitoring::before { background: var(--partial); }
.timeline .tl-status { font-weight: 600; }
.timeline p { margin: 2px 0 4px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- contact ---------- */

.contact-hero { margin-bottom: 28px; }
.contact-hero p { max-width: 520px; margin: 0 auto; }
.contact-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 16px; }
.contact-card { display: flex; align-items: center; gap: 14px; padding: 18px; text-decoration: none; transition: border-color .15s, transform .15s; }
.contact-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.contact-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--maint-soft); color: var(--accent); flex: none; }
.contact-icon svg { width: 22px; height: 22px; }
.contact-text { display: grid; min-width: 0; }
.contact-text b { overflow-wrap: anywhere; }
.contact-go { margin-left: auto; color: var(--muted); font-size: 18px; }
.contact-note { padding: 18px; }
.contact-note p { margin: 4px 0 8px; }

/* ---------- admin ---------- */

.form { padding: 18px; display: grid; gap: 12px; }
.form h3 { margin: 0; font-size: 16px; }
.field { display: grid; gap: 4px; }
.field label, .field .label { font-size: 13px; font-weight: 600; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type="text"], input[type="password"], input[type="datetime-local"], select, textarea {
  width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; }
.checks label { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.admin-item { padding: 14px 18px; border-top: 1px solid var(--border); }
.admin-item:first-of-type { border-top: 0; }
.admin-item .form { padding: 12px 0 0; }
.admin-group { padding: 14px 18px; border-top: 1px solid var(--border); }
.admin-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-row .grow { flex: 1; min-width: 160px; overflow-wrap: anywhere; }
.admin-svc { padding: 10px 0 10px 14px; margin-top: 8px; border-left: 2px solid var(--border); }
.admin-svc .form { padding: 4px 0; }
.btn:disabled { opacity: .4; cursor: default; }
.svc-form[data-type="tcp"] .only-http, .svc-form[data-type="http"] .only-tcp { display: none; }
.cron-url { flex: 1; min-width: 0; overflow-wrap: anywhere; padding: 6px 10px; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }
.toast {
  position: fixed; z-index: 60; left: 50%; bottom: 20px; transform: translateX(-50%);
  max-width: min(520px, calc(100% - 32px)); padding: 12px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
  background: var(--surface); border: 1px solid var(--border);
}
.toast-ok { color: var(--up); border-color: var(--up); }
.toast-err { color: var(--down); border-color: var(--down); }
.msg { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; }
.msg-err { background: var(--down-soft); color: var(--down); }
.msg-ok { background: var(--up-soft); color: var(--up); }

/* ---------- misc ---------- */

.footer { padding-top: 20px; padding-bottom: 28px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); }
.footer a { color: var(--muted); }

.loading { display: grid; place-items: center; min-height: 240px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--muted); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 600px) {
  main { padding-top: 28px; }
  .hero h1 { font-size: 24px; }
  .bars { gap: 2px; height: 30px; }
  .row { grid-template-columns: 1fr; }
  .group > summary, .service { padding-left: 14px; padding-right: 14px; }
}
