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

:root {
  --bg: #0e0e0e;
  --surface: #1a1a1a;
  --surface-2: #222;
  --border: #2e2e2e;
  --border-focus: #3a5a48;
  --text: #d0d0d0;
  --text-dim: #555;
  --text-muted: #888;
  --accent: #00c170;
  --accent-hover: #00e080;
  --accent-dim: #007a47;
  --error: #e05c5c;
  --success: #00c170;
  --outgoing-bg: #0d3d28;
  --outgoing-text: #a0e0c0;
  --incoming-bg: #202020;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.app {
  display: flex;
  gap: 52px;
  align-items: center;
  padding: 24px;
}

/* ── Phone Frame ── */

.emulator-col {
  flex-shrink: 0;
}

.phone-frame {
  width: 296px;
  height: 556px;
  background: #111;
  border-radius: 46px;
  border: 1.5px solid #2a2a2a;
  box-shadow:
    0 0 0 1px #141414,
    0 24px 64px rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.phone-top-bar {
  height: 48px;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-shrink: 0;
  padding: 0 20px;
}

.phone-camera {
  width: 9px;
  height: 9px;
  background: #1c1c1c;
  border-radius: 50%;
  border: 1px solid #2e2e2e;
  order: 1;
}

.phone-speaker {
  width: 52px;
  height: 4px;
  background: #222;
  border-radius: 2px;
  order: 2;
}

.phone-screen {
  flex: 1;
  background: #080808;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid #1c1c1c;
  border-bottom: 1px solid #1c1c1c;
}

.phone-bottom-bar {
  height: 36px;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.home-indicator {
  width: 96px;
  height: 4px;
  background: #242424;
  border-radius: 2px;
}

/* ── Conversation ── */

.conversation {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: #2a2a2a transparent;
}

.conversation::-webkit-scrollbar { width: 3px; }
.conversation::-webkit-scrollbar-track { background: transparent; }
.conversation::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 2px; }

.conversation-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 11px;
  text-align: center;
  padding: 20px;
  line-height: 1.6;
}

.message {
  max-width: 82%;
  padding: 7px 11px;
  border-radius: 16px;
  font-size: 11.5px;
  line-height: 1.5;
  word-break: break-word;
}

.message.outgoing {
  align-self: flex-end;
  background: var(--outgoing-bg);
  color: var(--outgoing-text);
  border-bottom-right-radius: 4px;
}

