:root {
  color-scheme: dark;
  --black: #000000;
  --surface-100: #0a0a0a;
  --surface-200: #111111;
  --surface-300: #1a1a1a;
  --surface-400: #242424;
  --surface-500: #2e2e2e;
  --white: #ffffff;
  --gray-100: #e8e8e8;
  --gray-200: #cccccc;
  --gray-300: #aaaaaa;
  --gray-400: #888888;
  --gray-500: #666666;
  --gray-600: #444444;
  --gray-700: #333333;
  --divider: #222222;
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono-font: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  background: var(--black);
  color: var(--white);
  overflow: hidden;
}

body {
  font-family: var(--ui-font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button,
input {
  font: inherit;
}

button {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  touch-action: manipulation;
}

input {
  appearance: none;
  -webkit-appearance: none;
}

#app {
  min-height: 100vh;
  height: 100vh;
  height: 100svh;
  min-height: 100dvh;
  height: 100dvh;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100%;
  min-height: 100dvh;
  min-height: 0;
  background: var(--black);
  overflow: hidden;
}

.connection-strip {
  background: var(--surface-100);
  border-bottom: 1px solid var(--divider);
  padding: calc(8px + var(--safe-top)) calc(16px + var(--safe-right)) 8px calc(16px + var(--safe-left));
}

.connection-strip__body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.connection-strip__main {
  min-width: 0;
  flex: 1;
}

.content-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  padding: 0 calc(20px + var(--safe-right)) calc(88px + var(--safe-bottom)) calc(20px + var(--safe-left));
}

.screen {
  padding: 24px 0 16px;
}

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

.screen-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--white);
}

.section-header {
  margin: 20px 0 12px;
}

.section-header__title,
.section-subtitle,
.meta-label,
.input-label {
  font-size: 10px;
  line-height: 1.2;
  font-weight: 500;
  letter-spacing: 0.24em;
  color: var(--gray-500);
}

.section-header__line {
  margin-top: 8px;
  height: 1px;
  background: var(--divider);
}

.section-subtitle {
  margin-bottom: 10px;
}

.stack {
  display: grid;
  gap: 8px;
}

.spacer-8 {
  height: 8px;
}

.spacer-16 {
  height: 16px;
}

.card,
.list-card,
.metric-row,
.esp-bar {
  background: var(--surface-200);
  border: 1px solid var(--surface-400);
  border-radius: 8px;
}

.card {
  padding: 14px;
  margin-bottom: 12px;
}

.list-card,
.metric-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
}

.list-card--button {
  text-align: left;
}

.list-card.selected {
  background: var(--surface-300);
}

.list-card.inverse {
  background: var(--white);
  color: var(--black);
}

.list-card__right,
.inline-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-command__body {
  flex: 1;
  min-width: 0;
}

.command-label {
  font-size: 14px;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: inherit;
}

.meta-value {
  font-size: 13px;
  line-height: 1.35;
  font-weight: 400;
  color: var(--gray-200);
}

.meta-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}

.meta-row__label {
  flex: 1;
  font-size: 12px;
  line-height: 1.35;
  color: var(--gray-400);
}

.meta-row__value {
  flex: 2;
  text-align: right;
  font-size: 13px;
  line-height: 1.35;
  color: var(--gray-200);
  word-break: break-word;
}

.mono,
.mono-small,
.meta-row__value.mono,
.endpoint-row {
  font-family: var(--mono-font);
}

.mono {
  font-size: 11px;
  line-height: 1.35;
  color: var(--gray-300);
}

.mono-small {
  font-size: 10px;
  line-height: 1.35;
  color: var(--gray-500);
}

.dim {
  color: var(--gray-600);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 12px 20px;
  border-radius: 2px;
  border: 1px solid transparent;
  font-size: 14px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

.btn:disabled,
.action-tile:disabled,
.bottom-nav__item:disabled {
  cursor: default;
  opacity: 0.55;
}

.btn.primary {
  background: var(--white);
  color: var(--black);
  border-color: var(--white);
}

.btn.secondary {
  background: var(--surface-200);
  color: var(--gray-200);
  border-color: var(--surface-500);
}

.btn.full {
  width: 100%;
}

.btn.small,
.btn.tiny {
  min-height: 40px;
  padding: 10px 14px;
  font-size: 12px;
}

.button-grid,
.filter-grid,
.tile-grid {
  display: grid;
  gap: 8px;
}

.button-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}

.button-grid--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.filter-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

.tile-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
}

.action-tile {
  width: 100%;
  min-height: 52px;
  padding: 12px;
  text-align: left;
  background: var(--surface-300);
  border: 1px solid var(--surface-500);
  border-radius: 2px;
}

.action-tile.disabled {
  background: var(--surface-100);
}

.action-tile.span-full {
  grid-column: 1 / -1;
}

.esp-bar {
  display: flex;
  align-items: center;
  min-height: 56px;
  margin-top: 12px;
  padding: 0 12px;
  background: var(--surface-300);
  border-color: var(--surface-500);
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 6px;
  background: var(--surface-300);
  border: 1px solid var(--surface-400);
}

