:root {
  --bg: #0b0f17;
  --panel: #111827;
  --panel-2: #172033;
  --border: #243047;
  --text: #e5edf8;
  --muted: #8b9bb4;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --danger: #f87171;
  --success: #22c55e;
  --radius: 12px;
  --font: Inter, system-ui, -apple-system, 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(--font);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
}

button,
input {
  font-family: inherit;
  font-size: inherit;
}

.app-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-width: 0;
  overflow: hidden;
}

.brand-bar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-bar h1 {
  margin: 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-sub {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.my-site-box {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.55);
}

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}

.contacts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
}

.contacts-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.contact-card {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 10px 11px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.contact-card:hover {
  background: var(--panel-2);
}

.contact-card.active {
  background: rgba(2, 132, 199, 0.18);
  border-color: rgba(56, 189, 248, 0.55);
}

.contact-info {
  min-width: 0;
  flex: 1;
}

.contact-name {
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-url {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  flex-shrink: 0;
}

/* Workspace */
.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  background: var(--bg);
}

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

.chat-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-topbar-left strong {
  font-size: 14px;
}

.chat-topbar-url {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
}

.split-stage {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
  background: var(--border);
  gap: 1px;
}

.pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.pane iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--bg);
}

.welcome-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.welcome-card {
  max-width: 520px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
}

.welcome-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.welcome-card p {
  margin: 0 0 12px;
  color: var(--muted);
}

.welcome-steps {
  margin: 0 0 18px;
  padding-left: 18px;
  color: var(--text);
}

.welcome-steps li {
  margin-bottom: 6px;
}

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

.input {
  width: 100%;
  background: #0d1422;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}

.input:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  transition: background 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}

.btn:hover:not(:disabled) {
  background: #1f2b42;
  border-color: #384a6b;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: #0369a1;
}

.btn-danger {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(127, 29, 29, 0.25);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(153, 27, 27, 0.45);
}

.btn-sm {
  padding: 5px 9px;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
}

.pill-d1 {
  color: #7dd3fc;
  border-color: #0369a1;
  background: rgba(2, 132, 199, 0.16);
}

.pill-r2 {
  color: #86efac;
  border-color: #15803d;
  background: rgba(22, 163, 74, 0.16);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.modal h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

.hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.status-line {
  font-size: 12px;
  margin-top: 8px;
}

.status-line.ok {
  color: var(--success);
}

.status-line.error {
  color: var(--danger);
}

.toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: #0f172a;
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  z-index: 60;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.hidden {
  display: none !important;
}

/* Responsive mobile layout */
@media (max-width: 860px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    max-height: 36vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .workspace {
    height: auto;
    min-height: 64vh;
  }

  .split-stage {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
}
