/* The NAT overload simulator. Opened full screen or in an iframe, which cannot
   see the site's own light/dim switch, so it follows the reader's system
   preference, as the OSPF demos do. */

:root {
  --bg: #ffffff;
  --card: #ffffff;
  --border: #dfe3e8;
  --text: #22272e;
  --dim: #5f6b78;
  --accent: #0077b8;
  --btn: #f4f5f7;
  --panel: #0d2436;
  --panel-text: #eaf1f6;
  --wire: #9aa8b4;
  --inside: rgba(217, 130, 43, 0.07);
  --inside-stroke: rgba(217, 130, 43, 0.45);
  --outside: rgba(59, 111, 216, 0.06);
  --outside-stroke: rgba(59, 111, 216, 0.4);
  --router: #eef5ee;
  --router-stroke: #4c9a5f;
  --host: #f7f9fb;
  --priv: #c46a12;
  --pub: #1f8a45;
  --drop: #d23b3b;
  --flash: rgba(255, 196, 0, 0.35);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1d2b;
    --card: #112b40;
    --border: #234862;
    --text: #eaf1f6;
    --dim: #9fb2c2;
    --accent: #4fb3ff;
    --btn: #16374f;
    --panel: #081b29;
    --panel-text: #eaf1f6;
    --wire: #5b7382;
    --inside: rgba(217, 145, 75, 0.09);
    --inside-stroke: rgba(217, 145, 75, 0.5);
    --outside: rgba(111, 155, 240, 0.08);
    --outside-stroke: rgba(111, 155, 240, 0.5);
    --router: #163f2a;
    --router-stroke: #4fae6f;
    --host: #16374f;
    --priv: #f0a050;
    --pub: #5fd38a;
    --drop: #ff6464;
    --flash: rgba(255, 196, 0, 0.3);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.nat-app { padding: 0.5rem 16px 1.5rem; max-width: 1500px; margin: 0 auto; }
.mono, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.nat-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.9rem; margin: 0 0 0.45rem; }
.nat-head h1 { font-size: 1.3rem; margin: 0; letter-spacing: -0.01em; }
.nat-head p { margin: 0; color: var(--dim); font-size: 0.92rem; }
.in-viewer .nat-head { display: none; } /* the viewer page's top bar holds it */

/* --- controls */
.nat-bar, .nat-start { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.nat-start { gap: 0.5rem; }
.nat-btn, .nat-speed button {
  background: var(--btn); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.35rem 0.9rem; font-size: 0.88rem; cursor: pointer;
}
.nat-btn:hover, .nat-speed button:hover { border-color: var(--accent); }
.nat-btn:disabled { opacity: 0.45; cursor: default; }
.nat-btn.play { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 6rem; font-weight: 600; }
.nat-btn.go { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.nat-btn.small { padding: 0.12rem 0.55rem; font-size: 0.78rem; border-radius: 6px; }
.nat-speed { display: inline-flex; }
.nat-speed button { border-radius: 0; margin-left: -1px; padding: 0.35rem 0.6rem; }
.nat-speed button:first-child { border-radius: 8px 0 0 8px; }
.nat-speed button:last-child { border-radius: 0 8px 8px 0; }
.nat-speed button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.nat-clock { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9rem; color: var(--dim); min-width: 7rem; }
.nat-aging { display: inline-flex; align-items: center; gap: 0.5rem; margin-left: auto; font-size: 0.82rem; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text); }
.nat-box h2:has(.nat-aging) { display: flex; align-items: center; gap: 0.4rem; }
.nat-start-group.conn { margin-left: auto; padding-top: 0.15rem; padding-bottom: 0.15rem; }
.nat-aging input { width: 180px; accent-color: var(--accent); }
.nat-aging output { font-family: ui-monospace, Menlo, Consolas, monospace; min-width: 3.3rem; font-weight: 700; color: var(--accent); }

.nat-start { margin-top: 0.45rem; }
.nat-start-group {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem;
  border: 1px solid var(--border); border-radius: 10px; padding: 0.25rem 0.45rem; background: var(--card);
}
.nat-start-group.in { border-left: 4px solid var(--priv); }
.nat-start-group.out { border-left: 4px solid var(--drop); }
.nat-start-group .h { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--dim); margin-right: 0.2rem; }
.nat-start-group .arrow { color: var(--dim); }
.nat-start .port {
  width: 4rem; background: var(--btn); color: var(--text); border: 1px solid var(--border); border-radius: 7px;
  padding: 0.3rem 0.4rem; font-size: 0.86rem; font-family: ui-monospace, Menlo, Consolas, monospace;
}
.nat-start .port.bad { border-color: var(--drop); outline: 2px solid color-mix(in srgb, var(--drop) 35%, transparent); }
.nat-start .colon { color: var(--dim); margin: 0 -0.2rem; font-family: ui-monospace, Menlo, Consolas, monospace; }
.nat-start-group .addr { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.88rem; color: var(--pub); font-weight: 600; }
.nat-app select {
  background: var(--btn); color: var(--text); border: 1px solid var(--border); border-radius: 7px;
  padding: 0.3rem 0.4rem; font-size: 0.86rem;
}

