/* ── Theme tokens ─────────────────────────────────────────── */

:root {
  --bg: #f0f2f5;
  --bg-soft: #e8ecf1;
  --panel: #ffffff;
  --ink: #1a1f2b;
  --muted: #6b7a8d;
  --line: #d5dce6;
  --brand: #4a7dff;
  --brand-strong: #3560d4;
  --brand-muted: rgba(74, 125, 255, 0.12);
  --danger: #e25555;
  --danger-muted: rgba(226, 85, 85, 0.1);
  --ok: #22a06b;
  --ok-muted: rgba(34, 160, 107, 0.1);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
  --transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

html[data-theme="dark"] {
  --bg: #0c0f14;
  --bg-soft: #12161e;
  --panel: #1a1f2b;
  --ink: #e4eaf4;
  --muted: #8899ad;
  --line: #252d3a;
  --brand: #5b8eff;
  --brand-strong: #7aa4ff;
  --brand-muted: rgba(91, 142, 255, 0.14);
  --danger: #f06b6b;
  --danger-muted: rgba(240, 107, 107, 0.12);
  --ok: #4cc98e;
  --ok-muted: rgba(76, 201, 142, 0.12);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3), 0 1px 6px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.2);
}

/* ── Reset & base ────────────────────────────────────────── */

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

html,
body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}

body.modal-open {
  overflow: hidden;
}

/* ── Shell layout ────────────────────────────────────────── */

.app-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px 40px;
  padding-bottom: max(40px, env(safe-area-inset-bottom, 0px));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 8px 0;
}

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

.nav-toggle {
  min-width: 40px;
  font-size: 1.15rem;
  line-height: 1;
}

h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ── Side nav ────────────────────────────────────────────── */

.tabs {
  position: fixed;
  top: 0;
  right: 0;
  width: min(300px, 88vw);
  height: 100vh;
  z-index: 1300;
  display: grid;
  grid-auto-rows: min-content;
  gap: 6px;
  padding: 16px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.18);
  overflow-y: auto;
}

.tabs.open {
  animation: navSlideIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.nav-head {
  margin-bottom: 6px;
}

.nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 1250;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.nav-overlay.open {
  animation: fadeIn 0.2s ease-out;
}

@keyframes navSlideIn {
  from { transform: translateX(100%); opacity: 0.7; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.hidden {
  display: none !important;
}

.tab-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink);
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  transition: all var(--transition);
}

.tab-btn:hover {
  background: var(--brand-muted);
  border-color: var(--brand);
}

.tab-btn.active {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
  box-shadow: 0 2px 8px rgba(74, 125, 255, 0.3);
}

/* ── Status bar ──────────────────────────────────────────── */

.status-row {
  margin-bottom: 12px;
}

.status {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all var(--transition);
}

.status:empty {
  display: none;
}

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

.status.busy {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-muted);
}

.status.error {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-muted);
}

.status.ok {
  color: var(--ok);
  border-color: var(--ok);
  background: var(--ok-muted);
}

/* ── Main content ────────────────────────────────────────── */

main {
  display: grid;
  gap: 14px;
}

.tab {
  display: none;
  gap: 14px;
}

.tab.active {
  display: grid;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 18px;
  box-shadow: var(--shadow);
}

.stack {
  display: grid;
  gap: 10px;
}

/* ── Category picker ─────────────────────────────────────── */

.category-picker {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.category-col-main {
  grid-row: 1 / 3;
}

.category-picker.compact {
  max-height: 420px;
  overflow-y: auto;
}

.category-column {
  min-width: 0;
  display: grid;
  gap: 6px;
  align-content: start;
}

.category-list {
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: var(--panel);
  max-height: 260px;
  overflow-y: auto;
  display: grid;
  gap: 2px;
  padding: 4px;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.category-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
  line-height: 1.3;
  font-weight: 500;
  font-size: 0.9rem;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.category-item:hover {
  background: var(--brand-muted);
  border-color: transparent;
}

.category-item.active {
  background: var(--brand);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}

.category-empty {
  color: var(--muted);
  font-size: 0.84rem;
  padding: 8px 6px;
}

/* ── Dynamic form fields ─────────────────────────────────── */

.dynamic-field {
  display: grid;
  gap: 6px;
}

.dynamic-field-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.dynamic-field-label.required::after {
  content: " *";
  color: var(--danger);
}

.dynamic-options {
  display: grid;
  gap: 6px;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
}

/* ── Flex helpers ────────────────────────────────────────── */

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

.split {
  justify-content: space-between;
}

/* ── Accounts ────────────────────────────────────────────── */

.accounts-head {
  margin-bottom: 12px;
}

.account-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--bg-soft);
  transition: border-color var(--transition);
}

