:root {
  --bg: #111111;
  --bg-2: #161616;
  --panel: #1a1a1a;
  --panel-2: #212121;
  --line: #2a2a2a;
  --text: #f2f2f2;
  --muted: #9a9a9a;
  --faint: #6b6b6b;
  --accent: #ffffff;
  --accent-ink: #111111;
  --green: #2bd48a;
  --green-bg: rgba(43, 212, 138, .12);
  --blue: #4c8dff;
  --amber: #f5b544;
  --amber-bg: rgba(245, 181, 68, .12);
  --red: #ff6b6b;
  --red-bg: rgba(255, 107, 107, .12);
  --radius: 14px;
  --sidebar: 240px;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 500; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.green { color: var(--green); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex-shrink: 0; background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 6px; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, #2bd48a, #4c8dff); display: grid; place-items: center; color: #0b0b0b; font-size: 14px; font-weight: 800; }
.org { color: var(--muted); font-size: 13px; padding: 0 10px 16px; border-bottom: 1px solid var(--line); margin-bottom: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; text-decoration: none;
  color: var(--muted); margin-bottom: 2px; font-size: 14.5px;
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: var(--panel-2); color: var(--text); }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav .sep { height: 22px; }
.nav .badge { margin-left: auto; background: var(--amber); color: #111; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 7px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; }

.main { flex: 1; min-width: 0; }
.topbar { display: none; }
.content { padding: 26px 30px 60px; max-width: 1200px; margin: 0 auto; }
.content.full { padding: 0; max-width: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

@media (max-width: 899px) {
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; width: 270px; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.55); }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: #0d0d0d; position: sticky; top: 0; z-index: 10; }
  .content { padding: 18px 16px 50px; }
}

/* ---------- controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); padding: 9px 16px; border-radius: 99px; cursor: pointer; font-size: 14px;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; }
.btn.primary:hover { opacity: .9; }
.btn.green { background: var(--green); color: #07140d; border-color: var(--green); font-weight: 600; }
.btn.danger { color: var(--red); border-color: rgba(255,107,107,.35); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

.input, select.input, textarea.input {
  width: 100%; background: #0e0e0e; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
}
.input:focus { border-color: #4a4a4a; }
textarea.input { resize: vertical; min-height: 90px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; margin-bottom: 6px; font-weight: 500; }
label.field small { display: block; color: var(--faint); margin-top: 5px; font-size: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }

.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { background: none; border: 0; padding: 6px 12px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); }

.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #333; border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); }

/* ---------- tarjetas y tablas ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 14px; }
.stats .card, .lines-grid .card { margin-top: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr)); gap: 14px; }
.stat-title { color: var(--text); font-weight: 500; }
.stat-value { font-size: 34px; font-weight: 500; margin: 8px 0 4px; display: flex; align-items: baseline; gap: 10px; }
.stat-value small { font-size: 14px; color: var(--green); font-weight: 600; }
.stat-range { color: var(--faint); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.chart { width: 100%; height: 150px; margin-top: 12px; display: block; }
.chart text { fill: var(--faint); font-size: 10px; }

.funnel { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-top: 14px; }
.funnel div { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.funnel b { display: block; font-size: 22px; font-weight: 500; margin-top: 6px; }

.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pager { color: var(--faint); margin-top: 14px; font-size: 13px; }

.avatar { width: 26px; height: 26px; border-radius: 50%; background: #333; display: inline-grid; place-items: center; font-size: 12px; font-weight: 600; flex-shrink: 0; color: #ddd; }
.who { display: flex; align-items: center; gap: 10px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 500; background: var(--panel-2); color: var(--muted); }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.blue { background: rgba(76,141,255,.14); color: var(--blue); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; color: var(--faint); }
.search input { padding-left: 34px; }

.empty { text-align: center; padding: 70px 20px; }
.empty .ico { width: 88px; height: 88px; border-radius: 16px; background: var(--panel-2); display: grid; place-items: center; margin: 0 auto 22px; color: var(--muted); }
.empty h2 { font-size: 19px; margin-bottom: 8px; }

/* ---------- páginas ---------- */
.pages-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 16px; }
.page-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.page-card:hover { border-color: #3a3a3a; }
.page-thumb { height: 190px; overflow: hidden; position: relative; background: #000; }
.page-thumb iframe { width: 400%; height: 400%; transform: scale(.25); transform-origin: 0 0; border: 0; pointer-events: none; }
.page-meta { padding: 14px 16px; display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.page-meta b { font-weight: 500; display: block; }

.editor { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; flex-direction: column; }
.editor-top { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.editor-body { flex: 1; display: grid; grid-template-columns: 380px 1fr; min-height: 0; }
.editor-side { border-right: 1px solid var(--line); overflow-y: auto; padding: 16px; }
.editor-preview { background: #0a0a0a; display: flex; justify-content: center; align-items: stretch; padding: 18px; min-height: 0; }
.editor-preview iframe { border: 1px solid var(--line); border-radius: 12px; background: #fff; width: 100%; height: 100%; transition: max-width .2s; }
.editor-preview.mobile iframe { max-width: 390px; }
.section-title { font-weight: 600; margin: 6px 0 12px; display: flex; align-items: center; gap: 8px; }
.side-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type=color] { width: 40px; height: 38px; border: 1px solid var(--line); border-radius: 8px; background: none; padding: 2px; cursor: pointer; }
@media (max-width: 899px) {
  .editor-body { grid-template-columns: 1fr; grid-template-rows: auto 60vh; overflow-y: auto; }
  .editor-side { border-right: 0; overflow: visible; }
}

/* ---------- líneas ---------- */
.lines-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 14px; }
.line-card { display: flex; gap: 14px; align-items: flex-start; }
.line-ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; }
.line-ico.wa { background: rgba(37, 211, 102, .12); color: #25d366; }
.line-ico.tg { background: rgba(42, 171, 238, .14); color: #2aabee; }
.option { display: flex; gap: 14px; align-items: center; padding: 16px; border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px; cursor: pointer; width: 100%; text-align: left; margin-bottom: 12px; }
.option:hover:not(:disabled) { border-color: #444; }
.option:disabled { opacity: .5; cursor: default; }
.option b { display: block; font-weight: 500; font-size: 15px; }
.qr-box { text-align: center; }
.qr-box img { background: #fff; border-radius: 12px; padding: 8px; width: 260px; max-width: 100%; }
.steps { text-align: left; color: var(--muted); line-height: 1.7; padding-left: 20px; }

/* ---------- inbox ---------- */
.inbox { display: grid; grid-template-columns: 320px 1fr 300px; height: calc(100vh - 0px); }
.inbox-list { border-right: 1px solid var(--line); overflow-y: auto; }
.inbox-list .search { max-width: none; margin: 14px; }
.chat-item { display: flex; gap: 10px; padding: 12px 14px; cursor: pointer; border-bottom: 1px solid #1d1d1d; }
.chat-item:hover { background: var(--panel); }
.chat-item.on { background: var(--panel-2); }
.chat-item .meta { min-width: 0; flex: 1; }
.chat-item .meta div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .unread { background: var(--green); color: #07140d; font-weight: 700; font-size: 11px; border-radius: 99px; padding: 1px 7px; align-self: center; }
.chat { display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 12px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px; background: #0d0d0d; }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 12px; background: var(--panel-2); line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: #144d37; }
.msg time { display: block; font-size: 10.5px; color: var(--faint); margin-top: 4px; text-align: right; }
.msg img { max-width: 260px; border-radius: 8px; display: block; cursor: zoom-in; }
.chat-send { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--line); }
.chat-side { border-left: 1px solid var(--line); padding: 18px; overflow-y: auto; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--faint); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 1100px) { .inbox { grid-template-columns: 280px 1fr; } .chat-side { display: none; } }
@media (max-width: 899px) {
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 57px); }
  .inbox.has-chat .inbox-list { display: none; }
  .inbox:not(.has-chat) .chat { display: none; }
}

/* ---------- venta (detalle) ---------- */
.sale-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.receipt { background: #0b0b0b; border: 1px solid var(--line); border-radius: 12px; display: grid; place-items: center; min-height: 280px; overflow: hidden; }
.receipt img { max-width: 100%; max-height: 70vh; display: block; }
.receipt iframe { width: 100%; height: 60vh; border: 0; }
@media (max-width: 700px) { .sale-detail { grid-template-columns: 1fr; } }

/* ---------- configuración ---------- */
.tabs { display: inline-flex; gap: 2px; background: var(--panel); border: 1px solid var(--line); padding: 4px; border-radius: 99px; margin-bottom: 22px; flex-wrap: wrap; }
.tabs a { padding: 6px 14px; border-radius: 99px; text-decoration: none; color: var(--muted); }
.tabs a.on { background: var(--panel-2); color: var(--text); }
.map-table td, .map-table th { white-space: normal; vertical-align: top; }
.map-table select { min-width: 160px; }
.danger-zone { border-color: rgba(255,107,107,.3); }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.65); backdrop-filter: blur(4px); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: 100%; max-width: 500px; max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px; }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 10px; }
.modal-head h2 { font-size: 19px; display: flex; align-items: center; gap: 10px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #f2f2f2; color: #111; padding: 10px 18px; border-radius: 99px; z-index: 200; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.err { background: var(--red); color: #fff; }

.notice { background: var(--amber-bg); color: var(--amber); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.notice.blue { background: rgba(76,141,255,.12); color: #9dbcff; }
code { background: #0b0b0b; border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }
