/* Reusable building blocks. */

/* --- Panel: a titled block --- */
.panel {
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.panel-body {
  padding: 0.9rem 0.75rem 0.2rem;
}

.panel-head .muted {
  font-size: 0.87rem;
}

/* A remark or a link at the top of a panel that has no heading of its own. */
.panel-head:not(:has(h2)) {
  font-size: 0.87rem;
}

/* --- Tabs: the panels of a page, one at a time --- */
.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.tab {
  margin-bottom: -1px;
  padding: 0.5rem 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-count {
  margin-left: 0.4rem;
  font-size: 0.87rem;
  font-weight: 400;
  color: var(--text-muted);
}

.table-scroll {
  overflow-x: auto;
}

/* --- Generated files and other text to copy --- */
.code {
  margin: 0;
  padding: 0.75rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.45;
  tab-size: 2;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* A link that is an action rather than a way to another page. */
a.button {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height);
  padding: 0 0.8rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

a.button:hover {
  background: var(--row-hover);
}

/* --- A list that opens under its button: boxes to tick, several at once --- */
.dropdown {
  position: relative;
}

.dropdown > summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height);
  padding: 0 0.8rem;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
  user-select: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.dropdown > summary::-webkit-details-marker {
  display: none;
}

/* The mark that says there is something to open. */
.dropdown > summary::after {
  margin-left: 0.5rem;
  font-size: 0.7em;
  content: "▾";
}

.dropdown > summary:hover,
.dropdown[open] > summary {
  background: var(--row-hover);
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + 0.25rem);
  right: 0;
  z-index: 30;
  min-width: 15rem;
  max-height: min(26rem, 70vh);
  padding: 0.5rem;
  overflow-y: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.dropdown-panel .button-row {
  margin: 0 0 0.4rem;
}

.dropdown-panel label {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.25rem;
  font-weight: 400;
  white-space: nowrap;
  cursor: pointer;
}

.dropdown-panel label:hover {
  background: var(--row-hover);
}

/* A box to tick is as large as a letter, not as a field to type into. */
.dropdown-panel label input {
  flex: none;
  width: 1rem;
  height: 1rem;
  min-height: 0;
  margin: 0;
}

.steps {
  margin: 0 0 1rem;
  padding-left: 1.4rem;
}

.steps li {
  margin-bottom: 0.4rem;
}

/* The code an authenticator app scans; black on white whatever the colour mode. */
.qr {
  display: block;
  margin: 0.5rem 0 1rem;
  background: #ffffff;
  border: 1px solid var(--border);
}

.login-more {
  margin: 1rem 0 0;
  font-size: 0.9rem;
}

.form-section {
  margin: 1.5rem 0 0.75rem;
  font-size: 1rem;
}

.form-section:first-child {
  margin-top: 0;
}

/* A unified diff: what was removed, what was added. */
.diff span {
  display: block;
}

.diff .add {
  color: var(--ok);
}

.diff .del {
  color: var(--error);
}

.diff .hunk {
  color: var(--text-muted);
}

/* Present for the browser, out of sight for the user. */
.offscreen {
  position: fixed;
  left: -100rem;
}

/* --- Matrix: rows against columns, one letter per cell --- */
.matrix th,
.matrix td {
  padding: 0.35rem 0.5rem;
  text-align: center;
  white-space: nowrap;
}

.matrix th:first-child {
  text-align: left;
}

.matrix tbody th {
  font-weight: 400;
}

.matrix td {
  border-left: 1px solid var(--border);
  font-family: var(--font-mono);
  font-weight: 600;
}

.matrix .tagged {
  color: var(--accent);
}

/* With many columns, so that they still fit side by side. */
.matrix.dense th,
.matrix.dense td {
  padding: 0.3rem;
}

/* The matrix of who reaches whom: every cell leads to its explanation. */
.matrix td a {
  display: block;
  color: inherit;
  text-decoration: none;
}

.matrix td a:hover {
  text-decoration: underline;
}

.matrix .open {
  color: var(--ok);
}

.matrix .blocked,
.matrix .same {
  font-weight: 400;
  color: var(--text-muted);
}

.matrix .one-way,
.matrix .uncertain,
.matrix .partial {
  color: var(--warn);
}

.matrix .untagged {
  color: var(--ok);
}

/* A cell somebody said something about: a frame, green where the rules do as they should,
   red where they do otherwise. */
.matrix td.as-wanted {
  box-shadow: inset 0 0 0 2px var(--lamp-ok);
}

.matrix td.deviates {
  color: var(--on-accent);
  background: var(--lamp-error);
  box-shadow: inset 0 0 0 2px var(--lamp-error);
}

/* Key/value list: the label column stays narrow. */
.facts th {
  width: 12rem;
  font-weight: 400;
  color: var(--text-muted);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--text-muted);
}

/* --- Status: a lamp, always together with a word ---
   What is on, wrong or failing is a filled dot in a strong colour. What is off is a pale
   grey one with a rim and a muted word: unlit, and told apart by more than a shade.
   Standing by is a ring in orange: ready, not in use, and no warning, which is filled. */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  color: var(--text-muted);
}