.account-row:hover {
  border-color: var(--brand);
}

.account-row .row {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.account-row > :first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.account-actions {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.account-actions .btn {
  min-width: 110px;
  text-align: center;
}

.account-label {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 2px;
}

.add-account-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--brand);
  color: #fff;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(74, 125, 255, 0.3);
  transition: transform var(--transition), box-shadow var(--transition);
}

.add-account-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(74, 125, 255, 0.35);
}

.add-account-btn:active {
  transform: translateY(0);
}

/* ── Form elements ───────────────────────────────────────── */

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 0.92rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-muted);
}

textarea {
  resize: vertical;
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  padding: 9px 16px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  color: #fff;
  background: var(--brand);
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
}

a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(74, 125, 255, 0.25);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.btn.ghost {
  color: var(--ink);
  background: var(--panel);
  border-color: var(--line);
}

.btn.ghost:hover {
  border-color: var(--brand);
  background: var(--brand-muted);
  box-shadow: none;
}

.btn.compact {
  padding: 7px 10px;
  font-weight: 600;
  font-size: 0.85rem;
}

.btn.danger {
  color: #fff;
  border-color: transparent;
  background: var(--danger);
}

.btn.danger:hover {
  box-shadow: 0 4px 12px rgba(226, 85, 85, 0.25);
}

/* ── Conversations ───────────────────────────────────────── */

.conv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--bg-soft);
  cursor: pointer;
  overflow: hidden;
  min-width: 0;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.conv-row:hover {
  border-color: var(--brand);
  background: var(--brand-muted);
}

.conv-row.active {
  border-color: var(--brand);
  background: var(--brand-muted);
  box-shadow: inset 0 0 0 1px rgba(74, 125, 255, 0.15);
}

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-strong) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  font-size: 1.05rem;
}

.conv-main {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
  overflow: hidden;
}

.conv-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

