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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #23273a;
  --border: #2e3247;
  --text: #e8eaf6;
  --text-muted: #7b82a8;
  --accent: #5c6bc0;
  --green: #43a047;
  --yellow: #fdd835;
  --red: #e53935;
  --orange: #fb8c00;
}

body { background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; min-height: 100vh; }

/* ── Header ─────────────────────────────────────────────── */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.logo { font-size: 1.2rem; font-weight: 700; }
nav { display: flex; gap: 8px; }
nav button {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  padding: 6px 16px; border-radius: 6px; cursor: pointer; font-size: 0.9rem;
  display: flex; align-items: center; gap: 6px;
  transition: all 0.15s;
}
nav button.active, nav button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.test-mode-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-muted);
  padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
  transition: all 0.15s; white-space: nowrap;
}
.test-mode-btn:hover { border-color: #f9a825; color: #ffe082; }
.test-mode-btn.active { background: #33290d; border-color: #f9a825; color: #ffe082; font-weight: 600; }

.test-mode-banner {
  background: #33290d; border-bottom: 1px solid #f9a825; color: #ffe082;
  text-align: center; padding: 8px; font-size: 0.85rem; font-weight: 600; letter-spacing: 0.02em;
}
.badge {
  background: var(--red); color: #fff; border-radius: 9px;
  font-size: 0.75rem; padding: 1px 7px; font-weight: 700;
}

/* ── Main ───────────────────────────────────────────────── */
main { max-width: 1200px; margin: 0 auto; padding: 28px 24px; }
h2 { font-size: 1.3rem; margin-bottom: 20px; color: var(--text); }
.empty { color: var(--text-muted); text-align: center; padding: 60px 0; font-size: 1rem; }

/* ── Cards (Pending) ────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; display: flex; flex-direction: column;
  transition: border-color 0.2s;
}
.card:hover { border-color: var(--accent); }
.card-photo { width: 100%; height: 200px; overflow: hidden; background: var(--surface2); }
.card-photo img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title { font-weight: 700; font-size: 1rem; line-height: 1.3; }
.card-meta { font-size: 0.8rem; color: var(--text-muted); display: flex; gap: 10px; }
.card-price { font-size: 1.1rem; cursor: pointer; }
.card-price input { font-size: 1rem; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--accent); background: var(--surface2); color: var(--text); width: 120px; }
.card-desc { font-size: 0.82rem; color: var(--text-muted); line-height: 1.5; flex: 1; }
.card-channels { display: flex; gap: 6px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ── Buttons ────────────────────────────────────────────── */
.btn-approve, .btn-reject, .btn-delete, .btn-sm {
  flex: 1; padding: 10px; border: none; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: 0.9rem; transition: opacity 0.15s;
}
.btn-approve { background: var(--green); color: #fff; }
.btn-reject  { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.btn-delete  { background: transparent; color: #ef5350; border: 1px solid #b71c1c; flex: none; padding: 10px 14px; }
.btn-delete:hover { background: #3e1111; }
.btn-sm      { flex: none; padding: 5px 12px; font-size: 0.8rem; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Pills ──────────────────────────────────────────────── */
.channel-pill, .status-pill {
  font-size: 0.72rem; padding: 2px 8px; border-radius: 4px;
  background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border);
}
.channel-pill.posted, .status-pill.live    { background: #1b5e20; color: #a5d6a7; border-color: #2e7d32; }
.channel-pill.pending, .status-pill.pending_approval { background: #33290d; color: #ffe082; border-color: #f9a825; }
.channel-pill.failed,  .status-pill.rejected { background: #3e1111; color: #ef9a9a; border-color: #b71c1c; }
.channel-pill.skipped  { background: var(--surface2); color: var(--text-muted); }

/* ── Table ──────────────────────────────────────────────── */
.filter-bar { margin-bottom: 16px; }
.filter-bar select { padding: 7px 12px; border-radius: 6px; background: var(--surface2); border: 1px solid var(--border); color: var(--text); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
th { color: var(--text-muted); font-weight: 600; background: var(--surface); }
tr:hover td { background: var(--surface2); }
img.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }

/* ── Import ─────────────────────────────────────────────── */
.import-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; max-width: 860px; }
@media (max-width: 640px) { .import-grid { grid-template-columns: 1fr; } }
.import-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.import-box h3 { font-size: 1rem; font-weight: 700; }
.import-box p { color: var(--text-muted); font-size: 0.87rem; line-height: 1.5; }
.import-box .note { font-size: 0.78rem; color: var(--text-muted); }
.import-box code { background: var(--surface2); padding: 1px 5px; border-radius: 3px; font-size: 0.8rem; }
.file-label {
  display: flex; align-items: center; gap: 10px;
  border: 2px dashed var(--border); border-radius: 8px; padding: 16px;
  cursor: pointer; color: var(--text-muted); transition: border-color 0.2s; font-size: 0.87rem;
}
.file-label:hover { border-color: var(--accent); }
.file-label input { display: none; }
.import-result { font-weight: 600; color: var(--green); font-size: 0.9rem; }
.btn-approve { max-width: 180px; }

/* ── Conversations ──────────────────────────────────────── */
.convo-layout { display: flex; gap: 16px; height: calc(100vh - 160px); }
.session-list { width: 280px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--border); padding-right: 12px; }
.session-item { display: flex; gap: 10px; padding: 10px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; margin-bottom: 4px; }
.session-item:hover { background: var(--surface2); }
.session-item.active { background: var(--surface2); border-color: var(--accent); }
.session-thumb { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.session-meta { flex: 1; overflow: hidden; }
.session-preview { font-size: 0.82rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-date { font-size: 0.75rem; color: var(--text-muted); margin-top: 3px; }
.message-thread { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.msg { display: flex; flex-direction: column; max-width: 80%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot  { align-self: flex-start; align-items: flex-start; }
.msg-bubble { padding: 10px 14px; border-radius: 12px; font-size: 0.87rem; line-height: 1.5; white-space: pre-wrap; }
.msg.user .msg-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg.bot  .msg-bubble { background: var(--surface2); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.msg-time { font-size: 0.72rem; color: var(--text-muted); margin-top: 3px; padding: 0 4px; }

/* ── Listing Detail Drawer ──────────────────────────────── */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 200;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 520px; max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 201; display: flex; flex-direction: column;
  box-shadow: -8px 0 40px rgba(0,0,0,0.5);
  transform: translateX(0); transition: transform 0.25s ease;
}
[x-cloak] .drawer { transform: translateX(100%); }
.drawer-inner { display: flex; flex-direction: column; height: 100%; }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.drawer-header h3 { font-size: 1rem; font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 12px; }
.drawer-close { background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.drawer-close:hover { background: var(--surface2); }
.drawer-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.drawer-photo { flex-shrink: 0; height: 260px; background: var(--surface2); overflow: hidden; }
.drawer-photo img { width: 100%; height: 100%; object-fit: contain; }
.drawer-fields { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.drawer-fields label { display: flex; flex-direction: column; gap: 5px; font-size: 0.8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.drawer-fields input, .drawer-fields select, .drawer-fields textarea {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); padding: 9px 12px; font-size: 0.9rem; font-family: inherit;
  transition: border-color 0.15s;
}
.drawer-fields input:focus, .drawer-fields select:focus, .drawer-fields textarea:focus {
  outline: none; border-color: var(--accent);
}
.drawer-fields textarea { resize: vertical; min-height: 100px; }
.drawer-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.drawer-channels { display: flex; flex-direction: column; gap: 8px; }
.channel-checks { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.channel-check {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface2); cursor: pointer; font-size: 0.82rem;
  text-transform: capitalize; color: var(--text-muted); transition: all 0.15s;
  user-select: none; opacity: 0.55;
}
.channel-check input { display: none; }
.channel-check.checked { border-color: var(--accent); color: var(--text); background: #1e2340; opacity: 1; }
.channel-check:hover { border-color: var(--accent); opacity: 0.85; }
.ch-status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--border);
}
.ch-status-dot.posted  { background: #43a047; }
.ch-status-dot.pending { background: #f9a825; }
.ch-status-dot.failed  { background: #e53935; }
.ch-status-dot.skipped { background: var(--border); }
.field-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.drawer-actions {
  display: flex; gap: 8px; padding: 16px 20px;
  border-top: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap;
}
.drawer-actions .btn-approve { flex: 1; max-width: none; }
.drawer-actions .btn-reject  { flex: none; padding: 10px 16px; }
.drawer-actions .btn-delete  { flex: none; }

/* ── Login screen ──────────────────────────────────────── */
[x-cloak] { display: none !important; }
.login-screen {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px 28px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
}
.login-card h2 { text-align: center; margin: 0 0 4px; font-size: 1.4rem; }
.login-logo { text-align: center; font-size: 2.4rem; }
.login-card label { display: flex; flex-direction: column; gap: 6px;
  font-size: 0.78rem; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; }
.login-card input { background: var(--surface2); border: 1px solid var(--border);
  border-radius: 7px; color: var(--text); padding: 11px 13px; font-size: 1rem; }
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button { padding: 12px; font-size: 0.95rem; }
.login-error { color: #ef5350; font-size: 0.85rem; text-align: center; }

/* ── User chip + logout ─────────────────────────────────── */
.user-chip { display: flex; align-items: center; gap: 8px; margin-left: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 18px; padding: 4px 6px 4px 12px; font-size: 0.85rem; }
.user-name { color: var(--text); }
.btn-logout { background: transparent; color: var(--text-muted); border: none;
  cursor: pointer; padding: 4px 8px; border-radius: 50%; font-size: 0.95rem; }
.btn-logout:hover { background: var(--surface); color: var(--text); }

/* ── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 12px 20px; border-radius: 8px;
  font-size: 0.9rem; z-index: 999; box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* ── Mobile (≤ 720px) ───────────────────────────────────────
   Pending list and selected-item drawer stack vertically — no
   horizontal scrolling, no side-by-side layout. The drawer
   becomes an inline section under the list instead of an
   overlay. */
@media (max-width: 720px) {
  body, html { overflow-x: hidden; }
  main { padding: 16px 12px; }

  header { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  nav { flex-wrap: wrap; }
  nav button { padding: 7px 11px; font-size: 0.85rem; }
  .test-mode-btn { font-size: 0.78rem; padding: 6px 10px; }

  /* Single-column card grid */
  .grid { grid-template-columns: 1fr; gap: 14px; }
  .card-photo { height: 220px; }
  .card-actions { flex-wrap: wrap; }
  .card-actions button { flex: 1 1 calc(50% - 4px); min-width: 0; }

  /* Table → block-style on phones */
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  table tr {
    border: 1px solid var(--border); border-radius: 10px;
    margin-bottom: 12px; padding: 10px; background: var(--surface);
  }
  table td { border: none; padding: 6px 0; }
  img.thumb { width: 60px; height: 60px; }

  /* Conversations: stack list + thread */
  .convo-layout { flex-direction: column; height: auto; }
  .session-list { width: 100%; max-height: 220px; border-right: none; border-bottom: 1px solid var(--border); padding-right: 0; padding-bottom: 8px; }

  /* DRAWER → fullscreen takeover on mobile (cleaner than inline)
     Hide the grid behind it so accidental taps can't land on cards. */
  .drawer-overlay { display: none !important; }
  body.drawer-open main { display: none; }
  .drawer {
    position: fixed; inset: 0; width: 100%; height: 100%;
    max-width: 100%; max-height: 100%;
    border: none; border-radius: 0; margin-top: 0;
    box-shadow: none;
  }
  /* Sticky header so close (✕) is always reachable */
  .drawer-header { position: sticky; top: 0; background: var(--surface); z-index: 5; }
  .drawer-actions { position: sticky; bottom: 0; background: var(--surface); z-index: 5; }
  .drawer-photo { height: 220px; }
  .drawer-fields { padding: 14px; gap: 12px; }
  .drawer-row { grid-template-columns: 1fr; }     /* price + condition stack */
  .drawer-actions { flex-direction: column; }
  .drawer-actions button { width: 100%; max-width: none; }
  .drawer-header { padding: 14px 16px; }
  .drawer-header h3 { font-size: 0.95rem; }

  /* Channel chips never push horizontal scroll */
  .channel-checks { gap: 6px; }
  .channel-check { font-size: 0.78rem; padding: 5px 10px; }

  /* Toast bottom-centre on phones */
  .toast { left: 12px; right: 12px; bottom: 16px; text-align: center; }

  /* CSV import single column */
  .import-grid { grid-template-columns: 1fr; }
}
