:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f6f8;
  color: #17212b;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #f4f6f8;
}

body {
  min-height: 100vh;
  margin: 0;
  background: #f4f6f8;
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #74a7ee;
  outline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 19px;
  line-height: 1.2;
}

h2 {
  font-size: 24px;
  line-height: 1.25;
}

h3 {
  font-size: 15px;
  line-height: 1.35;
}

svg {
  display: block;
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.eyebrow {
  color: #657280;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  text-transform: uppercase;
}

.muted,
.field-hint {
  color: #697887;
  font-size: 12px;
  line-height: 1.45;
}

.login-view {
  display: grid;
  min-height: 100vh;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  place-items: center;
  background: #e9eef1;
}

.login-panel {
  display: grid;
  gap: 22px;
  width: min(100%, 390px);
  padding: 30px;
  border: 1px solid #cfd8de;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 50px rgb(28 49 59 / 12%);
}

.brand-mark {
  border-radius: 8px;
}

.login-subtitle {
  margin-top: 5px;
  color: #526170;
  font-size: 14px;
}

.form-error {
  padding: 10px 12px;
  border-left: 3px solid #bf3b30;
  background: #fff0ee;
  color: #8f241c;
  font-size: 13px;
  line-height: 1.4;
}

.app-view {
  min-height: 100vh;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid #31564f;
  background: #143c35;
  color: #ffffff;
  padding-top: env(safe-area-inset-top);
}

.header-inner,
.account-inner,
.tab-inner,
.main-content {
  width: min(100%, 1120px);
  margin-inline: auto;
}

.header-inner {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
}

.brand-lockup {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
}

.brand-lockup img {
  flex: 0 0 auto;
  border-radius: 7px;
}

.brand-lockup .eyebrow {
  color: #acd3c4;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
}

.usage-summary {
  max-width: 180px;
  overflow: hidden;
  color: #dce9e5;
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: inline-flex;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid #bfcbd2;
  border-radius: 6px;
  background: #ffffff;
  color: #31404e;
}

.icon-button:hover {
  border-color: #82939e;
  background: #f0f4f6;
}

.header-button {
  border-color: #487067;
  background: #204b43;
  color: #ffffff;
}

.header-button:hover {
  border-color: #6c968c;
  background: #2a5a50;
}

.icon-button-danger {
  color: #a12e25;
}

.account-band {
  border-bottom: 1px solid #d5dde2;
  background: #ffffff;
}

.account-inner {
  display: grid;
  grid-template-columns: auto minmax(180px, 360px) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
}

.account-select-label {
  color: #5d6a77;
  font-size: 12px;
  font-weight: 800;
}

.account-select {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 6px 34px 6px 10px;
  border: 1px solid #bfcbd2;
  border-radius: 6px;
  background: #ffffff;
  color: #18232c;
  font-weight: 700;
}

.account-tools {
  display: flex;
  gap: 7px;
}

.tab-bar {
  position: sticky;
  z-index: 15;
  top: calc(64px + env(safe-area-inset-top));
  border-bottom: 1px solid #d5dde2;
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(8px);
}

.tab-inner {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding-inline: 20px;
}

.tab-button {
  display: inline-flex;
  min-width: 0;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: #5f6d79;
  font-size: 13px;
  font-weight: 750;
}

.tab-button:hover {
  background: #f3f6f7;
  color: #23313c;
}

.tab-button.is-active {
  border-bottom-color: #2f896c;
  color: #155b47;
}

.main-content {
  padding: 28px 20px calc(44px + env(safe-area-inset-bottom));
}

.tab-panel {
  display: grid;
  gap: 22px;
}

.section-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading > div {
  min-width: 0;
}

.section-heading h2 {
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.status-chip {
  display: inline-flex;
  min-height: 30px;
  flex: 0 0 auto;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-good {
  background: #dcf4e8;
  color: #176442;
}

.status-warning {
  background: #fff0c9;
  color: #79540e;
}

.status-bad {
  background: #fee8e5;
  color: #9f2b22;
}

.status-neutral {
  background: #e8edf0;
  color: #53626e;
}

.relay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.action-button,
.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid #167052;
  border-radius: 6px;
  background: #167052;
  color: #ffffff;
  font-weight: 800;
}

.action-button:hover,
.button-primary:hover {
  border-color: #0f5b42;
  background: #0f5b42;
}

.action-button-secondary,
.button-secondary {
  border-color: #aebbc3;
  background: #ffffff;
  color: #293845;
}

.action-button-secondary:hover,
.button-secondary:hover {
  border-color: #7f909b;
  background: #edf2f4;
}

.button-primary {
  border-color: #167052;
  background: #167052;
}

.button-danger-text {
  border-color: #d5a9a4;
  background: #ffffff;
  color: #a12e25;
}

.button-danger-text:hover {
  border-color: #ba6259;
  background: #fff1ef;
}

.button-wide {
  width: 100%;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  display: grid;
  min-width: 0;
  min-height: 104px;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  padding: 16px;
  border: 1px solid #d4dce1;
  border-radius: 8px;
  background: #ffffff;
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  color: #1b2731;
  font-size: 15px;
  line-height: 1.35;
}

.metric-label {
  display: block;
  color: #697682;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
  text-transform: uppercase;
}

.metric-icon {
  display: grid;
  width: 38px;
  height: 38px;
  border-radius: 7px;
  place-items: center;
}

.metric-icon-green {
  background: #daf1e6;
  color: #196044;
}

.metric-icon-blue {
  background: #e1edfb;
  color: #285f9c;
}

.metric-icon-yellow {
  background: #fff0c9;
  color: #805a0c;
}

.metric-icon-coral {
  background: #fde7e3;
  color: #a33d33;
}

.status-details,
.backup-band {
  border-top: 1px solid #d6dee3;
  border-bottom: 1px solid #d6dee3;
  background: #ffffff;
}

.status-details dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
}

.status-details dl > div {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(130px, 0.7fr) minmax(0, 1.3fr);
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #edf0f2;
}

.status-details dl > div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.status-details dt {
  color: #66737f;
  font-size: 12px;
  font-weight: 750;
}

.status-details dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: #25323d;
  font-size: 13px;
  line-height: 1.4;
}