.conv-name {
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.conv-title {
  font-weight: 700;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.conv-subject {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.conv-preview {
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.unread-badge {
  background: var(--brand);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

/* ── Ads ─────────────────────────────────────────────────── */

.ads-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.ad-row {
  display: flex;
}

.ad-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  overflow: hidden;
  display: grid;
  grid-template-rows: 150px 1fr auto;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
}

.ad-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.ad-card-media {
  position: relative;
  background: var(--brand-muted);
  border-bottom: 1px solid var(--line);
}

.ad-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ad-card-ph {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  color: var(--muted);
}

.ad-card-body {
  min-width: 0;
  display: grid;
  gap: 6px;
  padding: 12px 14px 10px;
}

.ad-title {
  font-weight: 700;
  line-height: 1.3;
  font-size: 0.95rem;
  min-height: 2.4em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.ad-meta {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

.ad-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.chip.ok {
  color: var(--ok);
  border-color: var(--ok);
  background: var(--ok-muted);
}

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

.ad-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ad-card-actions {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
}

/* ── Meta text ───────────────────────────────────────────── */

.meta {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
}

/* ── Messages ────────────────────────────────────────────── */

.messages {
  margin-bottom: 8px;
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.message {
  display: flex;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.message.me {
  justify-content: flex-end;
}

.message.other {
  justify-content: flex-start;
}

.bubble {
  position: relative;
  padding: 10px 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  max-width: 82%;
  min-width: 0;
  font-size: 0.92rem;
  overflow: hidden;
}

.message.me .bubble {
  background: var(--brand);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 2px 6px rgba(74, 125, 255, 0.2);
}

.message.other .bubble {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 18px 18px 18px 4px;
  box-shadow: var(--shadow-sm);
}

.bubble-text {
  overflow-wrap: anywhere;
}

.bubble-meta {
  font-size: 0.7rem;
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

.message.me .bubble-meta {
  color: rgba(255, 255, 255, 0.75);
}

.message.other .bubble-meta {
  color: var(--muted);
}

.bubble-read {
  letter-spacing: -0.08em;
  font-weight: 700;
}

.bubble-read.unread {
  opacity: 0.7;
}

.bubble-read.read {
  opacity: 1;
  color: #8fd3ff;
}

.message.other .bubble-read {
  color: var(--muted);
}

.message-attachments {
  margin-top: 6px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.message-attachment {
  width: 180px;
  height: 180px;
  border-radius: var(--radius-xs);
  border: none;
  background: var(--bg-soft);
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 0;
  transition: opacity var(--transition);
}

.message-attachment:active {
  opacity: 0.7;
}

.message-attachment img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
}

.message.me .message-attachment {
  border: none;
}

/* Single attachment: wider, more photo-like */
.message-attachments:has(.message-attachment:only-child) .message-attachment {
  width: 220px;
  height: 200px;
}

/* Loading state for proxy images */
.message-attachment img:not([src]),
.message-attachment img[src=""] {
  visibility: hidden;
}

.message-attachment:has(img:not([src])),
.message-attachment:has(img[src=""]) {
  background: var(--bg-soft);
  position: relative;
}

.message-attachment:has(img:not([src]))::after,
.message-attachment:has(img[src=""])::after {
  content: "";
  position: absolute;
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.message-actions {
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.msg-action-btn {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all var(--transition);
}

.msg-action-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-muted);
}

.msg-action-btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.message-translation {
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
}

.message-translation-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.message-translation-text {
  font-size: 0.88rem;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.offer-card {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--brand) 10%, var(--bg-soft));
  padding: 10px;
  display: grid;
  gap: 8px;
  max-width: 100%;
  overflow: hidden;
}

.offer-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border: 1px solid var(--brand);
  color: var(--brand);
  background: var(--brand-muted);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.75rem;
  font-weight: 700;
}

.offer-lines {
  display: grid;
  gap: 4px;
  font-size: 0.9rem;
}

.offer-line {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  overflow: hidden;
  word-break: break-word;
}

.offer-line strong {
  color: var(--ink);
}

.offer-total {
  border-top: 1px solid var(--line);
  padding-top: 6px;
}

.offer-cancel-btn {
  margin-top: 2px;
}

/* ── Reply composer ──────────────────────────────────────── */

.reply-composer {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  overflow: hidden;
}

.reply-composer textarea {
  border: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: transparent;
  min-height: 48px;
  resize: vertical;
}

.reply-composer textarea:focus {
  box-shadow: none;
}

.reply-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all var(--transition);
}

.icon-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-muted);
}

.icon-btn.send {
  color: #fff;
  border-color: transparent;
  background: var(--brand);
  box-shadow: 0 2px 8px rgba(74, 125, 255, 0.25);
}

.icon-btn.send:hover {
  color: #fff;
  box-shadow: 0 4px 12px rgba(74, 125, 255, 0.35);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Settings ────────────────────────────────────────────── */

.settings-option {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  padding: 12px 14px;
  background: var(--bg-soft);
  cursor: pointer;
  transition: border-color var(--transition);
}

.settings-option:hover {
  border-color: var(--brand);
}

.switch {
  position: relative;
  width: 44px;
  height: 26px;
  flex: 0 0 auto;
}

.switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(120, 133, 153, 0.4);
  transition: background var(--transition);
}

.switch-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition);
}

.switch input[type="checkbox"]:checked + .switch-slider {
  background: var(--brand);
}

.switch input[type="checkbox"]:checked + .switch-slider::after {
  transform: translateX(18px);
}

.setting-copy {
  line-height: 1.35;
  font-size: 0.92rem;
}

/* ── Misc ────────────────────────────────────────────────── */

.result {
  margin-top: 8px;
  font-size: 0.9rem;
}

.result a {
  color: var(--brand);
}

.empty {
  margin: 0;
  color: var(--muted);
}

.file-tools {
  justify-content: space-between;
}

.files-list {
  display: grid;
  gap: 6px;
}

.file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  background: var(--bg-soft);
}

.reply-file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  background: var(--bg-soft);
}

.reply-file-main {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.reply-file-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 76%;
}

/* ── Modals ──────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(520px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 10px;
}

#ad-edit-modal .modal-card {
  width: min(760px, 100%);
}

.ad-edit-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.ad-edit-header h3 {
  margin: 0;
}

.modal-card h3 {
  margin: 0 0 6px;
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-help {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.modal-help code {
  font-family: "JetBrains Mono", "Consolas", monospace;
  font-size: 0.82rem;
  background: var(--bg-soft);
  padding: 2px 5px;
  border-radius: 4px;
}

.modal-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.account-add-proxy-tools {
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.account-add-proxy-status {
  min-height: 18px;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: right;
  flex: 1 1 auto;
}

.account-add-proxy-status.busy {
  color: var(--brand);
}

.account-add-proxy-status.ok {
  color: var(--ok);
}

.account-add-proxy-status.error {
  color: var(--danger);
}

/* ── Admin ───────────────────────────────────────────────── */

