:root {
  --bg: #f5f5f5;
  --panel: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --sub: #888888;
  --accent: #d32f2f;
  --accent-light: rgba(211, 47, 47, 0.08);
  --blue: #1976d2;
  --green: #2e7d32;
  --yellow: #f9a825;
  --red: #d32f2f;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  color: var(--accent);
  font-size: 15px;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.nav a {
  color: var(--sub);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}

.nav a.active {
  color: var(--text);
  background: var(--bg);
}

.nav a:hover {
  color: var(--text);
  text-decoration: none;
}

.agent-pill {
  margin-left: auto;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--sub);
}

.version {
  font-size: 11px;
  color: var(--sub);
}

/* ── Layout ── */
.inbox-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100vh - 49px);
  margin: -16px;
}

/* ── Sidebar (Queue) ── */
.queue {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.queue .panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 16px 0;
}

.queue .panel-title-row h2 {
  font-size: 15px;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
}

.search-row {
  padding: 10px 16px 0;
  display: flex;
  gap: 6px;
}

.search-row input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.search-row input:focus {
  border-color: var(--blue);
}

.search-row button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.search-row button:hover {
  opacity: 0.9;
}

.filters {
  padding: 8px 16px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 12px;
  color: var(--sub);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
}

.chip:hover {
  color: var(--text);
  border-color: #ccc;
  text-decoration: none;
}

.chip.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

.conversation-list {
  margin-top: 8px;
  overflow-y: auto;
  flex: 1;
}

.conversation-card {
  display: block;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}

.conversation-card:hover {
  background: var(--bg);
  text-decoration: none;
}

.conversation-card.active {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
}

.conv-line-1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.conv-line-1 strong {
  font-size: 14px;
  font-weight: 600;
}

.conv-line-2 {
  font-size: 12px;
  color: var(--sub);
  margin-top: 2px;
}

.conv-line-3 {
  font-size: 13px;
  color: var(--sub);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.status-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--sub);
}

/* ── Timeline (Chat) ── */
.timeline {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.timeline-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.tags {
  font-size: 12px;
  color: var(--sub);
  margin-top: 2px;
}

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

.header-actions form {
  display: flex;
  gap: 6px;
  align-items: center;
}

.header-actions select,
.header-actions input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  background: var(--panel);
  color: var(--text);
}

.header-actions button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}

.header-actions button:hover {
  background: var(--bg);
}

/* ── Messages ── */
.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.message {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.message:last-child {
  border-bottom: none;
}

.message.note {
  background: #fffde7;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid #fff9c4;
  margin: 4px 0;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  margin-bottom: 4px;
}

.message-meta span:first-child {
  font-weight: 600;
  color: var(--accent);
}

.message.out .message-meta span:first-child {
  color: var(--blue);
}

.message.note .message-meta span:first-child {
  color: var(--yellow);
}

.message-meta span:last-child {
  color: var(--sub);
  font-weight: 400;
  white-space: nowrap;
}

.message-body {
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.quote {
  background: rgba(25, 118, 210, 0.08);
  border-left: 3px solid var(--blue);
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--sub);
}

/* ── Composer ── */
.composer {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  align-items: flex-end;
}

.composer-left {
  flex-shrink: 0;
}

.composer-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.composer-right {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.composer select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
  background: var(--panel);
  color: var(--text);
  width: 100px;
}

.composer textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  min-height: 100px;
  max-height: 200px;
  font-family: inherit;
  outline: none;
  line-height: 1.5;
}

.composer textarea:focus {
  border-color: var(--blue);
}

.attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  font-size: 18px;
  transition: background 0.15s;
}

.attach-btn:hover {
  background: var(--border);
}

.file-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
}

.file-preview span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
}

.file-remove {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.composer button[type="submit"] {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  min-height: 40px;
}

.composer button[type="submit"]:hover {
  opacity: 0.9;
}

/* File display in messages */
.msg-file-preview {
  margin: 8px 0;
}

.msg-img {
  max-width: 400px;
  max-height: 300px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.msg-video {
  max-width: 400px;
  max-height: 300px;
  border-radius: 8px;
}

.msg-file-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 6px 0;
  font-size: 13px;
}

.msg-file-attachment a {
  color: var(--blue);
  text-decoration: none;
}

.msg-file-attachment a:hover {
  text-decoration: underline;
}

/* ── Context panel (Wallet) ── */
.context {
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: none;
}

.inbox-layout.has-context {
  grid-template-columns: 280px 1fr 300px;
}

.inbox-layout.has-context .context {
  display: block;
}

.context h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.wallet-card {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.wallet-card.ok {
  background: #e8f5e9;
  border-color: #c8e6c9;
}

.wallet-card.warn {
  background: #fff8e1;
  border-color: #ffecb3;
}

.wallet-card.neutral {
  background: var(--bg);
}

.wallet-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}

.wallet-row span {
  color: var(--sub);
}

.action-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
}

/* ── Empty states ── */
.empty-box,
.empty-center,
.warning {
  padding: 16px;
  text-align: center;
  color: var(--sub);
  font-size: 13px;
}

.empty-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.empty-center h3 {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 4px;
}

/* ── Generic button ── */
button {
  cursor: pointer;
  border: none;
  font-family: inherit;
}

/* ── Code ── */
code {
  font-family: ui-monospace, Menlo, Monaco, "Courier New", monospace;
  font-size: 12px;
  word-break: break-all;
}

/* ── Tables ── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

.table th {
  font-weight: 600;
  color: var(--sub);
  font-size: 12px;
  text-transform: uppercase;
}

/* ── Admin pages ── */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

main {
  padding: 16px;
}

.quick-wrap,
.relay-wrap,
.admin-wrap {
  max-width: 1200px;
  margin: 0 auto;
}

.quick-card {
  max-width: 580px;
  margin: 0 auto;
}

.relay-list,
.audit-list {
  display: grid;
  gap: 8px;
}

.relay-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.relay-head {
  display: flex;
  justify-content: space-between;
}

.relay-text {
  margin: 8px 0;
}

.relay-actions {
  display: flex;
  gap: 16px;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.audit-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
}

.audit-meta {
  font-size: 11px;
  color: var(--sub);
  margin-bottom: 4px;
}

.payload-block {
  margin: 4px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, Menlo, Monaco, "Courier New", monospace;
  font-size: 12px;
}

/* ── Add Agent form ── */
.add-agent-form {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.add-agent-form .form-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.form-field label {
  display: block;
  font-size: 11px;
  color: var(--sub);
  margin-bottom: 4px;
}

.form-field input,
.form-field select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}

.btn-add-agent {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  padding: 8px 14px;
  font-weight: 500;
}

.btn-remove {
  background: #ffebee;
  color: var(--red);
  border: 1px solid #ffcdd2;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
}

.btn-remove:hover {
  background: #ffcdd2;
}

/* ── Utility ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Responsive ── */
@media (max-width: 920px) {
  .inbox-layout,
  .inbox-layout.has-context {
    grid-template-columns: 1fr;
    height: auto;
  }

  .queue {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }

  .context {
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .topbar {
    flex-wrap: wrap;
    gap: 8px;
  }

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

  .header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .add-agent-form .form-row {
    grid-template-columns: 1fr;
  }
}


/* ── Quick replies dropdown ── */
.qr-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
  z-index: 100;
}

.qr-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.qr-item:last-child {
  border-bottom: none;
}

.qr-item:hover {
  background: var(--accent-light);
}

.qr-item strong {
  color: var(--accent);
}

.composer-center {
  position: relative;
}

/* ── Delivery failed banner ── */
.delivery-failed {
  background: #ffebee;
  color: var(--red);
  padding: 8px 16px;
  font-size: 13px;
  border-bottom: 1px solid #ffcdd2;
  text-align: center;
}

/* ── Load older messages ── */
.load-older {
  text-align: center;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.load-older a {
  color: var(--blue);
  font-size: 13px;
}


/* ── Formatting Toolbar ── */
.format-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.fmt-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary, #666);
  line-height: 1;
  min-width: 28px;
  text-align: center;
}

.fmt-btn:hover {
  background: var(--accent-light, #e3f2fd);
  border-color: var(--border);
  color: var(--accent, #1976d2);
}

.fmt-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}

.emoji-toggle {
  font-size: 18px !important;
  padding: 2px 6px !important;
}

/* ── Emoji Picker ── */
.emoji-picker {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
  z-index: 200;
  max-height: 250px;
  overflow-y: auto;
  padding: 8px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 2px;
}

.emoji-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  font-size: 22px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.1s;
}