/* --- what just happened, above the drawing */
.nat-say {
  display: flex; gap: 0.9rem; align-items: baseline; margin: 0.5rem 0 0.5rem;
  background: var(--panel); color: var(--panel-text); border-radius: 8px; padding: 0.45rem 0.9rem;
  /* A fixed height, so a longer event does not move the drawing and the
     buttons under the pointer. */
  height: 4.3rem; overflow-y: auto;
}
.nat-say .t { font-family: ui-monospace, Menlo, monospace; font-size: 0.78rem; opacity: 0.7; white-space: nowrap; }
.nat-say p { margin: 0; }
.nat-say .main { font-size: 1.1rem; font-weight: 600; line-height: 1.3; margin-bottom: 0.15rem; }
.nat-say .more { font-size: 0.9rem; line-height: 1.4; opacity: 0.92; }
.nat-say .a-priv { color: #ffb366; }
.nat-say .a-pub { color: #7ee2a2; }
.nat-say .bad { color: #ff8a8a; }
.nat-say code { font-size: 0.95em; }

/* --- the drawing */
.nat-svg-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
#nat-svg { display: block; width: 100%; min-width: 900px; height: auto; user-select: none; }
.n-region { stroke-width: 1.5; stroke-dasharray: 6 4; }
.n-region.inside { fill: var(--inside); stroke: var(--inside-stroke); }
.n-region.outside { fill: var(--outside); stroke: var(--outside-stroke); }
.n-region-name { font-size: 14px; font-weight: 700; fill: var(--dim); }
.n-region-sub { font-size: 12px; font-weight: 400; fill: var(--dim); }
.n-wire { stroke: var(--wire); stroke-width: 3; stroke-linecap: round; }
.n-host rect { fill: var(--host); stroke: var(--wire); stroke-width: 2; }
.n-name { font-size: 13.5px; font-weight: 700; fill: var(--text); }
.n-ip { font-size: 12px; font-family: ui-monospace, Menlo, Consolas, monospace; fill: var(--text); }
.n-note { font-size: 11.5px; fill: var(--dim); }
.n-router .body { fill: var(--router); stroke: var(--router-stroke); stroke-width: 2.5; }
.n-port { fill: var(--text); stroke: var(--card); stroke-width: 1.5; }
.n-port-tag { font-weight: 700; fill: var(--text); }
.n-port-ip { font-size: 12.5px; font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; paint-order: stroke; stroke: var(--card); stroke-width: 4px; }
.n-status { font-size: 11.5px; font-family: ui-monospace, Menlo, Consolas, monospace; fill: var(--text); }
.n-status.idle { fill: var(--dim); }
.n-status.head { font-family: inherit; fill: var(--dim); font-size: 11px; }
.a-priv { fill: var(--priv); color: var(--priv); }
.a-pub { fill: var(--pub); color: var(--pub); }

.n-pkt rect.bg { fill: var(--card); stroke: var(--border); stroke-width: 1.2; }
.n-pkt text { font-size: 10.4px; font-family: ui-monospace, Menlo, Consolas, monospace; fill: var(--text); }
.n-pkt .k { font-size: 9.5px; font-weight: 800; font-family: inherit; }
.n-pkt .lbl { fill: var(--dim); }
.n-pkt .chg { font-weight: 800; text-decoration: underline; }
.n-pkt.flash rect.bg { fill: color-mix(in srgb, var(--flash) 70%, var(--card)); stroke: var(--accent); stroke-width: 2; }
.n-pkt.dropped rect.bg { stroke: var(--drop); stroke-width: 2.2; }
.n-x { stroke: var(--drop); stroke-width: 4; stroke-linecap: round; }

/* --- the table and the side panels */
.nat-lower { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.75rem; margin-top: 0.5rem; }
@media (min-width: 1100px) { .nat-lower { grid-template-columns: minmax(0, 1fr) 380px; } }
.nat-side { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.nat-box { border: 1px solid var(--border); border-radius: 12px; background: var(--card); padding: 0.7rem 0.85rem; font-size: 0.84rem; min-width: 0; }
.nat-box h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--dim); margin: 0 0 0.45rem; }
.nat-box h2 .sub { text-transform: none; letter-spacing: 0; font-weight: 400; }
.nat-empty { color: var(--dim); margin: 0.2rem 0; }

#nat-table { overflow-x: auto; }
#nat-table table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
#nat-table th { text-align: left; font-weight: 600; color: var(--dim); font-size: 0.74rem; border-bottom: 1px solid var(--border); padding: 0.25rem 0.45rem; white-space: nowrap; }
#nat-table th small { display: block; font-weight: 400; }
#nat-table td { padding: 0.35rem 0.45rem; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
#nat-table td.st { color: var(--dim); font-size: 0.8rem; }
#nat-table td.addr { font-family: ui-monospace, Menlo, Consolas, monospace; }
#nat-table tr td:first-child { border-left: 4px solid var(--c, var(--wire)); }
#nat-table tr.fresh td { background: var(--flash); }
#nat-table tr.hit td { background: color-mix(in srgb, var(--flash) 45%, transparent); }
#nat-table tr.gone td { color: var(--dim); text-decoration: line-through; }
#nat-table tr.gone td.timer { text-decoration: none; }
.n-age { display: inline-flex; align-items: center; gap: 0.45rem; }
.n-age i { display: inline-block; width: 90px; height: 7px; border-radius: 4px; background: var(--btn); border: 1px solid var(--border); overflow: hidden; position: relative; }
.n-age i b { position: absolute; left: 0; top: 0; bottom: 0; background: var(--pub); }
.n-age i b.low { background: var(--drop); }
.n-age span { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.8rem; min-width: 3.4rem; }

.n-conn { display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem 0.45rem; padding: 0.35rem 0; border-bottom: 1px solid var(--border); }
.n-conn:last-child { border-bottom: 0; }
.n-conn .dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--c); flex: none; }
.n-conn .what { flex: 1 1 12rem; }
.n-conn .state { font-size: 0.76rem; color: var(--dim); display: block; }
.n-conn .state.bad { color: var(--drop); }

