:root {
  color-scheme: light;
  --bg: #f5fbff;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-strong: #ffffff;
  --surface-soft: rgba(26, 155, 230, 0.06);
  --text: #0f2433;
  --muted: #5d7684;
  --line: rgba(15, 36, 51, 0.1);
  --line-strong: rgba(15, 36, 51, 0.16);
  --blue: #1ba5e3;
  --blue-deep: #0f78bf;
  --green: #64d26d;
  --green-deep: #2ba85a;
  --idle: #8ba2ae;
  --error: #d45c5c;
  --shadow: 0 26px 70px rgba(29, 116, 171, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at 12% 12%, rgba(100, 210, 109, 0.2), transparent 22%),
    radial-gradient(circle at 88% 10%, rgba(27, 165, 227, 0.18), transparent 24%),
    linear-gradient(160deg, #ffffff 0%, #f5fbff 54%, #e8f7f4 100%);
  color: var(--text);
  font-family: "Manrope", "Segoe UI", sans-serif;
}

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

[x-cloak] {
  display: none !important;
}

.page {
  width: min(1180px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1.4rem 0 3rem;
}

.masthead {
  margin-bottom: 1.3rem;
}

h1,
h2 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

h1 {
  font-size: clamp(2.6rem, 7vw, 4.2rem);
}

h2 {
  font-size: clamp(1.35rem, 2vw, 1.8rem);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.2rem;
  align-items: start;
}

.card {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.session-card {
  padding: 1.45rem;
}

.log-card {
  padding: 1rem;
}

.status-row {
  display: flex;
  justify-content: flex-end;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.log-head {
  margin-bottom: 0.8rem;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.status-chip.is-idle {
  background: rgba(139, 162, 174, 0.14);
  color: var(--idle);
}

.status-chip.is-pending {
  background: rgba(27, 165, 227, 0.12);
  color: var(--blue-deep);
}

.status-chip.is-live {
  background: rgba(100, 210, 109, 0.15);
  color: var(--green-deep);
}

.status-dot {
  width: 0.58rem;
  height: 0.58rem;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 0.18rem rgba(255, 255, 255, 0.7);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  margin-top: 1.2rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.field:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.field span,
.topic-label {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid rgba(15, 36, 51, 0.12);
  border-radius: 18px;
  background: var(--surface-strong);
  color: var(--text);
  padding: 0.95rem 1rem;
  font: inherit;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease;
}

.field textarea {
  min-height: 14rem;
  resize: none;
  overflow-y: hidden;
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
  font-size: 0.95rem;
  line-height: 1.55;
}

.field input:focus,
.field textarea:focus,
.primary-button:focus {
  outline: none;
  border-color: rgba(15, 120, 191, 0.3);
  box-shadow: 0 0 0 0.22rem rgba(27, 165, 227, 0.14);
}

.field input:disabled,
.field textarea:disabled {
  color: rgba(15, 36, 51, 0.72);
  background: rgba(248, 252, 255, 0.84);
}

.topic-preview {
  display: grid;
  gap: 0.55rem;
  margin-top: 1.15rem;
  padding: 0.95rem 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-soft);
}

code {
  display: inline-block;
  max-width: 100%;
  padding: 0.2rem 0.4rem;
  border-radius: 0.45rem;
  background: rgba(15, 36, 51, 0.06);
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.action-row {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  margin-top: 1.2rem;
}

.primary-button {
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--green) 0%, var(--blue) 48%, var(--blue-deep) 100%);
  color: #f8ffff;
  padding: 0.95rem 1.35rem;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 18px 38px rgba(15, 120, 191, 0.22);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    opacity 120ms ease;
}

.primary-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  box-shadow: none;
}

.secondary-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--blue-deep);
  padding: 0.58rem 0.9rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition:
    border-color 120ms ease,
    background-color 120ms ease,
    opacity 120ms ease;
}

.secondary-button:hover:not(:disabled) {
  border-color: rgba(15, 120, 191, 0.24);
  background: rgba(27, 165, 227, 0.08);
}

.secondary-button:focus {
  outline: none;
  border-color: rgba(15, 120, 191, 0.3);
  box-shadow: 0 0 0 0.22rem rgba(27, 165, 227, 0.14);
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.telemetry-panel {
  display: grid;
  gap: 0.95rem;
  margin-top: 1.35rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}

.payload-grid {
  margin-top: 0;
}

.action-error {
  margin: 0;
  color: var(--error);
  font-size: 0.92rem;
  font-weight: 700;
}

.log-list {
  display: grid;
  gap: 0.75rem;
  max-height: 34rem;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.log-entry {
  min-width: 0;
  padding: 0.9rem 0.95rem 0.85rem;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.86);
}

.log-entry[data-kind="connack"],
.log-entry[data-kind="puback"] {
  border-left-color: var(--green-deep);
}

.log-entry[data-kind="socket"],
.log-entry[data-kind="publish"] {
  border-left-color: var(--blue-deep);
}

.log-entry[data-kind="error"] {
  border-left-color: var(--error);
}

.log-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
}

.log-kind {
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.log-entry p,
.empty-state {
  margin: 0.5rem 0 0;
}

.log-entry p {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.empty-state {
  color: var(--muted);
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .log-list {
    max-height: 20rem;
  }
}

@media (max-width: 640px) {
  .page {
    width: min(100vw - 1rem, 100%);
    padding: 1rem 0 2rem;
  }

  .session-card,
  .log-card {
    padding: 1rem;
  }

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

  .panel-head,
  .status-row,
  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-button {
    width: 100%;
  }
}
