/* Proxy Addon console
   Colour carries state and nothing else: if something is green it is online,
   if it is red it is down. Nothing decorative is ever coloured, so a glance
   across the page reads as status rather than as styling.

   Dark mode keeps that rule. The status hues are re-tuned rather than reused,
   because the greens and reds that read clearly on paper turn muddy on a dark
   surface, and this palette's whole job is to be legible at a glance. */

:root {
  --ink:        #16202b;
  --ink-2:      #3d4d5c;
  --muted:      #6b7c8c;
  --paper:      #f2f4f6;
  --surface:    #ffffff;
  --rule:       #dde3e9;
  --rule-firm:  #c3ccd6;

  --online:     #0e7c5a;
  --online-bg:  #e4f2ec;
  --warn:       #b4630c;
  --warn-bg:    #fbeedd;
  --down:       #b3261e;
  --down-bg:    #fbe7e5;
  --signal:     #1f5fa8;
  --signal-bg:  #e6eef8;

  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  /* Monospace only for machine values — addresses, ids, byte counts — where
     column alignment and telling 0 from O actually matter. */
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;

  --gap: 16px;
}

[data-theme="dark"] {
  --ink:        #e6edf3;
  --ink-2:      #b3c0cc;
  --muted:      #8996a3;
  --paper:      #0f161d;
  --surface:    #171f27;
  --rule:       #27323d;
  --rule-firm:  #3a4854;

  --online:     #4ec99a;
  --online-bg:  #14332a;
  --warn:       #e3a44f;
  --warn-bg:    #352813;
  --down:       #f08279;
  --down-bg:    #3a1f1d;
  --signal:     #6aa9f0;
  --signal-bg:  #16283f;
}

[data-theme="dark"] button.act {
  background: var(--signal);
  border-color: var(--signal);
  color: #0f161d;
}

[data-theme="dark"] button.act:hover { background: #82b8f5; }

[data-theme="dark"] .toast { background: #27323d; }

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: var(--paper);
  color: var(--ink);
}

/* The browser paints form controls and scrollbars from this. */
[data-theme="dark"] { color-scheme: dark; }

.theme-toggle {
  border: 1px solid var(--rule-firm);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  padding: 4px 9px;
  cursor: pointer;
}

.theme-toggle:hover { color: var(--ink); border-color: var(--ink-2); }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--signal); }

/* ---------------------------------------------------------------- sign in */

.signin {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.signin-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 28px;
}

.signin h1 {
  margin: 0 0 4px;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.signin p.sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 13px;
}

/* ------------------------------------------------------------------ shell */

.shell { display: flex; min-height: 100vh; }

.rail {
  width: 208px;
  flex: 0 0 208px;
  background: var(--surface);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--rule);
}

.brand strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand span {
  font-size: 12px;
  color: var(--muted);
}

.nav { padding: 10px 10px; flex: 1; }

.nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 2px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.nav button:hover { background: var(--paper); color: var(--ink); }

.nav button[aria-current="page"] {
  background: var(--signal-bg);
  color: var(--signal);
  font-weight: 550;
}

.nav .count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.who {
  padding: 14px 20px;
  border-top: 1px solid var(--rule);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.who .name { font-weight: 550; }
.who .role { color: var(--muted); font-size: 12px; }

.main { flex: 1; min-width: 0; padding: 24px 28px 64px; }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.page-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.page-head .hint { color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------------ fleet strip */

.fleet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
  gap: 12px;
  margin-bottom: var(--gap);
}

.edge {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--rule-firm);
  border-radius: 4px;
  padding: 13px 14px;
}

.edge.is-online  { border-left-color: var(--online); }
.edge.is-offline { border-left-color: var(--down); }
.edge.is-drain   { border-left-color: var(--warn); }