.admin-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.admin-metric {
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  background: var(--bg-soft);
}

.admin-metric strong {
  display: block;
  font-size: 1.1rem;
}

.admin-user {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--bg-soft);
  display: grid;
  gap: 6px;
}

.admin-user-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.admin-user-id {
  font-weight: 700;
}

.admin-user-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.admin-user-accounts {
  display: grid;
  gap: 5px;
}

.admin-user-account {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 7px 10px;
  font-size: 0.84rem;
  color: var(--muted);
}

.admin-user-account strong {
  color: var(--ink);
}

.admin-pager {
  margin-top: 10px;
  align-items: center;
}

#admin-broadcast-attachment {
  padding: 8px 10px;
}

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 680px) {
  html, body {
    font-size: 15px;
  }

  .app-shell {
    padding: 6px 8px 24px;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    gap: 6px;
    padding: 4px 0;
    margin-bottom: 8px;
  }

  .topbar h1 {
    font-size: 1.05rem;
  }

  .tabs {
    width: 100%;
    max-width: 100%;
  }

  .split {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    gap: 2px;
    flex-shrink: 0;
  }

  .header-actions .btn.ghost.compact {
    padding: 4px 6px;
    font-size: 0.75rem;
  }

  .status-row {
    margin-bottom: 8px;
  }

  .status {
    padding: 6px 10px;
    font-size: 0.82rem;
  }

  /* ── Card compact ── */
  .card {
    padding: 12px;
    border-radius: var(--radius-sm);
  }

  /* ── Messages list header - compact on mobile ── */
  #messages-list-card > .row.split {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  #messages-list-card > .row.split h2 {
    margin: 0;
    font-size: 1rem;
  }

  #messages-list-card > .row.split > .row {
    display: flex;
    width: 100%;
  }

  #messages-list-card > .row.split > .row select {
    flex: 1;
    min-width: 0;
  }

  #messages-list-card > .row.split > .row .btn {
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* ── Conversations list ── */
  .conv-row {
    flex-direction: row;
    align-items: center;
    padding: 10px 12px;
    gap: 10px;
    overflow: hidden;
  }

  .conv-avatar {
    width: 42px;
    height: 42px;
    font-size: 0.95rem;
  }

  .conv-name {
    font-size: 0.9rem;
  }

  .conv-subject {
    font-size: 0.8rem;
  }

  .conv-title {
    font-size: 0.9rem;
  }

  .conv-preview {
    font-size: 0.8rem;
  }

  .unread-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
  }

  /* ── Messages thread - fullscreen-style on mobile ── */
  #messages-thread-card {
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    background: transparent;
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 0;
    /* Break out of app-shell padding to use full width */
    margin-left: -8px;
    margin-right: -8px;
    width: calc(100% + 16px);
    max-width: calc(100% + 16px);
    overflow: hidden;
  }

  #messages-thread-card > .row.split {
    flex-direction: row;
    align-items: center;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: 8px 10px;
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 6px;
  }

  #messages-thread-card > .row.split h2 {
    margin: 0;
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
  }

  #messages-thread-card > .row.split .btn {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .messages {
    max-height: calc(100dvh - 220px);
    min-height: 200px;
    border-radius: 0;
    border: none;
    padding: 8px 6px;
    gap: 6px;
    margin-bottom: 0;
    width: 100%;
    max-width: 100%;
  }

  .message {
    max-width: 100%;
  }

  .bubble {
    max-width: 78%;
    padding: 7px 10px;
    font-size: 0.87rem;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .bubble-meta {
    gap: 4px;
    font-size: 0.67rem;
  }

  .message-actions {
    gap: 3px;
    margin-top: 3px;
  }

  .msg-action-btn {
    width: 24px;
    height: 24px;
  }

  .msg-action-btn svg {
    width: 11px;
    height: 11px;
  }

  /* ── Photo attachments on mobile ── */
  .message-attachment {
    width: 130px;
    height: 130px;
    border-radius: 8px;
  }

  .message-attachments:has(.message-attachment:only-child) .message-attachment {
    width: 170px;
    height: 150px;
  }

  .message-attachments {
    gap: 3px;
  }

  /* ── Reply composer fixed at bottom ── */
  #reply-form {
    background: var(--panel);
    border-top: 1px solid var(--line);
    border-radius: 0;
    padding: 6px;
    gap: 4px;
    max-width: 100%;
    overflow: hidden;
  }

  .reply-composer {
    grid-template-columns: 1fr auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-xs);
    max-width: 100%;
  }

  .reply-composer textarea {
    border-radius: var(--radius-xs) 0 0 var(--radius-xs);
    min-height: 36px;
    padding: 7px 10px;
    font-size: 0.87rem;
  }

  .reply-toolbar {
    padding: 3px;
    gap: 2px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
  }

  .icon-btn.send {
    width: 34px;
    height: 34px;
  }

  .file-tools {
    font-size: 0.76rem;
    flex-wrap: wrap;
    gap: 4px;
    padding: 0 2px;
  }

  .file-tools .meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
  }

  .file-tools .btn {
    flex-shrink: 0;
    font-size: 0.76rem;
    padding: 4px 8px;
  }

  /* ── Accounts ── */
  .account-row {
    align-items: stretch;
    flex-direction: column;
  }

  .account-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* ── Ads ── */
  .ad-row {
    flex-direction: column;
  }

  .ad-card {
    grid-template-rows: 160px 1fr auto;
  }

  .ad-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  /* ── Category picker ── */
  .category-picker {
    grid-template-columns: 1fr;
  }

  .category-col-main {
    grid-row: auto;
  }

  .category-list {
    max-height: 200px;
  }

  /* ── Modals ── */
  .modal-backdrop {
    padding: 8px;
  }

  .modal-card {
    border-radius: var(--radius-sm);
    padding: 14px;
    max-height: 95dvh;
  }

  .modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .modal-actions .btn:last-child {
    grid-column: span 2;
  }

  /* ── Buttons ── */
  .btn {
    padding: 10px 14px;
    font-size: 0.88rem;
  }

  .btn.compact {
    padding: 8px 10px;
  }

  /* ── Select / inputs ── */
  select,
  input,
  textarea {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 10px 12px;
  }
}

