:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-strong: #eef4f8;
  --text: #17212b;
  --muted: #637083;
  --line: #d8e0e8;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --warning: #9a5b00;
  --warning-bg: #fff4db;
  --danger: #a43a32;
  --ok: #137a41;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 24px;
}

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

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 18px;
}

.topbar p,
.text-meta,
dt,
.notice {
  color: var(--muted);
}

.status-badge {
  flex: 0 0 auto;
  min-width: 84px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  text-align: center;
  color: var(--muted);
}

.status-badge.connected {
  border-color: rgba(19, 122, 65, 0.26);
  background: rgba(19, 122, 65, 0.08);
  color: var(--ok);
}

.notice {
  display: grid;
  gap: 6px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid #f0c36a;
  border-radius: 8px;
  background: var(--warning-bg);
  color: var(--warning);
}

.hidden {
  display: none;
}

.work-area {
  display: grid;
  grid-template-columns: minmax(300px, 0.95fr) minmax(320px, 1.05fr);
  gap: 16px;
  align-items: start;
}

.control-panel,
.state-panel,
.diagnostic-panel,
.log-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.control-panel {
  padding: 18px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid #b9c5d1;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

input:focus {
  outline: 3px solid rgba(15, 118, 110, 0.16);
  border-color: var(--primary);
}

.text-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  font-size: 13px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 18px;
}

button {
  min-height: 46px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--primary-dark);
}

button:disabled {
  cursor: not-allowed;
  border-color: #c7d0d9;
  background: #dce3ea;
  color: #778596;
}

#clearLogButton {
  min-height: 34px;
  padding: 0 12px;
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--text);
}

.secondary-button {
  min-height: 36px;
  padding: 0 12px;
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--text);
}

.diagnostic-panel {
  margin-bottom: 16px;
  padding: 16px;
}

.diagnostic-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.diagnostic-list div {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  align-items: start;
  min-width: 0;
}

.state-grid {
  display: grid;
  gap: 16px;
}

.state-panel {
  padding: 16px;
}

dl {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
}

dl div {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

dt {
  font-size: 13px;
}

dd {
  margin: 0;
  min-width: 0;
  word-break: break-word;
  font-weight: 650;
}

.log-panel {
  margin-top: 16px;
  padding: 0;
  overflow: hidden;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

#logList {
  display: grid;
  gap: 0;
  max-height: 280px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

#logList li {
  padding: 10px 16px;
  border-bottom: 1px solid #edf1f5;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

#logList li.ok {
  color: var(--ok);
}

#logList li.error {
  color: var(--danger);
}

@media (max-width: 760px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .work-area {
    display: grid;
  }

  h1 {
    font-size: 23px;
  }

  .work-area {
    grid-template-columns: 1fr;
  }

  .diagnostic-header,
  .diagnostic-list {
    grid-template-columns: 1fr;
  }

  .diagnostic-header {
    display: grid;
  }

  .secondary-button {
    width: 100%;
  }

  .status-badge {
    justify-self: start;
  }
}