.edge .top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.edge .name {
  font-weight: 550;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edge .host {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.edge .metrics {
  display: flex;
  gap: 18px;
  margin-top: 11px;
}

.edge .metric .v {
  font-family: var(--mono);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.edge .metric .k { font-size: 11px; color: var(--muted); }

/* Fill shows headroom against max_clients — the number that decides whether
   this edge can take another viewer. */
.meter {
  height: 3px;
  background: var(--rule);
  border-radius: 2px;
  margin-top: 11px;
  overflow: hidden;
}

.meter i {
  display: block;
  height: 100%;
  background: var(--signal);
  border-radius: 2px;
}

.meter i.hot { background: var(--warn); }
.meter i.full { background: var(--down); }

/* ----------------------------------------------------------------- totals */

.totals {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  margin-bottom: var(--gap);
}

.totals div .v {
  font-family: var(--mono);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.totals div .k { font-size: 12px; color: var(--muted); }

/* ----------------------------------------------------------------- alerts */

.alert {
  border: 1px solid var(--down);
  border-left-width: 3px;
  background: var(--down-bg);
  border-radius: 4px;
  padding: 12px 14px;
  margin-bottom: var(--gap);
  font-size: 14px;
}

.alert h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.alert p  { margin: 0; color: var(--ink-2); font-size: 13px; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  margin-bottom: var(--gap);
}

.card > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 13px 16px;
  border-bottom: 1px solid var(--rule);
}

.card > header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card .body { padding: 16px; }

/* ----------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 9px 16px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
  vertical-align: middle;
}

tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--paper); }

td.num, th.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

td.mono { font-family: var(--mono); font-size: 12.5px; }

.scroll { overflow-x: auto; }

/* ------------------------------------------------------------------ chips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
  line-height: 1.6;
  background: var(--paper);
  color: var(--ink-2);
  border: 1px solid var(--rule);
  margin: 1px 3px 1px 0;
}

.chip.online  { background: var(--online-bg); color: var(--online); border-color: transparent; }
.chip.offline { background: var(--down-bg);   color: var(--down);   border-color: transparent; }
.chip.warn    { background: var(--warn-bg);   color: var(--warn);   border-color: transparent; }
.chip.info    { background: var(--signal-bg); color: var(--signal); border-color: transparent; }

.chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.chip button {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  padding: 0 0 0 2px;
  font: inherit;
  opacity: 0.6;
}

.chip button:hover { opacity: 1; }

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.empty strong { display: block; color: var(--ink); font-weight: 550; margin-bottom: 3px; }

/* ----------------------------------------------------------------- inputs */

label { display: block; font-size: 13px; margin-bottom: 5px; color: var(--ink-2); }

input, select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--rule-firm);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 1px;
}

.field { margin-bottom: 13px; }

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.row > * { flex: 1 1 150px; }
.row > .narrow { flex: 0 1 110px; }

button.act {
  padding: 7px 14px;
  border: 1px solid var(--signal);
  border-radius: 4px;
  background: var(--signal);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

button.act:hover { background: #1a5293; }
button.act:disabled { opacity: 0.5; cursor: default; }

button.ghost {
  padding: 5px 11px;
  border: 1px solid var(--rule-firm);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

button.ghost:hover { border-color: var(--ink-2); color: var(--ink); }
button.ghost.danger:hover { border-color: var(--down); color: var(--down); }

/* --------------------------------------------------------------- feedback */

.note {
  margin: 0 0 13px;
  padding: 9px 12px;
  border-radius: 4px;
  font-size: 13px;
  border: 1px solid;
}

.note.err  { background: var(--down-bg);   border-color: var(--down);   color: var(--down); }
.note.good { background: var(--online-bg); border-color: var(--online); color: var(--online); }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 340px;
  padding: 11px 15px;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  z-index: 50;
}

.toast.err { background: var(--down); }

/* The only unprompted motion on the page, and it exists to tell you the poll
   is alive rather than to decorate anything. */
.pulse {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--online);
  margin-right: 6px;
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.secret {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--paper);
  border: 1px solid var(--rule-firm);
  border-radius: 4px;
  padding: 9px 11px;
  word-break: break-all;
  margin: 8px 0 0;
}

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

/* ----------------------------------------------------------------- mobile */

@media (max-width: 760px) {
  .shell { flex-direction: column; }

  .rail {
    width: auto;
    flex: none;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
  }

  .nav {
    display: flex;
    overflow-x: auto;
    padding: 6px 8px;
    gap: 4px;
  }

  .nav button { width: auto; white-space: nowrap; margin: 0; }
  .nav .count { display: none; }
  .who { display: flex; justify-content: space-between; align-items: center; }
  .main { padding: 16px 14px 48px; }
  .totals { gap: 18px; }
  th, td { padding-left: 12px; padding-right: 12px; }
}


/* Collapsible card sections. The marker is left in place rather than replaced:
   it is the browser's own affordance for "this opens", and people already know
   what it means. */
.csv-summary {
  padding: 11px 16px;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
  font-weight: 550;
  color: var(--ink-2);
  cursor: pointer;
  list-style-position: inside;
}

.csv-summary:hover { color: var(--ink); background: var(--paper); }

details[open] .csv-summary { color: var(--ink); }

.csv-summary:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: -2px;
}