#nat-log { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; font-size: 0.8rem; }
#nat-log li { padding: 0.2rem 0 0.2rem 0.5rem; border-left: 3px solid var(--accent); line-height: 1.35; margin-bottom: 0.15rem; }
#nat-log li.drop { border-color: var(--drop); }
#nat-log li.gone { border-color: var(--dim); }
#nat-log li .t { display: inline-block; min-width: 3.2rem; color: var(--dim); font-family: ui-monospace, Menlo, monospace; }
/* No spin arrows: they take the room a five-digit port needs. */
.nat-start .port { -moz-appearance: textfield; appearance: textfield; }
.nat-start .port::-webkit-inner-spin-button, .nat-start .port::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* The switch, the servers' own networks, and the interface tooltips. */
.n-switch rect { fill: var(--host); stroke: var(--wire); stroke-width: 2; }
.n-net { fill: none; stroke: var(--outside-stroke); stroke-width: 1.2; stroke-dasharray: 4 3; }
.n-iface { cursor: default; }
.n-iface .hit { fill: transparent; }
.n-iface:hover .n-port { r: 8; fill: var(--accent); }
.n-port-tag { font-size: 11px; font-weight: 700; fill: var(--dim); }
.n-tip { pointer-events: none; }
.n-tip rect { fill: var(--panel); opacity: 0.96; }
.n-tip text { font-size: 13px; fill: var(--panel-text); }
.n-tip .h { font-weight: 700; }
.n-tip .ip { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; }
.n-tip .a-priv { fill: #ffb366; }
.n-tip .a-pub { fill: #7ee2a2; }
.n-tip .sub { font-size: 12px; opacity: 0.85; }