.banner--error {
  border-color: var(--surface-500);
}

.banner__icon {
  width: 16px;
  font-size: 14px;
  line-height: 1.2;
  color: var(--gray-400);
  flex: 0 0 auto;
}

.banner__text {
  font-size: 14px;
  line-height: 1.35;
  color: var(--gray-200);
}

.status-dot {
  width: 11px;
  height: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--gray-300);
  background: var(--surface-300);
  color: var(--gray-300);
  font-size: 7px;
  line-height: 1;
  flex: 0 0 auto;
}

.status-dot.is-on {
  background: var(--white);
}

.status-dot.is-off {
  background: var(--black);
}

.status-dot.inverse {
  border-color: var(--black);
  color: var(--black);
}

.connection-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.connection-state__dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--gray-700);
}

.connection-state.online .connection-state__dot,
.connection-state.online .mono-small {
  background: var(--white);
  color: var(--white);
}

.connection-state.offline .connection-state__dot,
.connection-state.offline .mono-small {
  background: var(--gray-600);
  color: var(--gray-600);
}

.connection-state.unauthorized .connection-state__dot,
.connection-state.unauthorized .mono-small {
  background: var(--gray-500);
  color: var(--gray-500);
}

.connection-state.checking .connection-state__dot,
.connection-state.checking .mono-small {
  background: var(--gray-300);
  color: var(--gray-300);
}

.connection-state.unreachable .connection-state__dot,
.connection-state.unreachable .mono-small {
  background: var(--gray-400);
  color: var(--gray-400);
}

.connection-state.unknown .connection-state__dot,
.connection-state.unknown .mono-small {
  background: var(--gray-700);
  color: var(--gray-700);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--surface-500);
  background: var(--surface-300);
  font-size: 11px;
  line-height: 1;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gray-300);
  flex: 0 0 auto;
}

.status-succeeded {
  color: var(--white);
}

.status-running {
  color: var(--gray-100);
}

.status-dispatched,
.status-acked {
  color: var(--gray-300);
}

.status-queued,
.status-accepted {
  color: var(--gray-400);
}

.status-failed {
  color: var(--gray-400);
}

.status-expired,
.status-cancelled {
  color: var(--gray-600);
}

.form-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.input-group {
  display: grid;
  gap: 6px;
}

.text-input {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid var(--surface-500);
  background: var(--surface-200);
  color: var(--gray-100);
  font-size: 16px;
  line-height: 1.35;
}

.text-input::placeholder {
  color: var(--gray-600);
}

.token-input-wrap {
  position: relative;
}

.token-input {
  padding-right: 68px;
}

.token-toggle {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 64px;
  height: 100%;
  padding: 0 12px;
  color: var(--gray-500);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.profile-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

.profile-row .grow {
  flex: 1;
}

.align-end {
  margin-bottom: 0;
  min-width: 150px;
}

.endpoint-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
}

.empty-card,
.empty-text {
  color: var(--gray-600);
}

.empty-card {
  padding: 14px;
  font-family: var(--mono-font);
  font-size: 11px;
}

.json-block {
  margin-top: 6px;
}

.bottom-nav {
  display: flex;
  flex: 0 0 auto;
  align-items: stretch;
  width: 100%;
  background: var(--surface-100);
  border-top: 1px solid var(--divider);
  padding: 4px calc(8px + var(--safe-right)) calc(4px + var(--safe-bottom)) calc(8px + var(--safe-left));
}

.bottom-nav__item {
  display: flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 58px;
  padding: 10px 6px;
  color: var(--gray-600);
}

.bottom-nav__item.active {
  flex: 1.8 1 0;
  color: var(--white);
}

.bottom-nav__icon {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.bottom-nav__icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.bottom-nav__label {
  display: none;
  font-family: var(--mono-font);
  font-size: 8px;
  line-height: 1.1;
  letter-spacing: 0;
  text-align: center;
}

.bottom-nav__item.active .bottom-nav__label {
  display: inline-block;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.8);
  z-index: 50;
}

.modal-card {
  width: min(420px, 100%);
  padding: 18px;
  border-radius: 8px;
  border: 1px solid var(--surface-500);
  background: var(--surface-100);
}

@media (max-width: 420px) {
  .content-scroll {
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
  }

  .button-grid--three {
    grid-template-columns: 1fr;
  }

  .profile-row {
    flex-direction: column;
    align-items: stretch;
  }

  .align-end {
    min-width: 0;
  }

  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 960px) {
  body {
    background:
      radial-gradient(circle at top, #171717 0%, #050505 42%, #000000 100%);
  }

  .app-shell {
    width: min(100%, 560px);
    margin: 0 auto;
    border-left: 1px solid var(--divider);
    border-right: 1px solid var(--divider);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.03), 0 30px 80px rgba(0, 0, 0, 0.6);
  }
}