.status::before {
  content: "";
  flex: none;
  width: 0.72rem;
  height: 0.72rem;
  background: var(--lamp-off-fill);
  border: 2px solid var(--lamp-off);
  border-radius: 50%;
}

.facts .status {
  align-items: baseline;
  white-space: normal;
}

.status.ok,
.status.warn,
.status.error,
.status.info,
.status.standby {
  color: inherit;
}

.status.ok::before {
  background: var(--lamp-ok);
  border-color: var(--lamp-ok);
}

.status.warn::before {
  background: var(--lamp-warn);
  border-color: var(--lamp-warn);
}

.status.error::before {
  background: var(--lamp-error);
  border-color: var(--lamp-error);
}

/* Something that is neither good nor bad, such as the action of a rule that forwards. */
.status.info::before {
  background: var(--accent);
  border-color: var(--accent);
}

.status.standby::before {
  background: transparent;
  border: 3px solid var(--lamp-standby);
}

/* --- Notice: something the user has to know or do --- */
.notice {
  margin-bottom: 1.25rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--off);
  border-radius: var(--radius);
}

.notice.error {
  border-left-color: var(--error);
}

.notice.ok {
  border-left-color: var(--ok);
}

.notice :last-child {
  margin-bottom: 0;
}

/* --- Icons and icon buttons --- */
.icon {
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button {
  flex: none;
  width: var(--control-height);
  padding: 0;
}

/* The way to the web interface of a device, behind its address. */
.address {
  white-space: nowrap;
}

.open-link {
  display: inline-flex;
  margin-left: 0.4rem;
  vertical-align: -0.2em;
}

.open-link .icon {
  width: 1rem;
  height: 1rem;
}

/* The waste bin of a button that deletes: it says so when the pointer is on it. */
/* A button that deletes: the waste bin alone, or words where a page has two things to
   delete and has to say which. */
button.danger:hover:not(:disabled),
button.danger:focus-visible {
  color: var(--error);
  border-color: var(--error);
}

/* --- Forms --- */
.form {
  max-width: 34rem;
}

.field {
  margin-bottom: 1rem;
}

.field small {
  display: block;
  margin-top: 0.25rem;
  color: var(--text-muted);
}

.field-label {
  margin-bottom: 0.25rem;
  font-weight: 600;
}

/* A field with something beside it: what the value means, or a button that acts on it. */
.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.75rem;
}

/* A number or a code: twelve characters wide. */
.field input.short {
  width: 12ch;
}

.field input[type="color"] {
  flex: none;
  width: 3.5rem;
  padding: 0.15rem;
  cursor: pointer;
}

/* --- Rate: what flows right now, as a bar and a number --- */
.rate {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  white-space: nowrap;
}

.rate-bar {
  flex: none;
  width: 7rem;
  height: 0.55rem;
}

.rate-track {
  fill: var(--table-head);
}

.rate-bar.in .rate-value {
  fill: var(--accent);
}

.rate-bar.out .rate-value {
  fill: var(--ok);
}

