:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-hover: #5a9dff;
  --error: #f4717a;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(61, 139, 253, 0.15), transparent);
}

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 20px 32px;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.125rem;
  color: #fff;
  flex-shrink: 0;
}

.header-text h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

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

.channel-tabs {
  display: flex;
  gap: 6px;
  padding: 16px 0 0;
  margin: 0 -4px;
  border-bottom: 1px solid var(--border);
}

.channel-tab {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.channel-tab:hover {
  color: var(--text);
  background: rgba(61, 139, 253, 0.08);
}

.channel-tab[aria-selected="true"] {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
  border-bottom-color: var(--surface);
  margin-bottom: -1px;
  position: relative;
  z-index: 1;
}

.channel-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.log-panels {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.log-panel[hidden] {
  display: none !important;
}

.chat-body {
  flex: 1;
  padding-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.conversation {
  flex: 1;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-heading {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: auto;
  max-height: min(45vh, 360px);
}

.log-empty {
  margin: 0;
  padding: 20px 14px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.table-wrap.has-messages [data-log-empty] {
  display: none;
}

.message-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.message-table th,
.message-table td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.message-table thead th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
  position: sticky;
  top: 0;
  z-index: 1;
}

.message-table tbody tr:last-child td {
  border-bottom: none;
}

.message-table .col-role {
  width: 7.5rem;
  white-space: nowrap;
  color: var(--text-muted);
  font-weight: 500;
}

.message-table .col-content {
  word-break: break-word;
  white-space: pre-wrap;
}

.message-table .role-user {
  color: var(--accent);
}

.message-table .role-assistant {
  color: #9dd6a4;
}

.message-table .role-error {
  color: var(--error);
}

.api-error {
  margin: 0;
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.phone-wrap {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.phone-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 139, 253, 0.2);
}

.phone-prefix {
  padding: 12px 0 12px 14px;
  color: var(--text-muted);
  font-weight: 600;
  user-select: none;
}

.phone-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 12px 14px 12px 4px;
  outline: none;
}

.phone-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.message-input {
  width: 100%;
  resize: vertical;
  min-height: 120px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.message-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 139, 253, 0.2);
}

.message-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.message-meta {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
}

.hint {
  margin: 8px 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.hint code {
  font-size: 0.8125rem;
  padding: 2px 6px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.error {
  margin: 8px 0 0;
  font-size: 0.8125rem;
  color: var(--error);
}

.btn-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-send:hover {
  background: var(--accent-hover);
}

.btn-send:active {
  transform: scale(0.98);
}

.btn-send:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}

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

.btn-send:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.actions .btn-send {
  width: auto;
  flex: 1;
  min-width: 0;
}

.actions .btn-clear-history {
  flex: 1 1 100%;
  white-space: normal;
  background: #dc3545;
  border: 1px solid #b52a37;
}

.actions .btn-clear-history:hover {
  background: #c82333;
}

.actions .btn-clear-history:disabled:hover {
  background: #dc3545;
}

.actions .btn-agent-visibility {
  flex: 1 1 100%;
  white-space: normal;
  text-align: center;
  text-decoration: none;
  color: inherit;
}

.btn-receive {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  font-weight: 500;
  white-space: nowrap;
}

.btn-receive:hover {
  background: #324055;
}

.btn-receive:disabled:hover {
  background: var(--surface-hover);
}

@media (max-width: 560px) {
  .actions {
    flex-direction: column;
  }

  .actions .btn-send {
    width: 100%;
  }
}