.emoji-item:hover {
  background: var(--accent-light, #e3f2fd);
  transform: scale(1.15);
}

/* ── Message text formatting ── */
.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-code {
  background: rgba(0,0,0,0.06);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.9em;
  color: #d63384;
}

.msg-code-block {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 10px 14px;
  border-radius: 6px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.85em;
  overflow-x: auto;
  margin: 6px 0;
  white-space: pre-wrap;
}

.message-body strong {
  font-weight: 700;
}

.message-body em {
  font-style: italic;
}

.message-body del {
  text-decoration: line-through;
  opacity: 0.7;
}

/* ── Voice message styling ── */
.msg-audio {
  width: 100%;
  max-width: 300px;
}


/* ── Activity Log ── */
.activity-log {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.activity-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.activity-item:hover {
  background: var(--accent-light);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-icon {
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: #f0f0f0;
}

.activity-item.message_added .activity-icon {
  background: #e3f2fd;
}

.activity-item.telegram_inbound .activity-icon {
  background: #e8f5e9;
}

.activity-item.assignment_changed .activity-icon,
.activity-item.status_changed .activity-icon {
  background: #fff3e0;
}

.activity-item.agent_created .activity-icon,
.activity-item.agent_deleted .activity-icon {
  background: #fce4ec;
}

.activity-content {
  flex: 1;
  min-width: 0;
}

.activity-header {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.activity-actor {
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
}

.activity-action {
  color: var(--sub);
  font-size: 13px;
}

.activity-action strong {
  color: var(--text);
  font-weight: 600;
}

.activity-details {
  margin-top: 2px;
  font-size: 12px;
  color: var(--sub);
}

.activity-details a {
  color: var(--blue);
  font-weight: 500;
}

.activity-time {
  display: block;
  font-size: 11px;
  color: #aaa;
  margin-top: 3px;
}


/* ── Wallet Context Panel ── */
.wallet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.wallet-status-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.5px;
}

.wallet-status-badge.linked {
  background: #e8f5e9;
  color: #2e7d32;
}

.wallet-network {
  font-size: 12px;
  color: var(--sub);
  font-weight: 500;
}

.wallet-address {
  margin-bottom: 12px;
  padding: 6px 10px;
  background: #f5f5f5;
  border-radius: 6px;
  font-size: 13px;
}

.wallet-address a {
  color: var(--blue);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.external-icon {
  font-size: 11px;
  opacity: 0.6;
}

/* ── HL Summary ── */
.hl-summary {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-bottom: 12px;
}

.hl-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 0;
  font-size: 12px;
  color: var(--sub);
}

.hl-row.main {
  padding: 6px 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.hl-row.main span {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.hl-value {
  font-size: 18px !important;
  font-weight: 700 !important;
  color: var(--text) !important;
}

/* ── HL Positions ── */
.hl-positions {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.hl-positions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
}

.hl-pos-count {
  background: var(--accent-light);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
}

.hl-position {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.hl-pos-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.hl-coin {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}

.hl-side {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}

.hl-side.long {
  background: #e8f5e9;
  color: #2e7d32;
}

.hl-side.short {
  background: #ffebee;
  color: #c62828;
}

.hl-leverage {
  font-size: 10px;
  font-weight: 600;
  color: var(--sub);
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 3px;
}

.hl-pos-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hl-pos-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--sub);
  padding: 1px 0;
}

.hl-pos-row .profit {
  color: #2e7d32;
  font-weight: 600;
}

.hl-pos-row .loss {
  color: #c62828;
  font-weight: 600;
}

.hl-pos-row small {
  font-size: 10px;
  opacity: 0.8;
  margin-left: 3px;
}

.hl-no-positions,
.hl-unavailable {
  text-align: center;
  padding: 16px;
  color: var(--sub);
  font-size: 13px;
}

/* ── HL Section Label ── */
.hl-section-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 6px;
}

.hl-section-label span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--sub);
  letter-spacing: 0.5px;
}

.hl-view-all {
  font-size: 11px;
  color: var(--blue);
  font-weight: 500;
}


/* ── HL Breakdown (L1 / Hip3 / Spot) ── */
.hl-breakdown {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0 10px;
  padding: 6px 8px;
  background: #f8f8f8;
  border-radius: 6px;
}

.hl-breakdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--sub);
}

.hl-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.hl-badge.l1 {
  background: #e3f2fd;
  color: #1565c0;
}

.hl-badge.hip3 {
  background: #f3e5f5;
  color: #7b1fa2;
}

.hl-badge.spot {
  background: #e8f5e9;
  color: #2e7d32;
}

.hl-margin-type {
  font-size: 9px;
  font-weight: 600;
  padding: 0 4px;
  border-radius: 2px;
  text-transform: uppercase;
}

.hl-margin-type.isolated {
  background: #fff3e0;
  color: #e65100;
}

/* ══════════════════════════════════════════════════════
   MOBILE UX OVERHAUL
   ══════════════════════════════════════════════════════ */

