:root {
  --bg: #0c0f14;
  --surface: #141922;
  --surface-2: #1b222e;
  --border: #273142;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4c8dff;
  --accent-hover: #3b7be8;
  --ok: #2ea043;
  --warn: #d29922;
  --danger: #f85149;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--mono);
}

.small {
  font-size: 12px;
}

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

.error-text {
  color: var(--danger);
  margin: 4px 0 0;
  font-size: 13px;
}

code {
  font-family: var(--mono);
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 14px;
  min-height: 0;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
}

.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}

.badge {
  font-size: 11px;
  font-family: var(--mono);
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  margin-left: auto;
}

.sidebar-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.conv-item:hover {
  background: var(--surface-2);
}

.conv-item.active {
  background: var(--surface-2);
  border-color: var(--accent);
}

.conv-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.conv-del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 15px;
}

.conv-del:hover {
  color: var(--danger);
}

.sidebar-bottom {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.sync-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.main-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.tab {
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}

.tab.active {
  background: var(--surface-2);
  color: var(--text);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

select, input[type="text"], input[type="password"], textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
}

select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.checkbox-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-size: 12px;
  cursor: pointer;
}

.auth-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.status-pill.ok {
  border-color: rgba(46, 160, 67, 0.5);
  color: #56d364;
}

.status-pill.warn {
  border-color: rgba(210, 153, 34, 0.5);
  color: #e3b341;
}

.banner {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.banner.warn {
  background: rgba(210, 153, 34, 0.14);
  color: #f0c674;
}

.banner.info {
  background: rgba(76, 141, 255, 0.14);
  color: #b4d0ff;
}

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover:not(:disabled) {
  border-color: #48566e;
}

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

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn.danger {
  background: rgba(248, 81, 73, 0.16);
  border-color: var(--danger);
  color: #ff7b72;
}

.btn.small {
  padding: 4px 10px;
  font-size: 12px;
}

.btn.full {
  width: 100%;
}

.btn.icon {
  padding: 2px 8px;
  font-size: 18px;
  line-height: 1;
}

.view {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.view.active {
  display: flex;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty-state {
  margin: auto;
  max-width: 460px;
  text-align: center;
}

.msg {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.msg.user {
  background: #172030;
  border-color: #2b3d59;
}

.msg-role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.msg-body {
  white-space: pre-wrap;
  line-height: 1.55;
  word-break: break-word;
}

.msg-steps {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.step-pill {
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}

.msg-meta {
  margin-top: 8px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
}

.composer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 54px;
  max-height: 220px;
  line-height: 1.45;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.terminal-toolbar {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.terminal-container {
  flex: 1;
  min-height: 0;
  background: #000;
  padding: 8px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
}

.card.wide {
  max-width: 620px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.modal-header h2, .card h2 {
  margin: 0;
  font-size: 18px;
}

.step-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.step-label {
  font-size: 13px;
  font-weight: 500;
}

.url-row {
  display: flex;
  gap: 8px;
}

.url-preview {
  display: block;
  overflow-x: auto;
  white-space: nowrap;
  padding: 6px 8px;
}

.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    max-height: 180px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
