:root {
  --bg: #0d1117;
  --panel: #151b23;
  --panel-alt: #1c2430;
  --border: #2a3441;
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --ponchi: #2dd4a7;
  --deskomigo: #4ea1ff;
  --localsave: #f5a623;
  --accent: #2dd4a7;
  --accent-ink: #062017;
  --danger: #ef5350;
  --warn: #f5a623;
  --topbar-h: 58px;
  --tabbar-h: 60px;
}
* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 12px); }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Inter, sans-serif;
  margin: 0;
}
a { color: var(--accent); }

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 20px;
  height: var(--topbar-h);
  padding: 0 20px;
  padding-top: env(safe-area-inset-top);
  background: rgba(13, 17, 23, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text); flex-shrink: 0;
}
.logo-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--ponchi), var(--deskomigo));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; color: #04141c;
}
.logo-name { font-size: 16px; font-weight: 700; letter-spacing: 0.02em; }

/* Desktop nav: icon pills */
.nav { display: flex; align-items: center; gap: 4px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 7px;
  color: var(--text-dim); text-decoration: none;
  font-size: 13.5px; font-weight: 600;
  padding: 7px 12px; border-radius: 8px;
  transition: color 0.12s, background 0.12s;
}
.nav a svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav a:hover { color: var(--text); background: var(--panel-alt); }
.nav a.active { color: var(--text); background: var(--panel-alt); }
.nav a.active svg { color: var(--accent); }

.badge {
  background: var(--accent); color: var(--accent-ink); border-radius: 999px;
  font-size: 11px; padding: 1px 7px; font-weight: 700; line-height: 1.5;
}

/* Settings dropdown (native <details>) */
.menu { position: relative; margin-left: auto; }
.menu summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px;
  color: var(--text-dim); transition: color 0.12s, background 0.12s;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover, .menu[open] summary { color: var(--text); background: var(--panel-alt); }
.menu summary svg { width: 19px; height: 19px; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 200px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.menu-panel a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 13.5px; font-weight: 500;
}
.menu-panel a svg { width: 16px; height: 16px; color: var(--text-dim); }
.menu-panel a:hover { background: var(--panel-alt); }
.menu-panel hr { border: none; border-top: 1px solid var(--border); margin: 6px 4px; }
/* click-away backdrop */
.menu[open]::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
}

/* ============================================================
   Bottom tab bar (mobile app navigation)
   ============================================================ */