/* ── Extra small screens (under 400px) ── */
@media (max-width: 400px) {
  .app-shell {
    padding: 4px 4px 20px;
  }

  .card {
    padding: 8px;
  }

  .topbar h1 {
    font-size: 0.95rem;
  }

  .header-actions .btn.ghost.compact {
    padding: 3px 5px;
    font-size: 0.7rem;
  }

  #messages-thread-card {
    margin-left: -4px;
    margin-right: -4px;
    width: calc(100% + 8px);
    max-width: calc(100% + 8px);
  }

  .bubble {
    max-width: 82%;
    padding: 6px 8px;
    font-size: 0.84rem;
  }

  .bubble-meta {
    font-size: 0.64rem;
    gap: 2px;
  }

  .msg-action-btn {
    width: 22px;
    height: 22px;
  }

  .msg-action-btn svg {
    width: 10px;
    height: 10px;
  }

  .messages {
    padding: 5px 4px;
    gap: 5px;
  }

  #messages-thread-card > .row.split {
    padding: 6px 8px;
  }

  #messages-thread-card > .row.split h2 {
    font-size: 0.8rem;
  }

  .message-attachment {
    width: 110px;
    height: 110px;
  }

  .message-attachments:has(.message-attachment:only-child) .message-attachment {
    width: 150px;
    height: 130px;
  }

  .offer-card {
    padding: 6px;
    gap: 4px;
    font-size: 0.82rem;
  }

  .offer-lines {
    font-size: 0.82rem;
  }

  .offer-badge {
    font-size: 0.68rem;
    padding: 2px 6px;
  }

  .conv-avatar {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
  }

  .conv-row {
    padding: 8px 10px;
    gap: 8px;
  }

  .reply-composer textarea {
    min-height: 32px;
    padding: 6px 8px;
    font-size: 0.84rem;
  }

  .icon-btn {
    width: 28px;
    height: 28px;
  }

  .icon-btn.send {
    width: 30px;
    height: 30px;
  }

  #reply-form {
    padding: 4px;
  }

  .file-tools {
    font-size: 0.72rem;
    padding: 0;
  }
}