.message.incoming {
  align-self: flex-start;
  background: var(--incoming-bg);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.message-meta {
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 3px;
}

.message.outgoing .message-meta { text-align: right; }

@keyframes incoming-flash {
  0%   { background: #2a4a3a; }
  60%  { background: #2a4a3a; }
  100% { background: var(--incoming-bg); }
}

.message.incoming.flash {
  animation: incoming-flash 0.9s ease-out forwards;
}

/* ── Compose area ── */

.compose-area {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 7px 8px;
  border-top: 1px solid #181818;
  background: #0c0c0c;
  flex-shrink: 0;
}

.message-input {
  flex: 1;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 8px 12px;
  resize: none;
  outline: none;
  max-height: 80px;
  overflow-y: auto;
  line-height: 1.4;
  transition: border-color 0.15s;
}

.message-input:focus { border-color: var(--border-focus); }
.message-input::placeholder { color: #3a3a3a; }

.send-btn {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  line-height: 1;
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { background: var(--accent-dim); }
.send-btn:disabled { background: #2a2a2a; color: #555; cursor: default; }

/* ── Developer Controls ── */

.controls-col {
  width: 270px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.controls-header {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.controls-title {
  font-size: 17px;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.controls-subtitle {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.control-label {
  font-size: 9.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.control-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}

.control-input:focus { border-color: var(--border-focus); }
.control-input::placeholder { color: #383838; }

.status-area {
  min-height: 18px;
  font-size: 11.5px;
  line-height: 1.5;
}

.status-error { color: var(--error); }
.status-success { color: var(--success); }
.status-info { color: var(--text-muted); }

.controls-footer {
  margin-top: 8px;
}

.hint-text {
  font-size: 10px;
  color: #2e2e2e;
}

/* ── Settings gear (controls panel) ── */

.controls-header {
  position: relative;
}

.settings-gear-btn {
  position: absolute;
  top: 0;
  right: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  padding: 2px;
  line-height: 1;
  transition: color 0.15s;
}

.settings-gear-btn:hover { color: var(--text-muted); }

/* ── Modal footer layout: gear left, buttons right ── */

.modal-footer {
  align-items: center;
}

.modal-endpoints-gear {
  background: none;
  border: none;
  color: #2e2e2e;
  font-size: 12px;
  cursor: pointer;
  padding: 2px;
  line-height: 1;
  margin-right: auto;
  transition: color 0.15s;
}

.modal-endpoints-gear:hover { color: var(--text-dim); }

/* ── Config Editor Modal ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: #131313;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  width: 660px;
  max-width: 92vw;
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.9);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  border-bottom: 1px solid #222;
  flex-shrink: 0;
}

.modal-title {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.15s;
}

.modal-close-btn:hover { color: var(--text); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: #2a2a2a transparent;
}

.config-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.config-table th {
  text-align: left;
  font-size: 9.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0 8px 9px;
  border-bottom: 1px solid #222;
  font-weight: normal;
}

.config-table th:last-child {
  width: 36px;
}

.config-table td {
  padding: 5px 8px;
  vertical-align: top;
}

.config-table tr + tr td {
  padding-top: 4px;
}

.config-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 10px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

.config-input:focus { border-color: var(--border-focus); }
.config-input.has-error { border-color: var(--error); }

.field-error {
  display: block;
  color: var(--error);
  font-size: 10px;
  margin-top: 3px;
  padding-left: 2px;
}

.delete-row-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}

.delete-row-btn:hover { border-color: var(--error); color: var(--error); }

.add-row-btn {
  background: none;
  border: 1px dashed #2e2e2e;
  color: var(--text-dim);
  border-radius: 4px;
  padding: 9px 16px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  cursor: pointer;
  width: 100%;
  transition: border-color 0.15s, color 0.15s;
  text-align: left;
}

.add-row-btn:hover { border-color: var(--accent-dim); color: var(--accent); }

.config-empty-row td {
  text-align: center;
  color: var(--text-dim);
  font-size: 11.5px;
  padding: 28px 8px;
  border-bottom: 1px solid #1c1c1c;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid #222;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.btn {
  padding: 8px 20px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

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

.btn-secondary {
  background: none;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-secondary:hover { color: var(--text); border-color: #444; }

/* ── Task 1: Byline ── */

.controls-byline {
  font-size: 9px;
  color: #2e2e2e;
  letter-spacing: 0.04em;
}

/* ── Task 2: Phone screen contact/app name header ── */

.phone-contact-header {
  flex-shrink: 0;
  padding: 5px 10px 4px;
  text-align: center;
  border-bottom: 1px solid #181818;
  background: #0c0c0c;
  display: none;
}

.phone-contact-header.has-contact {
  display: block;
}

.phone-contact-name {
  font-size: 11px;
  font-weight: bold;
  color: var(--text);
  line-height: 1.3;
}

.phone-contact-sub {
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 1px;
}

/* ── Task 3 & 4: Compose-area tool buttons (Download, Reset) ── */

.tool-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  width: 28px;
  height: 28px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
  line-height: 1;
}

.tool-btn:hover { border-color: var(--border-focus); color: var(--text-muted); }

/* ── Task 5: Combo field (number history dropdown) ── */

.combo-field {
  position: relative;
}

.number-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-top: 2px;
  z-index: 50;
  max-height: 180px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #2a2a2a transparent;
}

.number-dropdown-item {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-mono);
  transition: background 0.1s;
}

.number-dropdown-item:hover { background: #2a2a2a; }

/* ── Task 6: Collapsible panel ── */

.panel-area {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.panel-toggle-btn {
  background: none;
  border: none;
  color: #2e2e2e;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 2px;
  line-height: 1;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
  align-self: center;
  -webkit-user-select: none;
  user-select: none;
}

.panel-toggle-btn:hover { color: var(--text-dim); background: #1a1a1a; }

.controls-col.panel-collapsed { display: none; }

/* ── Task 2: Third column in config table (App Name) ── */

.config-table th:nth-child(3) {
  width: 140px;
}

/* ── Router Endpoints Popup ── */

.endpoints-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.endpoints-popup-overlay.open { display: flex; }

.endpoints-popup-box {
  background: #131313;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  width: 400px;
  max-width: 92vw;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
  overflow: hidden;
}

.endpoints-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #222;
  flex-shrink: 0;
}

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

.endpoints-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: #2a2a2a transparent;
}

.endpoint-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.1s;
}

.endpoint-entry:hover { background: #1e1e1e; }
.endpoint-entry.active { background: #152014; }

.endpoint-radio {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid #3a3a3a;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.endpoint-entry.active .endpoint-radio { border-color: var(--accent); }

.endpoint-radio-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  display: none;
}

.endpoint-entry.active .endpoint-radio-dot { display: block; }

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

.endpoint-label {
  font-size: 11.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.endpoint-url {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.endpoint-delete-btn {
  background: none;
  border: none;
  color: #383838;
  font-size: 15px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s;
}

.endpoint-delete-btn:hover { color: var(--error); }

.endpoints-add-area {
  padding: 10px 16px;
  border-top: 1px solid #1e1e1e;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.endpoints-add-row {
  display: flex;
  gap: 6px;
}

.endpoint-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 8px;
  outline: none;
  transition: border-color 0.15s;
}

.endpoint-input:focus { border-color: var(--border-focus); }
.endpoint-input-label { width: 90px; flex-shrink: 0; }
.endpoint-input-url { flex: 1; min-width: 0; }

.endpoint-add-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}

.endpoint-add-btn:hover { border-color: var(--accent-dim); color: var(--accent); }

.endpoint-add-error {
  font-size: 10px;
  color: var(--error);
  min-height: 13px;
}

/* ── Help button (controls panel header) ── */

.help-btn {
  position: absolute;
  top: 0;
  right: 20px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--font-mono);
  font-weight: bold;
  cursor: pointer;
  padding: 2px 3px;
  line-height: 1;
  transition: color 0.15s;
}

.help-btn:hover { color: var(--text-muted); }

/* ── Help Modal ── */

.help-modal-box {
  width: 520px;
}

.help-modal-body {
  gap: 0;
}

.help-topic-item {
  padding: 7px 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.1s, color 0.1s;
}

.help-topic-item:hover {
  background: #1e1e1e;
  color: var(--text);
}

.help-group {
  display: flex;
  flex-direction: column;
  margin-top: 16px;
}

.help-group-header {
  font-size: 9.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: normal;
  padding: 0 8px 6px;
}

.help-back-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  margin-bottom: 18px;
  display: inline-block;
  transition: color 0.15s;
}

.help-back-btn:hover { color: var(--text); }

.help-blurb-text {
  font-size: 12px;
  color: var(--text);
  line-height: 1.7;
}

.help-icon-list {
  list-style: disc;
  padding-left: 18px;
  font-size: 12px;
  color: var(--text);
  line-height: 1.7;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