.rate-text {
  min-width: 6.2rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- What a rule asks of a packet, one thing at a time: each marked by what it is. ---
   A chip is a word on a ground of its kind's colour. The arrows between them are the way
   of a packet, read from left to right: from where it comes, by the interface it comes
   in, to where it goes, by the interface it leaves. */
.chip {
  padding: 0.05rem 0.4rem;
  white-space: nowrap;
  background: var(--chip-list);
  border-radius: var(--radius);
}

.chip.network,
.chip.address {
  background: var(--chip-network);
}

.chip.interface {
  background: var(--chip-interface);
}

.chip.vlan {
  background: var(--chip-vlan);
}

.chip.service {
  background: var(--chip-service);
}

/* Everything but what follows: the sign stands before its chip and joins it. */
.chip-not {
  padding: 0.05rem 0.35rem;
  font-weight: 700;
  color: var(--on-chip-not);
  background: var(--chip-not);
  border-radius: var(--radius) 0 0 var(--radius);
}

.chip-not + .chip {
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* Before plain words it stands by itself. */
.chip-not.alone {
  margin-right: 0.3rem;
  border-radius: var(--radius);
}

.term {
  display: inline-block;
  margin: 0.1rem 0.3rem 0.1rem 0;
  white-space: nowrap;
}

.term-way {
  color: var(--text-muted);
}

/* A rate over time as a small line: in a row of a table, or larger in a window. */
.spark {
  display: block;
  max-width: 100%;
}

.spark path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* What went back out, where a line is drawn for each way: as in the bars beside it. */
.spark path.out {
  stroke: var(--ok);
}

.spark.large {
  width: 100%;
  height: auto;
  border-bottom: 1px solid var(--border);
}

/* A rate over time with both its scales: the rates on the left, the times below. */
.rate-chart {
  display: block;
  width: 100%;
  height: auto;
}

.rate-chart path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rate-chart path.out {
  stroke: var(--ok);
}

.rate-chart .grid,
.rate-chart .tick {
  stroke: var(--border);
  stroke-width: 1;
}

.rate-chart text {
  font-size: 11px;
  fill: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.rate-chart .level {
  text-anchor: end;
}

.rate-chart .moment {
  text-anchor: middle;
}

/* The times at the two ends stay inside the drawing. */
.rate-chart .moment.first {
  text-anchor: start;
}

.rate-chart .moment.last {
  text-anchor: end;
}

.spark-scale {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.3rem 0 1rem;
  font-size: 0.87rem;
  color: var(--text-muted);
}

/* --- Swatch: the colour a network was given, shown wherever the network is named.
   A rectangle twice as wide as high, so that it is never taken for the dot of a state. --- */
.swatch {
  flex: none;
  width: 1.1rem;
  height: 0.55rem;
  margin-right: 0.35rem;
  vertical-align: 0.02rem;
}

.swatch.none rect {
  fill: none;
  stroke: var(--border);
}

/* The number of a network behind its mark: as wide as the longest number there is, so
   that in a column the marks stand below each other, be the number 1, 46 or 4094. */
.net-id {
  display: inline-block;
  min-width: 4ch;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* A choice with few options: every option is a button, the chosen ones are pressed. */
.choice {
  display: flex;
  flex-wrap: wrap;
}

.choice button {
  border-radius: 0;
  margin-left: -1px;
}

.choice button:first-child {
  margin-left: 0;
  border-radius: var(--radius) 0 0 var(--radius);
}

.choice button:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.choice button[aria-checked="true"],
.choice button[aria-pressed="true"] {
  position: relative;
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

/* A yes/no setting: one button that shows and switches its state. */
/* A slide switch: a track with a knob that sits left for off and right for on. The word
   beside it says which it is. */
.toggle {
  gap: 0.6rem;
  justify-content: flex-start;
  padding: 0;
  font-weight: 400;
  color: var(--text);
  background: transparent;
  border-color: transparent;
}

.toggle:hover:not(:disabled) {
  background: transparent;
}

.toggle::before {
  content: "";
  flex: none;
  width: 2.6rem;
  height: 1.4rem;
  background:
    radial-gradient(circle at 0.7rem 50%, var(--surface) 0.48rem, transparent 0.52rem) var(--off);
  border-radius: 1rem;
}

.toggle[aria-checked="true"]::before {
  background:
    radial-gradient(circle at calc(100% - 0.7rem) 50%, var(--on-accent) 0.48rem, transparent 0.52rem)
    var(--accent);
}

.toggle:disabled {
  opacity: 0.6;
}

/* --- Dialog --- */
.dialog {
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.1rem 1.25rem;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: var(--backdrop);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* --- Menu at the mouse: what can be done with the thing that was clicked --- */
.context-menu {
  position: fixed;
  z-index: 40;
  min-width: 13rem;
  max-width: min(26rem, calc(100vw - 0.5rem));
  padding: 0.25rem 0;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.context-menu button {
  display: block;
  width: 100%;
  min-height: 0;
  padding: 0.4rem 0.8rem;
  overflow: hidden;
  font-weight: 400;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: none;
  border: 0;
  border-radius: 0;
}

.context-menu button:hover:not(:disabled),
.context-menu button:focus-visible {
  background: var(--row-hover);
  outline: none;
}

.context-menu hr {
  margin: 0.25rem 0;
  border: 0;
  border-top: 1px solid var(--border);
}

/* The notice that the server does not answer: it lies over everything until it does. */
.connection-lost {
  border-left: 4px solid var(--lamp-error);
}

.connection-lost h2 {
  margin: 0 0 0.6rem;
}

.connection-lost p {
  margin: 0 0 0.6rem;
}

.connection-lost p:last-child {
  margin-bottom: 0;
}

/* --- Modal: a window over the page for one entity, to look at or to edit ---
   Its head is the status line of a page in small: title, remark, actions at the top right.
   The dialog has no padding, so a click on it is a click beside the box. */
.modal {
  width: min(40rem, calc(100vw - 2rem));
  max-width: none;
  max-height: calc(100vh - 2rem);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal.wide {
  width: min(84rem, calc(100vw - 2rem));
}

.modal.double {
  width: min(66rem, calc(100vw - 2rem));
}

.modal::backdrop {
  background: var(--backdrop);
}

.modal-box {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2rem - 2px);
}

.modal-head {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1rem;
  min-height: var(--statusbar-height);
  padding: 0.5rem 0.75rem 0.5rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  font-size: 1.1rem;
}

.modal-body {
  padding: 1.25rem 1.25rem 0.25rem;
  overflow: auto;
}

/* A window keeps its height when its tabs are switched: all panels lie in the same place,
   the ones not on show invisible, so that the tallest of them sets the height. */
.modal .tabs {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.modal .tabs > [role="tabpanel"] {
  grid-area: 2 / 1;
}

.modal .tabs > [role="tabpanel"][hidden] {
  display: block !important;
  visibility: hidden;
}

/* The window is the frame: the content of a tab is no tile of its own inside it, which
   would only add lines and one more level of nesting. */
.modal .tabs > .panel {
  margin-bottom: 0;
  background: none;
  border: 0;
  border-radius: 0;
}

.modal .tabs > .panel > .panel-head {
  padding-right: 0;
  padding-left: 0;
  border-bottom: 0;
}

.modal .tabs > .panel .panel-body,
.modal .tabs > .panel .dt-toolbar,
.modal .tabs > .panel .dt-pager {
  padding-right: 0;
  padding-left: 0;
}

/* The same holds for every tile in a window, whether it has the window to itself or
   shares it: the window is the frame. What tells tiles apart there is the heading each
   has and the space between them. */
.modal-body .panel {
  background: none;
  border: 0;
  border-radius: 0;
}

.modal-body > .panel:last-child {
  margin-bottom: 0;
}

.modal-body .panel > .panel-head {
  padding-right: 0;
  padding-left: 0;
  border-bottom: 0;
}

.modal-body .panel > .panel-body,
.modal-body .panel .dt-toolbar,
.modal-body .panel .dt-pager {
  padding-right: 0;
  padding-left: 0;
}

/* A tile without a heading begins where the window does. */
.modal-body .panel > .panel-body:first-child {
  padding-top: 0;
}

/* A form fills the window it has to itself; in a wide window it keeps its own width. */
.modal:not(.wide) .modal-body .form {
  max-width: none;
}

/* A form with more fields than fit one below the other: two columns in a wide window, one
   where there is no room for two. */
.modal .modal-body .form.columns {
  max-width: none;
}

.form.columns > .panel-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
  gap: 0 2.5rem;
  align-items: start;
}

.form.columns .form-section {
  margin-top: 0;
}

.form.columns .form-section ~ .form-section {
  margin-top: 1.5rem;
}

/* A list to pick several from is as high as it says itself here: the form is meant to be
   seen at once, and the list is one field of many. */
.form.columns select[multiple] {
  min-height: 0;
}

/* What spans the columns: a remark below them, or the buttons. */
.form.columns .across {
  grid-column: 1 / -1;
}

/* Two fields that belong together in one line: a long one and a short one beside it. */
.field-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7rem;
  gap: 0 1rem;
  align-items: start;
}
