:root {
  --bg: #0b0d12;
  --bg-elevated: #141821;
  --bg-hover: #1b2130;
  --border: #2a3142;
  --border-strong: #3d4660;
  --text: #eef1f6;
  --muted: #8b93a7;
  --green: #3dd68c;
  --green-dim: rgba(61, 214, 140, 0.16);
  --red: #f07178;
  --red-dim: rgba(240, 113, 120, 0.16);
  --orange: #e6a23c;
  --orange-dim: rgba(230, 162, 60, 0.16);
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
}

.page {
  width: min(480px, 100%);
  margin: 0 auto;
  padding: calc(20px + var(--safe-top)) 16px calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.offline-banner {
  margin: -4px 0 2px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--red-dim);
  border: 1px solid rgba(240, 113, 120, 0.45);
  color: #ffb4b8;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

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

.header-text h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.badge {
  flex-shrink: 0;
  margin-top: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.badge-running {
  color: #0b1b12;
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-dim);
}

.badge-stopped {
  color: #2a0c0e;
  background: var(--red);
  box-shadow: 0 0 0 4px var(--red-dim);
}

.badge-unknown {
  color: var(--muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.channels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.channel-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-height: 88px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.channel-card:active {
  transform: scale(0.98);
}

.channel-card:disabled {
  opacity: 0.6;
  cursor: wait;
}

.channel-card.active {
  border-color: var(--green);
  background: linear-gradient(180deg, var(--green-dim), var(--bg-elevated));
  box-shadow: 0 0 0 1px var(--green), var(--shadow);
}

.channel-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-strong);
}

.channel-card.active .channel-dot {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.channel-label {
  font-size: 15px;
  font-weight: 650;
  line-height: 1.25;
}

.btn {
  appearance: none;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-danger {
  color: #ffd6d8;
  background: #2a1316;
  border-color: rgba(240, 113, 120, 0.45);
}

.btn-danger:not(:disabled):active {
  background: #3a181c;
}

.btn-secondary {
  color: var(--text);
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.btn-secondary:not(:disabled):active {
  background: var(--bg-hover);
}

.btn-resume {
  color: #0b1b12;
  background: var(--green);
  border-color: var(--green);
}

.meta-line,
.session-line {
  margin: 0;
  font-size: 15px;
}

.session-line.session-ok {
  color: var(--green);
}

.session-line.session-bad {
  color: var(--red);
}

.session-line.session-unknown {
  color: var(--muted);
}

.error-block {
  border-radius: 12px;
  border: 1px solid rgba(230, 162, 60, 0.4);
  background: var(--orange-dim);
  overflow: hidden;
}

.error-toggle {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border: 0;
  background: transparent;
  color: #ffd9a0;
  font: inherit;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}

.error-chevron {
  color: var(--muted);
  font-size: 12px;
}

.error-block.open .error-chevron {
  transform: rotate(180deg);
}

.error-detail {
  margin: 0;
  padding: 0 14px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #f3e6c8;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.messages {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 4px 12px 8px;
}

.messages summary {
  cursor: pointer;
  list-style: none;
  padding: 12px 4px;
  font-weight: 650;
}

.messages summary::-webkit-details-marker {
  display: none;
}

.messages summary::after {
  content: "▾";
  float: right;
  color: var(--muted);
  font-weight: 400;
}

.messages[open] summary::after {
  transform: rotate(180deg);
  display: inline-block;
}

.messages-list {
  list-style: none;
  margin: 0;
  padding: 0 0 8px;
}

.messages-list li {
  padding: 10px 4px;
  border-top: 1px solid var(--border);
}

.messages-text {
  margin: 0 0 4px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.messages-meta {
  color: var(--muted);
  font-size: 12px;
}

.messages-empty {
  color: var(--muted);
  font-size: 14px;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.link-btn {
  appearance: none;
  border: 0;
  background: none;
  color: #9aa3b8;
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 0;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  width: min(448px, calc(100% - 32px));
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 12px;
  background: #1f2433;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  text-align: center;
  font-size: 14px;
  z-index: 20;
}

@media (min-width: 640px) {
  .page {
    padding-top: 40px;
  }
}
