:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #191c20;
  --panel-2: #20242a;
  --text: #f0f2f4;
  --muted: #9aa4af;
  --line: #30363f;
  --accent: #58a6ff;
  --danger: #ff6b6b;
  --ok: #7ee787;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

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

.topbar {
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
}

.top-actions,
.button-grid,
.dialog-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(290px, 380px) minmax(0, 1fr);
  min-height: calc(100vh - 70px);
}

.panel {
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.controls-panel {
  overflow: auto;
  padding: 14px;
}

.section-title {
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.session-list,
.thread-list {
  display: grid;
  gap: 8px;
}

.session-item {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  padding: 9px;
  text-align: left;
}

.session-item strong {
  overflow-wrap: anywhere;
}

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

.source-summary {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.source-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--muted);
}

.source-dot.online {
  background: var(--ok);
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px;
  gap: 8px;
  margin-bottom: 10px;
}

.thread-item {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  padding: 10px;
}

.thread-main {
  display: grid;
  gap: 3px;
}

.thread-title {
  color: var(--text);
  font-weight: 650;
  overflow-wrap: anywhere;
}

.thread-preview {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.thread-meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
}

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

.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
}

.badge.proxy {
  color: var(--accent);
}

.badge.local {
  color: var(--ok);
}

.tmux-details {
  margin-top: 14px;
}

.tmux-details summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d1117;
  color: var(--text);
  padding: 9px 10px;
}

textarea {
  min-height: 96px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.action-output {
  min-height: 44px;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d1117;
  padding: 10px;
  white-space: pre-wrap;
}

.terminal-panel {
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.terminal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 6px 10px;
}

#terminal-title {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

#terminal {
  min-height: 0;
  padding: 8px;
}

.login-page {
  display: grid;
  min-height: 100%;
  place-items: center;
}

.login-shell {
  width: min(92vw, 380px);
}

.login-box,
.dialog-form {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
}

.login-box h1,
.dialog-form h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.login-box label,
.dialog-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
}

dialog {
  width: min(92vw, 380px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.6);
}

@media (max-width: 860px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 65vh;
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
