:root {
  color-scheme: dark;
  --bg: #121110;
  --surface: #1b1a18;
  --surface-2: #23211e;
  --surface-3: #2c2925;
  --ink: #f1ece4;
  --muted: #9b948a;
  --line: #2f2c28;
  --line-soft: #26231f;
  --accent: #c08a4b;
  --accent-hi: #d9a466;
  --accent-soft: rgba(192, 138, 75, 0.14);
  --danger: #e06450;
  --ok: #3fb68b;
  --warn: #e0b43c;
  --radius: 14px;
  --accent-ink: #17130e;
  --font-title: Oswald, Impact, sans-serif;
  --font-body: Inter, system-ui, sans-serif;
  --header-bg: #0c0b0a;
  --closed-a: #171614;
  --closed-b: #1a1917;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
a { color: var(--accent-hi); }

/* ---------- Header ---------- */
header {
  position: sticky; top: 0; z-index: 5;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 20px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 44px; height: 44px; flex: none; display: grid; place-items: center; }
.logo svg, .logo img { width: 100%; height: 100%; display: block; object-fit: contain; }
.logo.initial { border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-family: var(--font-title); font-weight: 700; font-size: 22px; }
body.no-dur .dur-col { display: none; }
.brand h1 {
  margin: 0; font-family: var(--font-title); font-weight: 700;
  font-size: 22px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); line-height: 1.05;
}
.brand span { font-size: 12px; color: var(--muted); letter-spacing: .04em; }
nav { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.tab {
  background: transparent; color: var(--muted); border: 0; padding: 8px 14px;
  border-radius: 9px; cursor: pointer; font: inherit; font-size: 14px; font-weight: 500;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--surface-3); color: var(--ink); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #666; margin-left: 4px; vertical-align: 1px; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(63,182,139,.18); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--danger); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

/* ---------- Controles ---------- */
button {
  font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; transition: background .15s, border-color .15s;
}
button:hover { border-color: var(--muted); background: var(--surface-3); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.icon { width: 38px; padding: 8px 0; font-size: 18px; line-height: 1; }
input, select {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--ink); width: 100%;
}
input::placeholder { color: var(--muted); opacity: .7; }

/* ---------- Agenda: encabezado ---------- */
.agenda-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.agenda-head h2 { margin: 0; font-family: var(--font-title); font-weight: 600; font-size: 26px; letter-spacing: .01em; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 8px; }
.seg button.on { background: var(--surface-3); color: var(--ink); }
.nav-date { display: flex; align-items: center; gap: 6px; }
.nav-date input { width: 150px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat b { font-family: var(--font-title); font-variant-numeric: lining-nums tabular-nums; font-size: 26px; font-weight: 600; color: var(--accent-hi); line-height: 1.15; }
.stat small { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border-radius: 999px; padding: 6px 13px; font-size: 13.5px; display: inline-flex; align-items: center; gap: 7px; background: var(--surface); color: var(--muted); }
.chip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.note { background: rgba(224,180,60,.1); border: 1px solid rgba(224,180,60,.35); color: var(--ink); padding: 9px 13px; border-radius: 10px; margin-bottom: 10px; font-size: 14px; }
.hint { margin-top: 10px; }

/* ---------- Vista día ---------- */
.grid-wrap {
  overflow: auto; max-height: calc(100vh - 290px); min-height: 360px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.grid { display: flex; min-width: max-content; }
.times { width: 58px; flex: none; position: sticky; left: 0; z-index: 4; background: var(--surface); border-right: 1px solid var(--line); }
.col { flex: 1; min-width: 180px; border-right: 1px solid var(--line-soft); }
.col:last-child { border-right: 0; }
.colhead {
  height: 46px; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; font-size: 14.5px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 3; background: var(--surface);
}
.times .colhead { z-index: 5; }
.colhead i { width: 9px; height: 9px; border-radius: 50%; }
.colhead small { font-weight: 500; color: var(--muted); background: var(--surface-3); border-radius: 999px; padding: 0 7px; font-size: 12px; }
.colhead small:empty { display: none; }
.colbody { position: relative; background: repeating-linear-gradient(135deg, var(--closed-a) 0 8px, var(--closed-b) 8px 16px); cursor: copy; }
.colbody.off { cursor: default; }
.openband { position: absolute; left: 0; right: 0; background: var(--surface); }
.hline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); pointer-events: none; }
.hline.half { border-top-style: dashed; border-top-color: var(--line-soft); }
.tlabel { position: absolute; right: 8px; font-size: 11.5px; color: var(--muted); transform: translateY(-50%); font-variant-numeric: tabular-nums; }
.tlabel:first-child { transform: translateY(2px); }
.nowline { position: absolute; left: 0; right: 0; border-top: 2px solid var(--danger); z-index: 2; pointer-events: none; }
.nowline::before { content: ""; position: absolute; left: -1px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.appt {
  position: absolute; left: 5px; right: 5px; border-radius: 9px; padding: 5px 9px; overflow: hidden; cursor: pointer; z-index: 1;
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); border-left: 3px solid var(--c);
  font-size: 13px; line-height: 1.3; transition: transform .1s, filter .1s;
}
.appt:hover { filter: brightness(1.15); }
.appt b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.appt span { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.appt.past { opacity: .45; }

/* ---------- Vista semana ---------- */
.week { display: grid; grid-template-columns: repeat(var(--days, 7), minmax(0, 1fr)); gap: 8px; }
.wday { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-width: 0; }
.wday.today { border-color: var(--accent); }
.wday.closed { opacity: .55; }
.whead {
  display: flex; align-items: baseline; gap: 6px; border: 0; border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0;
  background: transparent; padding: 10px 12px; text-align: left; width: 100%;
}
.whead b { font-family: var(--font-title); font-weight: 600; font-size: 16px; }
.whead span { color: var(--muted); font-size: 13px; }
.whead em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--accent-hi); background: var(--accent-soft); border-radius: 999px; padding: 1px 8px; }
.wday.today .whead b { color: var(--accent-hi); }
.wday > p, .wlist > p { margin: 10px 12px; }
.wlist { display: flex; flex-direction: column; gap: 4px; padding: 6px; overflow-y: auto; max-height: calc(100vh - 330px); }
.witem {
  display: flex; gap: 8px; align-items: flex-start; text-align: left; border: 0; border-left: 3px solid var(--c);
  background: color-mix(in srgb, var(--c) 12%, var(--surface-2)); border-radius: 8px; padding: 6px 8px; width: 100%;
}
.witem time { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); padding-top: 1px; }
.witem span { min-width: 0; display: flex; flex-direction: column; }
.witem b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.witem small { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.witem.past { opacity: .45; }

/* ---------- Tarjetas / configuración ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 14px; font-family: var(--font-title); font-weight: 600; font-size: 20px; letter-spacing: .02em; }
.card h3 { margin: 18px 0 4px; font-size: 15px; }
.card.center { text-align: center; max-width: 520px; margin: 0 auto; }
.card button + button { margin-left: 6px; }
code { background: var(--surface-3); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px 16px; margin-bottom: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row !important; align-items: center; gap: 8px; color: var(--ink) !important; }
label.check input, table.edit input[type=checkbox], .days input { width: auto; accent-color: var(--accent); }
table.edit { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
table.edit th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 4px 6px; text-transform: uppercase; letter-spacing: .05em; }
table.edit td { padding: 5px 6px; vertical-align: middle; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days label { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); }

.big { font-size: 18px; font-weight: 600; }
#waQr { width: 280px; height: 280px; margin: 10px auto; display: block; border-radius: 12px; background: #fff; padding: 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-box { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: 100%; max-width: 460px; position: relative; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-box h2 { margin: 0 0 16px; font-family: var(--font-title); font-weight: 600; font-size: 22px; }
.modal-box .close { position: absolute; top: 12px; right: 12px; border: 0; font-size: 22px; background: transparent; color: var(--muted); padding: 4px 10px; }
.modal-box label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.modal-box label.check { margin-bottom: 10px; }
.modal-box .row { display: flex; gap: 10px; }
.modal-box .row > * { flex: 1; min-width: 0; }
.modal-box .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.detail p { margin: 7px 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface-3); border: 1px solid var(--line); color: var(--ink); padding: 11px 18px; border-radius: 12px; z-index: 20; box-shadow: 0 10px 30px rgba(0,0,0,.4); }

/* ---------- Pantallas medianas: semana en 2 columnas ---------- */
@media (max-width: 1100px) {
  .week { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .wlist { max-height: none; }
}

/* ---------- Celular ---------- */
@media (max-width: 700px) {
  header { padding: 10px 16px; }
  .logo { width: 36px; height: 36px; }
  .brand h1 { font-size: 19px; }
  nav { width: 100%; }
  .tab { flex: 1; padding: 8px 6px; }
  main { padding: 14px 16px; }
  .agenda-head h2 { font-size: 21px; width: 100%; }
  .toolbar { width: 100%; }
  .seg { flex: none; }
  .nav-date { flex: 1; justify-content: flex-end; }
  .nav-date input { display: none; }
  #newBtn { position: fixed; right: 16px; bottom: 18px; z-index: 6; border-radius: 999px; padding: 13px 20px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:last-child { grid-column: 1 / -1; }
  .stat b { font-size: 22px; }
  .grid-wrap { max-height: none; }
  .col { min-width: 150px; }
  .times { width: 48px; }
  .week { grid-template-columns: 1fr; }
  .wday.closed { display: none; }
  .hint { margin-bottom: 70px; }
  table.edit thead { display: none; }
  table.edit tr { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.edit td:first-child { grid-column: 1 / -1; }
}

/* ---------- Atendido / No vino ---------- */
.appt.o-done, .witem.o-done { opacity: .6; }
.appt.o-noshow, .witem.o-noshow { opacity: .7; border-left-color: var(--danger); background: rgba(224,100,80,.1); }
.appt.o-noshow b, .witem.o-noshow b { text-decoration: line-through; text-decoration-color: rgba(224,100,80,.7); }
.outcome-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.outcome-btns button { padding: 12px; font-weight: 600; font-size: 15px; }
.outcome-btns .done { background: rgba(63,182,139,.15); border-color: rgba(63,182,139,.5); }
.outcome-btns .done:hover { background: rgba(63,182,139,.25); }
.outcome-btns .noshow { background: rgba(224,100,80,.12); border-color: rgba(224,100,80,.45); }
.outcome-btns .noshow:hover { background: rgba(224,100,80,.22); }
.outcome-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; padding: 10px 14px; border-radius: 10px; font-weight: 600; }
.outcome-banner.done { background: rgba(63,182,139,.15); border: 1px solid rgba(63,182,139,.45); }
.outcome-banner.noshow { background: rgba(224,100,80,.12); border: 1px solid rgba(224,100,80,.45); }
.cancel-box { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.cancel-box summary { cursor: pointer; color: var(--muted); font-size: 13.5px; margin-bottom: 10px; }
.cancel-box summary:hover { color: var(--ink); }

/* ---------- Barra cuando el administrador mira un negocio ---------- */
.admin-bar { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; padding: 8px 20px; background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: 13.5px; color: var(--muted); }
.admin-bar a { color: var(--ink); font-weight: 600; text-decoration: none; }
.admin-bar a:hover { color: var(--accent-hi); }
#logoutBtn { color: var(--muted); }

/* Botón de tema claro/oscuro */
.tab.theme-btn { flex: none; padding: 8px 11px; font-size: 15px; line-height: 1; }

/* ---------- Turnos detectados en los chats ---------- */
.det-btn { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600; }
.det-btn b { color: var(--accent-hi); }
.det-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; background: var(--surface-2); }
.det-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.det-head span { color: var(--muted); font-size: 13px; }
.det-dudas { margin: 4px 0 8px; padding-left: 0; list-style: none; font-size: 13px; color: var(--warn); }
.det-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; margin-top: 10px; }
.det-fields label:first-child { grid-column: 1 / -1; }
.chat { display: flex; flex-direction: column; gap: 5px; margin: 8px 0; max-height: 260px; overflow-y: auto; padding: 8px; background: var(--bg); border-radius: 10px; }
.bubble { max-width: 82%; padding: 6px 10px; border-radius: 12px; font-size: 13.5px; line-height: 1.35; display: flex; flex-direction: column; }
.bubble small { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.bubble.cliente { align-self: flex-start; background: var(--surface-3); border-bottom-left-radius: 4px; }
.bubble.local, .bubble.bot { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.det-ev summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-top: 8px; }
.aprendizaje { text-align: left; }
.aprendizaje h3 { margin: 0 0 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tagf { background: var(--surface-3); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; }
.tagf small { color: var(--muted); }
.chat { overflow-x: hidden; }
.bubble span { overflow-wrap: anywhere; }
.modal-box { overflow-x: hidden; }

/* ---------- Clientes ---------- */
.cli-search { max-width: 320px; }
.cli-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px; }
.cli { display: flex; align-items: center; gap: 12px; text-align: left; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); width: 100%; }
.cli:hover { background: var(--surface-2); }
.cli-av { width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--c); }
.cli-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cli-main b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cli-main small { color: var(--muted); font-size: 12.5px; }
.cli-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.cli-tags em { font-style: normal; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--surface-3); color: var(--muted); }
.cli-tags em.fav { background: var(--accent-soft); color: var(--ink); }
.cli-tags em.bad, .bad { color: var(--danger); }
.cli-num { display: flex; flex-direction: column; align-items: center; flex: none; }
.cli-num b { font-family: var(--font-title); font-size: 20px; }
.cli-num small { font-size: 11px; color: var(--muted); }
.cli-mini { grid-template-columns: repeat(3, 1fr) !important; margin: 10px 0 14px; }
.cli-mini .stat b { font-size: 19px; }
.cli-h { margin: 18px 0 8px; font-size: 15px; }
.cli-turnos { display: flex; flex-direction: column; gap: 4px; }
.cli-turno { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; font-size: 13px; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); }
.cli-turno.cancel { opacity: .55; text-decoration: line-through; }
textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--ink); width: 100%; resize: vertical; }
