/*
 * Sentinel dashboard — hand-written, no framework, no build step.
 *
 * Dark by default because this is looked at during incidents, often at night.
 * System fonts only: a webfont means a network request, and a network request
 * from a security dashboard means either a CDN in the CSP or a self-hosted file
 * for no benefit.
 *
 * Roughly 450 lines. If it starts needing a preprocessor, something has gone
 * wrong with the scope of the interface.
 */

:root {
  --bg:        #0f1115;
  --bg-raised: #161a21;
  --bg-input:  #1c2129;
  --border:    #262c36;
  --border-lit:#333b47;

  --fg:        #e4e7ec;
  --fg-muted:  #8b939f;
  --fg-dim:    #5d6673;

  --accent:    #4c8dff;
  --accent-dim:#2f5fa8;

  --ok:        #35c07f;
  --warn:      #e0a33e;
  --bad:       #e5544b;
  --off:       #5d6673;

  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Light mode is offered rather than forced: some people work in bright rooms,
   and a dashboard that is unreadable in daylight gets checked less often. */
@media (prefers-color-scheme: light) {
  :root {
    --bg:        #f7f8fa;
    --bg-raised: #ffffff;
    --bg-input:  #ffffff;
    --border:    #dfe3e8;
    --border-lit:#c6ccd4;
    --fg:        #1a1d23;
    --fg-muted:  #5d6673;
    --fg-dim:    #8b939f;
    --accent:    #1f6feb;
    --accent-dim:#c2d8f7;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0 1.25rem;
  height: 52px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--fg);
  text-decoration: none;
  font-size: 1.05rem;
}

/* A CSS-only mark: an <img> or an inline SVG sprite would be another asset to
   ship and another CSP consideration for no visual gain at this size. */
.brand-mark {
  width: 14px; height: 14px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--ok));
  flex: none;
}
.brand-mark-lg { width: 26px; height: 26px; border-radius: 6px; }

.nav { display: flex; gap: .25rem; margin-left: .5rem; }
.nav a {
  color: var(--fg-muted);
  text-decoration: none;
  padding: .3rem .7rem;
  border-radius: var(--radius);
  font-size: .92rem;
}
.nav a:hover { color: var(--fg); background: var(--bg-input); }
.nav a.active { color: var(--fg); background: var(--bg-input); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .75rem;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-size: .9rem;
  color: var(--fg-muted);
}

.role {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .12rem .4rem;
  border-radius: 3px;
  border: 1px solid var(--border-lit);
  color: var(--fg-dim);
}
.role-owner    { color: var(--accent); border-color: var(--accent-dim); }
.role-operator { color: var(--warn); border-color: var(--warn); }

form.inline { display: inline; margin: 0; }

/* ---------------------------------------------------------------- layout */
.shell {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

.auth-shell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
}

.footer {
  padding: .9rem 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--fg-dim);
  font-size: .8rem;
  display: flex;
  gap: .5rem;
}

h1 { font-size: 1.4rem; font-weight: 600; margin: 0 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1rem;  font-weight: 600; margin: 2rem 0 .6rem; }
.card h2 { margin: 0 0 .8rem; font-size: .82rem; text-transform: uppercase;
           letter-spacing: .06em; color: var(--fg-muted); }

/* ---------------------------------------------------------------- auth card */
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.75rem;
}

.auth-head { text-align: center; margin-bottom: 1.5rem; }
.auth-head h1 { margin: .6rem 0 .2rem; font-size: 1.25rem; }
.auth-head p { margin: 0; font-size: .85rem; }
.auth-note {
  margin: 1.25rem 0 0;
  font-size: .78rem;
  color: var(--fg-dim);
  line-height: 1.5;
}
.auth-alt { margin-top: .6rem; }

/* ---------------------------------------------------------------- forms */
label {
  display: block;
  font-size: .85rem;
  font-weight: 500;
  color: var(--fg-muted);
  margin: 1rem 0 .35rem;
}