.backup-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
}

.backup-band p {
  margin-top: 4px;
}

.link-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(320px, 1.2fr);
  gap: 28px;
}

.pairing-section,
.qr-section {
  min-width: 0;
}

.pairing-section {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
  padding-block: 8px;
}

.stack-form {
  display: grid;
  gap: 14px;
  width: 100%;
}

.field {
  display: grid;
  min-width: 0;
  gap: 7px;
  color: #364653;
  font-size: 12px;
  font-weight: 750;
}

.field > span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #b8c5cc;
  border-radius: 6px;
  background: #ffffff;
  color: #18242e;
}

input:hover,
select:hover {
  border-color: #82949f;
}

input::placeholder {
  color: #8a969f;
}

.pairing-code-block {
  width: 100%;
  padding: 18px;
  border: 1px solid #9ac8b8;
  border-radius: 8px;
  background: #eef8f4;
}

.pairing-code {
  display: block;
  min-height: 48px;
  margin-block: 6px 8px;
  overflow-wrap: anywhere;
  color: #123f32;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 31px;
  font-weight: 800;
  line-height: 1.3;
}

.qr-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.qr-frame {
  display: grid;
  width: min(100%, 540px);
  aspect-ratio: 1 / 1;
  min-height: 300px;
  overflow: hidden;
  border: 1px solid #ccd6dc;
  border-radius: 8px;
  background: #ffffff;
  place-items: center;
}

.qr-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  color: #71808c;
  font-size: 13px;
  font-weight: 700;
}

.empty-state svg {
  width: 36px;
  height: 36px;
}

.settings-form {
  display: grid;
  gap: 20px;
}

.form-section {
  display: grid;
  gap: 15px;
  min-width: 0;
  margin: 0;
  padding: 18px;
  border: 1px solid #d2dbe0;
  border-radius: 8px;
  background: #ffffff;
}

.form-section legend {
  padding-inline: 6px;
  color: #25333e;
  font-size: 14px;
  font-weight: 850;
}

.provider-fields {
  display: grid;
  gap: 14px;
}

.field-badge {
  display: inline-block;
  margin-left: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #edf1f3;
  color: #62717d;
  font-size: 10px;
  font-weight: 800;
  vertical-align: middle;
}

.field-badge.is-configured {
  background: #dbf1e7;
  color: #176042;
}