.tabbar {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  color: var(--text-dim); text-decoration: none;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em;
  position: relative; padding-top: 4px;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.active { color: var(--accent); }
.tab-badge {
  position: absolute; top: 2px; left: calc(50% + 6px);
  background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; font-size: 10px; font-weight: 700;
  padding: 1px 6px; line-height: 1.4;
}

/* ============================================================
   Layout
   ============================================================ */
.container { padding: 24px 28px 40px; max-width: 1100px; margin: 0 auto; }

.page-head { margin-bottom: 20px; }
.page-head h2 { margin: 0 0 4px; font-size: 21px; }
.page-head p { margin: 0; color: var(--text-dim); font-size: 13.5px; line-height: 1.5; max-width: 640px; }

.section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--text-dim);
  margin: 26px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* ============================================================
   Cards & chips
   ============================================================ */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; margin-bottom: 14px;
}
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.brand-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); }
.dot.ponchi { background: var(--ponchi); }
.dot.deskomigo { background: var(--deskomigo); }
.dot.localsave { background: var(--localsave); }
.dot.onsms { background: #ff7a59; }
.dot.initor { background: #a78bfa; }
.dot.huntcustomer { background: #ee5d9a; }
.dot.luuky { background: #22d3ee; }

.status-pill {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; text-transform: uppercase;
  letter-spacing: 0.04em; font-weight: 700; white-space: nowrap;
}
.status-draft { background: #333; color: #ccc; }
.status-queued, .status-publishing { background: #1e3a5f; color: #7fb3f5; }
.status-scheduled { background: #1e3a5f; color: #7fb3f5; }
.status-published { background: #1b3d2f; color: var(--ponchi); }
.status-needs_manual_action { background: #4a3410; color: var(--localsave); }
.status-failed { background: #4a1e1e; color: var(--danger); }

.copy-text { color: var(--text); line-height: 1.5; font-size: 14px; white-space: pre-wrap; }
.meta { color: var(--text-dim); font-size: 12px; margin-top: 8px; }
.platform-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.tag { background: var(--panel-alt); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; font-size: 11px; color: var(--text-dim); }
a.tag { text-decoration: none; }
a.tag:hover { color: var(--text); border-color: var(--text-dim); }

/* ============================================================
   Home dashboard
   ============================================================ */
.attention-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  border-left: 3px solid var(--accent);
  padding: 14px 16px; margin-bottom: 12px;
  color: inherit; text-decoration: none;
  transition: background 0.12s;
}
.attention-card:hover { background: var(--panel-alt); }
.attention-card.warn { border-left-color: var(--warn); }
.attention-card .icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-alt); color: var(--accent);
}
.attention-card.warn .icon { color: var(--warn); }
.attention-card .icon svg { width: 20px; height: 20px; }
.attention-card .body { flex: 1; min-width: 0; }
.attention-card .title { font-size: 14px; font-weight: 600; }
.attention-card .sub { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.attention-card .go { color: var(--text-dim); flex-shrink: 0; }
.attention-card .go svg { width: 18px; height: 18px; }

.quick-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin-bottom: 4px;
}
.quick-card {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; text-decoration: none; color: var(--text);
  transition: background 0.12s, border-color 0.12s;
}
.quick-card:hover { background: var(--panel-alt); border-color: var(--text-dim); }
.quick-card svg { width: 22px; height: 22px; color: var(--accent); }
.quick-card .title { font-size: 14px; font-weight: 700; }
.quick-card .sub { font-size: 12px; color: var(--text-dim); line-height: 1.45; }

.empty-state {
  text-align: center; padding: 44px 20px; color: var(--text-dim);
  background: var(--panel); border: 1px dashed var(--border); border-radius: 12px;
  font-size: 14px; line-height: 1.6;
}

/* ============================================================
   Forms
   ============================================================ */
.label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-dim);
  margin: 0 0 6px; letter-spacing: 0.02em;
}
.input, .select, textarea.input {
  width: 100%; padding: 11px 12px;
  background: var(--panel-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 14px;
}
.input:focus, .select:focus { outline: none; border-color: var(--accent); }
textarea.input { resize: vertical; line-height: 1.5; }
.field { margin-bottom: 16px; }
.check-row {
  display: flex; align-items: center; gap: 9px;
  font-size: 13.5px; color: var(--text); cursor: pointer;
  padding: 6px 0;
}
.check-row input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  flex: 1; padding: 12px; border-radius: 8px; border: none; font-weight: 600;
  font-size: 14px; cursor: pointer; transition: opacity 0.15s;
  font-family: inherit;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-copy { background: var(--accent); color: var(--accent-ink); }
.btn-skip { background: var(--panel-alt); color: var(--text-dim); border: 1px solid var(--border); }
.btn-done { background: #1b3d2f; color: var(--ponchi); border: 1px solid var(--ponchi); }

/* ============================================================
   Manual queue (swipe UI)
   ============================================================ */
.queue-stack { max-width: 520px; margin: 10px auto; text-align: center; }
.queue-empty { color: var(--text-dim); padding: 60px 20px; }
.queue-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px; text-align: left; min-height: 260px; display: flex; flex-direction: column;
}
.queue-card .target { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.queue-card .context { color: var(--text-dim); font-size: 12px; margin-bottom: 14px; }
.queue-card .body { flex: 1; font-size: 15px; line-height: 1.6; white-space: pre-wrap; }
.queue-actions { display: flex; gap: 10px; margin-top: 20px; }
.progress { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }

.toast {
  position: fixed; bottom: calc(24px + var(--tabbar-h)); left: 50%; transform: translateX(-50%);
  background: var(--accent); color: var(--accent-ink); padding: 10px 18px; border-radius: 8px;
  font-size: 13px; font-weight: 600; opacity: 0; transition: opacity 0.2s; pointer-events: none;
  z-index: 60; white-space: nowrap;
}
.toast.show { opacity: 1; }
@media (min-width: 769px) { .toast { bottom: 24px; } }

/* Editable queue card */
.copy-editor {
  flex: 1;
  width: 100%;
  min-height: 200px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px;
  margin: 4px -10px 0;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.15s, background 0.15s;
}
.copy-editor:hover { border-color: var(--border); }
.copy-editor:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel-alt);
}
.editor-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
}
.editor-meta .hint { text-align: right; opacity: 0.7; }

/* ============================================================
   Group blast: collapsible per-brand sections + selectable rows
   ============================================================ */
.brand-section {
  border: 1px solid var(--border); border-radius: 10px;
  margin: 10px 0; overflow: hidden;
}
.brand-section summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--panel-alt);
  transition: background 0.12s;
}
.brand-section summary::-webkit-details-marker { display: none; }
.brand-section summary::before {
  content: "▸"; color: var(--text-dim); font-size: 12px;
  transition: transform 0.15s; flex-shrink: 0;
}
.brand-section[open] summary::before { transform: rotate(90deg); }
.brand-section summary:hover { background: var(--border); }
.brand-section .group-row { margin: 0 6px; }
.brand-section > .group-row:last-child { margin-bottom: 6px; }

.group-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 8px; cursor: pointer;
  font-size: 13px; transition: background 0.12s;
}
.group-row:hover { background: var(--panel-alt); }
.group-row input[type="checkbox"] { accent-color: var(--accent); }
.group-name { flex: 1; }
.policy {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 7px; border-radius: 999px; font-weight: 700; white-space: nowrap;
}
.policy-none       { background: #4a1e1e; color: var(--danger); }
.policy-thread_only{ background: #4a3410; color: var(--localsave); }
.policy-soft       { background: #1e3a5f; color: #7fb3f5; }
.policy-open       { background: #1b3d2f; color: var(--ponchi); }

/* ============================================================
   Mobile / PWA responsive layer
   ============================================================ */
@media (max-width: 768px) {
  /* Top bar slims down to logo + settings; nav moves to the bottom tab bar */
  .topbar { padding: 0 14px; padding-top: env(safe-area-inset-top); gap: 12px; }
  .topbar .nav { display: none; }
  .tabbar { display: flex; }

  .container {
    padding: 18px 16px;
    /* keep content clear of the fixed tab bar */
    padding-bottom: calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
    max-width: 100%;
  }

  .page-head h2 { font-size: 19px; }
  .card { padding: 14px; }
  .quick-grid { grid-template-columns: 1fr; }
  .attention-card { padding: 13px 14px; }

  /* Stack action buttons full-width and tappable */
  .queue-actions { flex-direction: column; gap: 10px; }
  .queue-actions .btn { width: 100%; padding: 14px; font-size: 16px; }

  /* Bigger tap targets */
  .group-row { padding: 12px 10px; }
  .account-cb, .group-cb { width: 20px; height: 20px; }
  .check-row { padding: 9px 0; }
  .check-row input[type="checkbox"] { width: 20px; height: 20px; }

  /* Inputs sized so iOS doesn't zoom on focus (needs >=16px) */
  textarea, select, input[type="text"], .copy-editor, .input, .select {
    font-size: 16px !important;
  }

  .queue-stack { margin: 6px auto; max-width: 100%; }
  .queue-card { padding: 18px; }
  .brand-chip { font-size: 13px; }
  .status-pill { font-size: 10px; }
}

@media (max-width: 900px) {
  .btn { min-height: 44px; }
}

/* ============================================================
   Login page
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
}
.login-logo { font-size: 24px; margin: 0 0 4px; letter-spacing: 0.02em; }
.login-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 24px; }
.login-input {
  width: 100%;
  padding: 13px 14px;
  margin-bottom: 12px;
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
}
.login-input:focus { outline: none; border-color: var(--accent); }
.login-btn { width: 100%; padding: 14px; font-size: 16px; margin-top: 6px; }
.login-error {
  background: #4a1e1e; color: var(--danger);
  padding: 10px 12px; border-radius: 8px;
  font-size: 13px; margin-bottom: 16px;
}

/* --- Instagram Reels readout (dashboard home) --- */
.reels-head {
  display: flex; gap: 18px; flex-wrap: wrap;
  font-size: 13px; color: var(--text-dim); margin-bottom: 10px;
}
.reels-head strong { color: var(--accent); font-size: 16px; }
.reels-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.reels-table th {
  text-align: left; font-weight: 500; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-dim); padding: 6px 8px 6px 0;
  border-bottom: 1px solid var(--border);
}
.reels-table td { padding: 7px 8px 7px 0; border-bottom: 1px solid var(--border); }
.reels-table tr:last-child td { border-bottom: none; }
.reels-table td:first-child { white-space: nowrap; }
.reels-table th:not(:first-child), .reels-table td:not(:first-child) { text-align: right; }