input[type="text"], input[type="password"], input[type="email"] {
  width: 100%;
  padding: .6rem .7rem;
  background: var(--bg-input);
  border: 1px solid var(--border-lit);
  border-radius: var(--radius);
  color: var(--fg);
  font: inherit;
}
input:focus-visible {
  outline: none;
  border-color: var(--accent);
  /* A visible focus ring, not a removed one. Keyboard users exist. */
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.code-input {
  font: 600 1.5rem/1 var(--mono);
  letter-spacing: .35em;
  text-align: center;
  padding: .75rem .5rem;
}

.btn {
  display: inline-block;
  padding: .55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-lit);
  background: var(--bg-input);
  color: var(--fg);
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
.btn:hover { border-color: var(--fg-dim); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-quiet { background: transparent; color: var(--fg-muted); }
.btn-quiet:hover { color: var(--fg); }
.btn-block { display: block; width: 100%; margin-top: 1.25rem; }

/* ---------------------------------------------------------------- notices */
.notice {
  border: 1px solid var(--border-lit);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: var(--bg-raised);
  padding: .8rem 1rem;
  margin-bottom: 1rem;
  font-size: .9rem;
}
.notice strong { display: block; margin-bottom: .25rem; }
.notice p { margin: 0; color: var(--fg-muted); line-height: 1.5; }

.notice-info     { border-left-color: var(--accent); }
.notice-warn     { border-left-color: var(--warn); }
.notice-critical { border-left-color: var(--bad); }

.alert {
  padding: .6rem .75rem;
  border-radius: var(--radius);
  font-size: .88rem;
  margin: 0 0 1rem;
}
.alert-error {
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent);
  color: var(--fg);
}

/* ---------------------------------------------------------------- cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem 1.15rem;
}

.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; }
.kv dt { color: var(--fg-muted); font-size: .87rem; }
.kv dd { margin: 0; font-size: .87rem; text-align: right; }

/* Status dot. Colour alone is never the only signal — every dot sits next to a
   word ("activ", "oprit"), so it still reads correctly without colour vision. */
.dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: .35rem;
  vertical-align: baseline;
}
.dot-ok   { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-bad  { background: var(--bad); }
.dot-off  { background: var(--off); }

/* ---------------------------------------------------------------- tables */
.table-scroll {
  /* Wide tables scroll inside their own box; the page body never scrolls
     sideways, which is what makes this usable on a phone during an incident. */
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-raised);
}

table { width: 100%; border-collapse: collapse; font-size: .87rem; }
thead th {
  text-align: left;
  font-weight: 500;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--fg-muted);
  padding: .6rem .8rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: .55rem .8rem; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-input); }
tr.row-bad td:first-child { box-shadow: inset 2px 0 0 var(--bad); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .6rem 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.list li:last-child { border-bottom: none; }

.badge {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .1rem .35rem;
  border-radius: 3px;
  background: var(--accent-dim);
  color: var(--fg);
}

/* ---------------------------------------------------------------- utility */
.mono   { font-family: var(--mono); font-size: .92em; }
.muted  { color: var(--fg-muted); }
.small  { font-size: .8rem; }
.nowrap { white-space: nowrap; }

.truncate {
  display: inline-block;
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .08em .35em;
  /* Long paths and commands must wrap rather than force a horizontal scroll. */
  word-break: break-word;
}

/* ---------------------------------------------------------------- motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------- narrow */
@media (max-width: 560px) {
  .topbar { height: auto; padding: .6rem 1rem; gap: .6rem; }
  .topbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
  .nav { margin-left: 0; }
  .shell { padding: 1.25rem 1rem 2.5rem; }
  .kv { grid-template-columns: 1fr; gap: .15rem; }
  .kv dd { text-align: left; margin-bottom: .5rem; }
  .truncate { max-width: 14ch; }
}

/* ---------------------------------------------------------------- print */
@media print {
  /* Reports get printed and pasted into incident write-ups. */
  .topbar, .footer, .btn { display: none; }
  body { background: #fff; color: #000; }
  .card, .table-scroll { border-color: #ccc; }
}

/* ── Services page (P2) ─────────────────────────────────────────────────── */
.statline { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .5rem 0 1rem; }
.pill {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; border: 1px solid transparent;
}
.pill-ok   { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.pill-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.pill-bad  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.pill-off  { color: var(--fg-muted); border-color: color-mix(in srgb, var(--off) 45%, transparent); }

table.services td { vertical-align: top; }
table.services th.num, table.services td.num { text-align: right; white-space: nowrap; }
.svc-name { font-weight: 600; }
.tag {
  display: inline-block; margin-left: .35rem; padding: 0 .4rem; border-radius: 4px;
  font-size: .7rem; font-weight: 600; color: var(--fg-muted);
  border: 1px solid color-mix(in srgb, var(--off) 50%, transparent);
}
.tag-exposed { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }

.uptime { font-weight: 600; }
.uptime-ok   { color: var(--ok); }
.uptime-warn { color: var(--warn); }
.uptime-bad  { color: var(--bad); }

.spark { display: block; }
.spark-line { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark-ok   { stroke: var(--ok); }
.spark-warn { stroke: var(--warn); }
.spark-bad  { stroke: var(--bad); }
.spark-off  { stroke: var(--off); }
.spark-100  { stroke: color-mix(in srgb, var(--fg-dim) 40%, transparent); stroke-width: 1; stroke-dasharray: 2 3; }
