/* ============================================================
   Trench — single source of truth for visual design
   See DESIGN.md at the repo root for the philosophy and rules.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600&family=Geist+Mono:wght@400;500&display=swap');

:root {
  /* ── Surfaces ─────────────────────────────────────────────── */
  --bg:          #0D0D0F;
  --bg-elev:     #161619;
  --bg-elev-2:   #1F1F24;
  --border:      #2A2A31;
  --border-subtle: rgba(42, 42, 49, 0.5);

  /* ── Text ─────────────────────────────────────────────────── */
  --text:        #F2F2F5;
  --text-muted:  #8B8B95;
  --text-dim:    #56565E;

  /* ── Brand ────────────────────────────────────────────────── */
  --primary:     #4A90E2;
  --primary-hi:  #7AB0EC;
  --primary-dim: #2E5F9B;
  --on-primary:  #FFFFFF;

  /* ── Accents (decorative only, never status) ──────────────── */
  --accent:      #FF7A59;
  --accent-alt:  #FFC857;

  /* ── Status (DO NOT CHANGE — per Trench spec) ─────────────── */
  --green:       #34d399;
  --yellow:      #fbbf24;
  --red:         #f87171;
  --blue:        #60a5fa;
  --gray:        #4b5563;
  --on-success:  #111111;
  --on-danger:   #FFFFFF;

  /* ── Status tinted fills ──────────────────────────────────── */
  --bg-success:  rgba(52, 211, 153, 0.10);
  --bg-warning:  rgba(251, 191, 36, 0.10);
  --bg-warning-2: rgba(251, 191, 36, 0.08);
  --bg-danger:   rgba(248, 113, 113, 0.10);
  --bg-danger-2: rgba(248, 113, 113, 0.15);

  /* ── Banner gradients (status-tinted dark surfaces) ───────── */
  --banner-online:       linear-gradient(135deg, #0D1F1A, #0F1A14);
  --banner-partial:      linear-gradient(135deg, #1F1A0D, #1A150F);
  --banner-offline:      linear-gradient(135deg, #141414, #111111);
  --banner-power-outage: linear-gradient(135deg, #1F1A06, #1A1608);
  --banner-maintenance:  linear-gradient(135deg, #0D141F, #0F121A);

  /* ── Overlay ──────────────────────────────────────────────── */
  --overlay:     rgba(0, 0, 0, 0.6);

  /* ── Typography ───────────────────────────────────────────── */
  --font-sans:   'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:   'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --text-xs:    0.70rem;
  --text-sm:    0.75rem;
  --text-base:  0.80rem;
  --text-md:    0.85rem;
  --text-lg:    0.90rem;
  --text-xl:    1.15rem;
  --fw-normal:  400;
  --fw-medium:  500;
  --fw-bold:    600;
  --lh-tight:   1.3;
  --lh-base:    1.6;

  /* ── Spacing scale (4px base) ─────────────────────────────── */
  --space-1:   4px;
  --space-2:   8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-7:  32px;
  --space-8:  40px;

  /* ── Radius scale ─────────────────────────────────────────── */
  --radius-sm:   4px;
  --radius-md:   6px;
  --radius-lg:   8px;
  --radius-xl:  12px;
  --radius-full: 9999px;
  --radius: var(--radius-xl);

  /* ── Shadows (status-dot glows) ───────────────────────────── */
  --glow-green:  0 0 8px var(--green);
  --glow-yellow: 0 0 8px var(--yellow);
  --glow-red:    0 0 8px var(--red);
  --glow-blue:   0 0 8px var(--blue);

  /* ── Motion ───────────────────────────────────────────────── */
  --dur-fast:   0.15s;
  --dur-base:   0.20s;
  --dur-slow:   0.30s;
  --dur-banner: 0.40s;
  --ease:       ease;

  /* ── Layout ───────────────────────────────────────────────── */
  --container:  640px;
  --modal-w:    340px;

  /* ── Z-index scale ────────────────────────────────────────── */
  --z-dropdown: 100;
  --z-modal:    1000;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ───────────────────────────────────────────────────── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: var(--lh-base);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container { max-width: var(--container); margin: 0 auto; padding: var(--space-8) var(--space-5); }
.container.narrow { max-width: 560px; }
.hidden { display: none !important; }

/* Section heading (admin) */
h2 {
  font-size: var(--text-base);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 36px 0 var(--space-3);
  padding-left: 2px;
}
h2:first-child { margin-top: 0; }

/* ── Banner (public) ────────────────────────────────────────── */
.banner {
  text-align: center;
  padding: var(--space-7) var(--space-6);
  border-radius: var(--radius);
  margin-bottom: 28px;
  transition: background var(--dur-banner);
}
.banner h1 {
  font-size: var(--text-xl);
  font-weight: var(--fw-bold);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.banner-sub { font-size: var(--text-base); color: var(--text-muted); margin-top: var(--space-2); }
.banner.online        { background: var(--banner-online); }
.banner.partial_outage{ background: var(--banner-partial); }
.banner.offline       { background: var(--banner-offline); }
.banner.power_outage  { background: var(--banner-power-outage); }
.banner.maintenance   { background: var(--banner-maintenance); }

/* ── Event alert (public) ───────────────────────────────────── */
.event-alert {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-6);
  border-left: 3px solid var(--yellow);
}
.event-alert.incident     { border-left-color: var(--red); }
.event-alert.power_outage { border-left-color: var(--yellow); }
.event-alert.maintenance  { border-left-color: var(--blue); }
.event-alert h3 { font-size: var(--text-lg); font-weight: var(--fw-bold); margin-bottom: 2px; }
.event-alert p  { font-size: var(--text-base); color: var(--text-muted); }

/* ── Card ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-3);
  transition: background var(--dur-base);
}
/* Public status cards: hover + min-height for uniform rows */
.card.card-status {
  margin-bottom: 10px;
  min-height: 68px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.card.card-status:hover { background: var(--bg-elev-2); }
.card-row  { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); }
.card-name { font-weight: var(--fw-medium); font-size: var(--text-lg); }
.card-sub  { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-1); }
.card-chip {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: var(--fw-normal);
  font-family: var(--font-mono);
  font-feature-settings: 'tnum' 1;
}
.spacer    { height: 18px; }

/* ── Status dot ─────────────────────────────────────────────── */
.dot { width: 10px; height: 10px; border-radius: var(--radius-full); display: inline-block; flex-shrink: 0; }
.banner .dot { width: 12px; height: 12px; }
.dot.up, .dot.current, .dot.online        { background: var(--green);  box-shadow: var(--glow-green);  }
.dot.degraded, .dot.partial_outage, .dot.stale { background: var(--yellow); box-shadow: var(--glow-yellow); }
.dot.down, .dot.offline                   { background: var(--red);    box-shadow: var(--glow-red);    }
.dot.power_outage                         { background: var(--yellow); box-shadow: var(--glow-yellow); }
.dot.maintenance                          { background: var(--blue);   box-shadow: var(--glow-blue);   }
.dot.unknown                              { background: var(--gray); }

/* ── Loading / spinner ──────────────────────────────────────── */
.loading { text-align: center; padding: var(--space-8) var(--space-5); color: var(--text-muted); }
.loading .spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
  margin-bottom: 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Footer + history (public) ──────────────────────────────── */
.footer { text-align: right; padding: 2px var(--space-1) 0; font-size: var(--text-xs); color: var(--text-muted); }
.footer-row { display: flex; justify-content: space-between; align-items: center; padding: 6px var(--space-1) 0; flex-wrap: wrap; gap: var(--space-1); }
.footer-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-feature-settings: 'tnum' 1;
}
.history-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-xs);
  cursor: pointer;
  padding: 3px 10px;
  border-radius: var(--radius-md);
  transition: color var(--dur-base), border-color var(--dur-base);
}
.history-toggle:hover { color: var(--text); border-color: var(--text-muted); }
.history-list { margin-top: 10px; padding: 0 var(--space-1); }
.history-item { font-size: 0.78rem; color: var(--text-muted); padding: var(--space-2) 0; border-bottom: 1px solid var(--border); }
.history-item:last-child { border-bottom: none; }
.history-item strong { color: var(--text); }
.history-type {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.65;
  margin-left: var(--space-3);
}
.history-timestamp {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  font-feature-settings: 'tnum' 1;
}

/* ── Forms (admin) ──────────────────────────────────────────── */
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-md);
  width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }
