/* Shared layout guardrails: keep readable text and controls inside their boxes. */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

.shell {
  display: block;
  --sidebar-column: 232px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-column);
  height: 100vh;
  min-height: 100vh;
  min-width: 0;
}

main {
  width: auto;
  min-width: 0;
  max-width: none;
  margin: 0 0 0 var(--sidebar-column);
}

.content {
  width: 100%;
  max-width: none;
  margin-inline: 0;
}

body,
main,
.content,
.panel,
form,
fieldset,
dialog,
.table-scroll,
.routing-device-card {
  min-width: 0;
}

p,
small,
label,
legend,
dt,
dd,
th,
td,
.notice,
.error,
.site-review-note,
.routing-snapshot-status,
button,
.button,
a {
  overflow-wrap: anywhere;
}

p,
li,
dd,
label,
label small,
.notice,
.error {
  line-height: 1.55;
}

label {
  gap: .45rem;
  line-height: 1.4;
}

label small {
  display: block;
  line-height: 1.5;
}

input,
select,
textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  padding: .65rem .75rem;
  line-height: 1.4;
  font: inherit;
}

input[type="checkbox"],
input[type="radio"] {
  display: inline-block;
  width: 1.2rem;
  min-width: 1.2rem;
  max-width: 1.2rem;
  min-height: 1.2rem;
  padding: 0;
  flex: 0 0 1.2rem;
  line-height: normal;
}

textarea {
  min-height: 7rem;
  resize: vertical;
}

button,
.button {
  min-width: 0;
  min-height: 2.65rem;
  line-height: 1.35;
  white-space: normal;
  text-align: center;
}

button.icon-button {
  width: 2.5rem;
  min-width: 2.5rem;
  height: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  flex: 0 0 2.5rem;
}

.form-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.form-row > *,
.form-row label,
.settings-row > *,
.panel-heading > *,
.dialog-heading > * {
  min-width: 0;
}

.dialog-heading {
  align-items: flex-start;
}

.dialog-heading h2,
.dialog-heading h3 {
  max-width: 100%;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.dialog-heading .icon-button {
  flex: 0 0 auto;
}

dialog {
  max-width: min(980px, calc(100vw - 2rem));
  max-height: min(90dvh, 1000px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  line-height: 1.55;
}

dialog form {
  min-width: 0;
}

.dialog-actions {
  align-items: center;
  row-gap: .65rem;
}

.dialog-actions > button,
.dialog-actions > .button {
  flex: 0 1 auto;
  max-width: 100%;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.table-scroll table {
  min-width: max-content;
}

.table-scroll td,
.table-scroll th {
  vertical-align: top;
}

.vrf-card,
.connection-end,
.site-address-card,
.routing-device-card,
.site-test-run,
.site-test-direction {
  min-width: 0;
}

.vrf-card h3,
.connection-end h3,
.site-address-card h3,
.routing-device-card h3 {
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.vrf-card dl,
.diagnostics-grid,
.settings-row,
.guide-columns,
.section-directory {
  min-width: 0;
}

@media (max-width: 700px) {
  .form-row,
  .site-path,
  .site-test-directions,
  #connection-ends,
  .site-addresses,
  .diagnostics-grid,
  .guide-columns,
  .section-directory {
    grid-template-columns: minmax(0, 1fr);
  }

  .dialog-actions {
    justify-content: flex-start;
  }

  .dialog-actions > button,
  .dialog-actions > .button {
    flex: 1 1 9rem;
  }

  .dialog-actions [data-close] {
    margin-right: 0;
  }

  .compact-actions [data-close] {
    margin-right: 0;
  }

  .filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .filters input,
  .filters select {
    width: 100%;
    max-width: none;
  }

  .table-footer {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: .5rem 1rem;
  }

  .site-test-run header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 1150px) {
  .shell {
    --sidebar-column: 195px;
  }
}

@media (max-width: 850px) {
  .shell {
    --sidebar-column: 74px;
  }
}

@media (max-width: 520px) {
  .shell {
    --sidebar-column: 56px;
  }

  .sidebar {
    padding-inline: 6px;
  }

  .brand {
    justify-content: center;
    padding-inline: 0;
  }

  .nav-item {
    padding-inline: 5px;
  }

  dialog {
    width: calc(100vw - 1rem);
    max-width: calc(100vw - 1rem);
    max-height: calc(100dvh - 1rem);
    padding: 1rem;
    border-radius: .75rem;
  }

  .dialog-heading {
    gap: .75rem;
    margin-bottom: 1rem;
  }

  .dialog-heading h2 {
    font-size: 1.3rem;
    letter-spacing: -.02em;
  }

  .dialog-actions {
    gap: .5rem;
    margin-top: 1.15rem;
    padding-top: 1rem;
  }

  .dialog-actions > button,
  .dialog-actions > .button {
    flex: 1 1 100%;
  }

  .config-dialog pre {
    max-width: 100%;
    padding: .85rem;
    font-size: .75rem;
    line-height: 1.55;
  }

  .settings-content,
  .guide-content {
    padding-inline: 1rem;
  }

  .routing-device-card {
    padding: .8rem;
  }

  .routing-device-card > header {
    align-items: flex-start;
    flex-direction: column;
  }

  .routing-device-card > header .button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
