/* 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 0.5rem 1.5rem 16px; min-width: 0; }

/* --- the simulator on the left, the NAT table in a pane on the right,
   between them an edge that drags (--side, set by overload.js) */
.nat-shell { display: grid; grid-template-columns: minmax(0, 1fr) 8px var(--side, 340px); }
.nat-divider { cursor: col-resize; display: flex; justify-content: center; touch-action: none; }
.nat-divider::after { content: ""; width: 2px; border-radius: 1px; background: var(--border); }
.nat-divider:hover::after, .dragging .nat-divider::after { background: var(--accent); }
.dragging { user-select: none; cursor: col-resize; }
.nat-pane { position: sticky; top: 0; height: 100vh; padding: 0.5rem 16px 0.5rem 0.5rem; }
.nat-pane .nat-table-box { height: 100%; display: flex; flex-direction: column; }
.nat-pane h2 { flex-wrap: wrap; }
.nat-pane .nat-aging { margin-left: 0; width: 100%; }
.nat-pane .nat-aging input { flex: 1; width: auto; min-width: 0; }
#nat-table { flex: 1; min-height: 0; overflow-y: auto; }
/* A phone has no room beside the simulator: the table goes last. */
@media (max-width: 859px) {
  .nat-shell { display: block; }
  .nat-app { padding: 0.5rem 16px 0; }
  .nat-divider { display: none; }
  .nat-pane { position: static; height: auto; padding: 0.75rem 16px 1.5rem; }
  #nat-table { max-height: 420px; }
}
.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 { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.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-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: 0.45rem 0; display: grid; grid-template-columns: minmax(0, 1fr) 2px minmax(0, 1fr); gap: 0 0.75rem; }
/* inside to outside on the left, over the home network; outside to inside
   on the right, over the Internet; a rule between the two */
.nat-tools { display: flex; flex-direction: column; align-items: flex-start; gap: 0.4rem; min-width: 0; }
.nat-tools-sep { background: var(--border); border-radius: 1px; }
@media (max-width: 859px) {
  .nat-start { grid-template-columns: minmax(0, 1fr); gap: 0.5rem; }
  .nat-tools-sep { height: 2px; }
}
.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-start-group .addr.priv { color: var(--priv); }
.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;
  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; it holds the main line and four bullets. */
  height: 8rem; 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; }
/* The one bold word a main line has is "Dropped", in the text file. */
.nat-say .main b { color: #ff8a8a; }
#nat-log li b { color: var(--drop); }
/* A bullet list, wherever the page's words take one. */
.bul { margin: 0.1rem 0 0; padding-left: 1.15rem; }
.bul .bul { margin: 0; }
.bul li { margin: 0.05rem 0; }
.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; gap: 0.75rem; }
.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; }

/* One card per NAT entry, in its connection's colour. */
.n-entry { border: 1px solid var(--border); border-left: 4px solid var(--c, var(--wire)); border-radius: 8px; padding: 0.35rem 0.55rem; margin-bottom: 0.45rem; font-size: 0.84rem; }
.n-entry.fresh { background: var(--flash); }
.n-entry.hit { background: color-mix(in srgb, var(--flash) 45%, transparent); }
.n-entry.gone { opacity: 0.6; }
.n-entry.gone dd code { text-decoration: line-through; }
.n-entry .top { display: flex; justify-content: space-between; gap: 0.5rem; font-weight: 600; }
.n-entry .top .pk { font-weight: 400; color: var(--dim); font-size: 0.78rem; }
.n-entry dl { margin: 0.25rem 0 0; }
.n-entry dt { color: var(--dim); font-size: 0.74rem; margin-top: 0.2rem; }
.n-entry dt small { font-size: 0.68rem; opacity: 0.85; margin-left: 0.35rem; }
.n-entry dd { margin: 0; white-space: nowrap; }
.n-entry code { font-family: ui-monospace, Menlo, Consolas, monospace; }
/* What a real router keeps the entry for: minutes or hours, where the
   simulator counts seconds. */
.n-entry .real { display: block; white-space: normal; font-size: 0.76rem; color: var(--accent); margin-top: 0.1rem; }
/* A ping has no ports: its identifier comes from the sending system. */
.nat-client-tool.icmp .colon, .nat-client-tool.icmp .port { display: 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; }


#nat-log { list-style: none; margin: 0; padding: 0; max-height: 320px; 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; }