label {
  font-size: var(--text-base);
  color: var(--text-muted);
  display: block;
  margin-bottom: var(--space-1);
  margin-top: var(--space-3);
}
.card > label:first-child,
.card > div:first-child > label:first-child { margin-top: 0; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  padding: var(--space-2) 18px;
  border: none;
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: opacity var(--dur-base);
  font-family: inherit;
}
.btn:hover    { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary  { background: var(--primary); color: var(--on-primary); }
.btn-danger   { background: var(--red);     color: var(--on-danger);  }
.btn-success  { background: var(--green);   color: var(--on-success); }
.btn-muted    { background: var(--border);  color: var(--text); }
.btn-sm       { padding: 5px var(--space-3); font-size: var(--text-sm); }
.btn-row      { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.btn-row.btn-row-tight { margin-top: 0; }

/* ── Messages ───────────────────────────────────────────────── */
.msg {
  font-size: var(--text-base);
  margin-top: 10px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
}
.msg:empty  { display: none; }
.msg.ok     { background: var(--bg-success); color: var(--green); }
.msg.err    { background: var(--bg-danger);  color: var(--red); }
.msg.u-mt-2 { margin-top: 10px; }

/* ── List items (admin) ─────────────────────────────────────── */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  gap: var(--space-2);
}
.list-item:last-child { border-bottom: none; }
.list-info { font-size: var(--text-md); flex: 1; min-width: 0; }
.list-info span { color: var(--text-muted); font-size: var(--text-sm); display: block; margin-top: 2px; }
.x-btn {
  width: 28px; height: 28px;
  border: none; background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all var(--dur-fast);
}
.x-btn:hover { background: var(--bg-danger-2); color: var(--red); }

/* ── Service admin item ─────────────────────────────────────── */
.svc-item { padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.svc-item:last-child { border-bottom: none; }
.svc-item-head { display: flex; align-items: center; gap: var(--space-2); }
.svc-item-name {
  font-size: var(--text-lg);
  font-weight: var(--fw-medium);
  flex-shrink: 0;
  max-width: 36%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.svc-item-url {
  color: var(--text-muted);
  font-size: 0.73rem;
  margin-top: var(--space-1);
  word-break: break-all;
  padding-left: 2px;
  font-family: var(--font-mono);
}
.input-wrap { position: relative; flex: 1; min-width: 0; }
.input-wrap input { width: 100%; padding: 6px 28px 6px 10px; font-size: 0.78rem; }
.input-confirm {
  position: absolute;
  right: var(--space-1); top: 50%;
  transform: translateY(-50%);
  width: 22px; height: 22px;
  background: none; border: none;
  color: var(--text-muted);
  opacity: 0.35;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  padding: 0;
  transition: opacity var(--dur-fast), color var(--dur-fast);
}
.input-confirm:hover, .input-confirm.flash { opacity: 1; color: var(--green); }

.svc-icon-btn {
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  transition: all var(--dur-fast);
}
.svc-icon-btn:hover { color: var(--text); border-color: var(--text-muted); }
.svc-icon-btn.active {
  color: var(--yellow);
  border-color: var(--yellow);
  background: var(--bg-warning-2);
}

/* ── Active events (admin) ──────────────────────────────────── */
.active-evt { padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.active-evt:last-child { border-bottom: none; }
.active-evt-row { display: flex; justify-content: space-between; align-items: start; gap: var(--space-2); }
.active-evt-info { flex: 1; }
.active-evt-title { font-size: var(--text-md); font-weight: var(--fw-medium); }
.active-evt-meta { font-size: 0.73rem; color: var(--text-muted); margin-top: 3px; }

/* ── History (admin) ────────────────────────────────────────── */
.history-item-admin {
  display: flex;
  justify-content: space-between;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: var(--space-2);
}
.history-item-admin:last-child { border-bottom: none; }
.history-info { font-size: 0.78rem; color: var(--text-muted); flex: 1; }
.history-info strong { color: var(--text); }

/* ── Toggle switch ──────────────────────────────────────────── */
.switch-row { display: flex; justify-content: space-between; align-items: center; padding: var(--space-2) 0; }
.switch-label { font-size: var(--text-md); font-weight: var(--fw-medium); }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  transition: var(--dur-slow);
  border-radius: 24px;
}
.slider:before {
  position: absolute; content: '';
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background: var(--text-muted);
  transition: var(--dur-slow);
  border-radius: var(--radius-full);
}
input:checked + .slider { background: var(--primary); }
input:checked + .slider:before { transform: translateX(18px); background: var(--on-primary); }

/* ── Service override (segmented buttons) ───────────────────── */
.svc-override-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: var(--space-3);
}
.svc-override-row:last-child { border-bottom: none; }
.svc-override-name { font-size: var(--text-md); flex: 1; }
.seg-btn-row { display: flex; gap: 0; }
.seg-btn {
  padding: 5px 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: all var(--dur-base);
  font-family: inherit;
}
.seg-btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.seg-btn:last-child  { border-radius: 0 var(--radius-md) var(--radius-md) 0; border-left: none; }
.seg-btn.active-up   { background: var(--green); color: var(--on-success); border-color: var(--green); }
.seg-btn.active-down { background: var(--red);   color: var(--on-danger);  border-color: var(--red); }

/* ── Preview box ────────────────────────────────────────────── */
.preview-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  margin-top: var(--space-3);
  font-size: 0.82rem;
}
.preview-row { display: flex; justify-content: space-between; align-items: center; padding: var(--space-1) 0; }
.preview-overall {
  font-size: var(--text-lg);
  font-weight: var(--fw-bold);
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

/* ── Ping log table ─────────────────────────────────────────── */
.ping-controls { display: flex; gap: 10px; align-items: flex-end; }
.ping-select-wrap { flex: 1; min-width: 0; }
.ping-filter-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--dur-fast);
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.ping-filter-btn:hover { border-color: var(--text-muted); }
.ping-filter-btn.active { border-color: var(--red); background: var(--bg-danger-2); }
.ping-filter-btn .dot { width: 12px; height: 12px; }

.ping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  table-layout: fixed;
  font-family: var(--font-mono);
  font-feature-settings: 'tnum' 1;
}
.ping-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: var(--fw-medium);
  padding: 6px var(--space-2);
  border-bottom: 1px solid var(--border);
}
.ping-table td {
  padding: 6px var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  white-space: nowrap;
}
.ping-table tr:last-child td { border-bottom: none; }
.ping-table tr.ping-down td  { color: var(--red); }
.ping-err {
  color: var(--text-muted);
  font-size: var(--text-xs);
  display: block;
  margin-top: 2px;
  word-break: break-all;
}
.ping-header-wrap { margin-top: 10px; padding-right: var(--space-2); }
.ping-scroll { max-height: 230px; overflow-y: auto; scrollbar-width: thin; }
.ping-empty  { margin-top: var(--space-2); }
.ping-error  { color: var(--red); margin-top: var(--space-2); }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--overlay);
  display: flex; align-items: center; justify-content: center;
  z-index: var(--z-modal);
  padding: var(--space-5);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}
.modal-backdrop.show { opacity: 1; }
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  max-width: var(--modal-w);
  width: 100%;
  transform: scale(0.96);
  transition: transform var(--dur-fast) var(--ease);
}
.modal-backdrop.show .modal { transform: scale(1); }
.modal-msg  { font-size: 0.92rem; line-height: 1.5; margin-bottom: var(--space-5); color: var(--text); }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Login wrap (admin) ─────────────────────────────────────── */
.login-wrap {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  padding: var(--space-5);
}
.login-wrap > * { width: 100%; max-width: 280px; }
.login-wrap input { margin-bottom: 14px; text-align: center; }

/* ── Utilities (for inline-style replacements) ──────────────── */
.u-w-full   { width: 100%; }
.u-flex-1   { flex: 1; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 480px) {
  .container { padding: var(--space-6) var(--space-4); }
  .container.narrow { padding: var(--space-6) var(--space-4); }
  .banner { padding: var(--space-6) 18px; }
}