.toggle-row {
  display: grid;
  min-height: 64px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  cursor: pointer;
}

.toggle-row > span:first-child {
  display: grid;
  gap: 3px;
}

.toggle-row strong {
  color: #2a3944;
  font-size: 13px;
}

.toggle-row small {
  color: #6d7b86;
  font-size: 11px;
  line-height: 1.4;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle {
  position: relative;
  width: 46px;
  height: 26px;
  border: 1px solid #aab7bf;
  border-radius: 999px;
  background: #cfd7dc;
  transition: background 140ms ease, border-color 140ms ease;
}

.toggle::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgb(19 35 43 / 28%);
  content: "";
  transition: transform 140ms ease;
}

.toggle-row input:checked + .toggle {
  border-color: #167052;
  background: #218263;
}

.toggle-row input:checked + .toggle::after {
  transform: translateX(20px);
}

.toggle-row input:focus-visible + .toggle {
  outline: 3px solid #74a7ee;
  outline-offset: 2px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.import-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 14px;
}

.log-output {
  min-height: 480px;
  max-height: 68vh;
  margin: 0;
  overflow: auto;
  padding: 16px;
  border: 1px solid #2e3b43;
  border-radius: 8px;
  background: #182229;
  color: #dce8e4;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.dialog {
  width: min(calc(100% - 32px), 440px);
  padding: 0;
  border: 1px solid #bfcbd2;
  border-radius: 8px;
  background: #ffffff;
  color: #17212b;
  box-shadow: 0 24px 70px rgb(21 36 44 / 28%);
}

.dialog::backdrop {
  background: rgb(11 25 30 / 54%);
}

.dialog form {
  display: grid;
  gap: 20px;
  padding: 20px;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.dialog-heading h2 {
  margin-top: 4px;
  font-size: 20px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(calc(100% - 36px), 420px);
  padding: 12px 14px;
  border-left: 4px solid #208061;
  border-radius: 6px;
  background: #152c27;
  color: #ffffff;
  box-shadow: 0 12px 34px rgb(16 32 38 / 24%);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

.toast.is-error {
  border-left-color: #e26155;
  background: #4b211e;
}

.is-busy #refresh-button svg {
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 860px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-details dl,
  .link-layout {
    grid-template-columns: 1fr;
  }

  .status-details dl > div:nth-last-child(2) {
    border-bottom: 1px solid #edf0f2;
  }

  .qr-frame {
    width: min(100%, 460px);
  }
}

@media (max-width: 600px) {
  h2 {
    font-size: 21px;
  }

  .header-inner {
    min-height: 60px;
    padding-inline: 14px;
  }

  .brand-lockup img {
    width: 36px;
    height: 36px;
  }

  .brand-lockup h1 {
    font-size: 16px;
  }

  .usage-summary {
    display: none;
  }

  .account-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    padding-inline: 14px;
  }

  .account-select-label {
    grid-column: 1 / -1;
  }

  .account-tools .icon-button {
    width: 36px;
    height: 38px;
    flex-basis: 36px;
  }

  .tab-bar {
    top: calc(60px + env(safe-area-inset-top));
  }

  .tab-inner {
    padding-inline: 0;
  }

  .tab-button {
    min-height: 56px;
    flex-direction: column;
    gap: 3px;
    padding: 6px 3px;
    font-size: 10px;
  }

  .tab-button svg {
    width: 19px;
    height: 19px;
  }

  .main-content {
    padding: 22px 14px calc(34px + env(safe-area-inset-bottom));
  }

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

  .status-chip {
    max-width: 43%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .relay-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .action-button {
    min-width: 0;
    padding-inline: 7px;
    font-size: 12px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 86px;
    align-items: center;
  }

  .status-details dl > div {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .backup-band {
    align-items: flex-start;
    flex-direction: column;
  }

  .pairing-code {
    font-size: 27px;
  }

  .qr-frame {
    min-height: 260px;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .import-row {
    grid-template-columns: 1fr;
  }

  .import-row .button {
    width: 100%;
  }

  .form-section {
    padding: 15px;
  }

  .form-actions .button,
  .stack-form .button {
    width: 100%;
  }

  .log-output {
    min-height: 400px;
    font-size: 11px;
  }
}

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