@media (max-width: 920px) {
  /* ── Topbar: compact, no wrap overflow ── */
  .topbar {
    padding: 8px 12px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .brand {
    font-size: 13px;
    min-width: 0;
    flex-shrink: 1;
  }

  .nav {
    gap: 2px;
    margin-left: 4px;
    flex-shrink: 0;
  }

  .nav a {
    padding: 5px 8px;
    font-size: 12px;
    white-space: nowrap;
  }

  .agent-pill {
    font-size: 11px;
    padding: 3px 8px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .version {
    display: none;
  }

  /* ── Main content: tighter padding ── */
  main {
    padding: 8px;
  }

  /* ── Inbox: full width, better queue ── */
  .queue {
    max-height: none;
  }

  .queue .panel-title-row {
    padding: 12px 12px 0;
  }

  .search-row {
    padding: 8px 12px 0;
  }

  .filters {
    padding: 6px 12px 0;
    gap: 4px;
  }

  .chip {
    font-size: 11px;
    padding: 2px 8px;
  }

  .conversation-card {
    padding: 10px 12px;
  }

  /* ── Chat header actions: stack vertically ── */
  .timeline-header {
    padding: 10px 12px;
    flex-direction: column;
    gap: 8px;
  }

  .header-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  .header-actions form {
    flex-wrap: wrap;
    gap: 4px;
  }

  .header-actions select,
  .header-actions input {
    font-size: 12px;
    padding: 5px 6px;
  }

  .header-actions button {
    font-size: 12px;
    padding: 5px 10px;
  }

  /* ── Messages: constrain images/video ── */
  .message-list {
    padding: 10px 12px;
  }

  .msg-img {
    max-width: 100% !important;
    max-height: 250px;
    height: auto;
  }

  .msg-video {
    max-width: 100% !important;
    max-height: 250px;
  }

  .msg-file-preview img,
  .msg-file-preview video {
    max-width: 100% !important;
  }

  .message-body img {
    max-width: 100% !important;
    height: auto;
  }

  /* ── Composer: compact on mobile ── */
  .composer {
    padding: 8px 12px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .composer textarea {
    min-height: 60px;
    font-size: 14px;
  }

  .composer select {
    width: 80px;
    font-size: 12px;
    padding: 6px;
  }

  .file-preview span {
    max-width: 150px;
  }

  /* ── Tables → Cards on mobile ── */
  .table,
  .table thead,
  .table tbody,
  .table th,
  .table td,
  .table tr {
    display: block;
  }

  .table thead {
    display: none;
  }

  .table tr {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--panel);
  }

  .table td {
    border-bottom: none;
    padding: 3px 0;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
  }

  .table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--sub);
    font-size: 11px;
    text-transform: uppercase;
    flex-shrink: 0;
    min-width: 80px;
  }

  /* ── Admin Replies: card layout ── */
  .admin-wrap {
    max-width: 100%;
  }

  .panel {
    padding: 10px;
    border-radius: 6px;
  }

  .panel .search-row {
    padding: 8px 0 0;
    flex-wrap: wrap;
  }

  .panel .search-row input {
    min-width: 0;
    flex: 1;
  }

  .panel .search-row select {
    flex-shrink: 0;
  }

  /* ── Admin Team: card layout for table ── */
  .add-agent-form .form-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .add-agent-form .form-row button {
    grid-column: 1 / -1;
  }

  /* ── Activity Log: tighter ── */
  .activity-item {
    padding: 8px 10px;
    gap: 8px;
  }

  .activity-icon {
    width: 24px;
    height: 24px;
    font-size: 14px;
  }

  .activity-actor {
    font-size: 12px;
  }

  .activity-action {
    font-size: 12px;
  }

  .activity-time {
    font-size: 10px;
  }

  /* ── Wallet context: full width ── */
  .context {
    padding: 12px;
  }

  .hl-position {
    padding: 8px 10px;
  }

  /* ── Split layout: single column ── */
  .split {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* ── Format toolbar: scrollable ── */
  .format-toolbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 6px;
  }

  .fmt-btn {
    min-width: 26px;
    padding: 4px 6px;
    font-size: 12px;
  }

  /* ── Emoji picker: fit screen ── */
  .emoji-picker {
    max-height: 180px;
  }

  .emoji-grid {
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
  }

  .emoji-item {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }
}

/* ── Extra small screens (iPhone SE, narrow) ── */
@media (max-width: 400px) {
  .topbar {
    padding: 6px 8px;
  }

  .brand {
    font-size: 12px;
  }

  .nav a {
    padding: 4px 6px;
    font-size: 11px;
  }

  .agent-pill {
    display: none;
  }

  .conversation-card {
    padding: 8px 10px;
  }

  .conv-line-1 strong {
    font-size: 13px;
  }

  .add-agent-form .form-row {
    grid-template-columns: 1fr;
  }

  .header-actions select,
  .header-actions input,
  .header-actions button {
    font-size: 11px;
  }
}
