:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1d2320;
  --muted: #6b736e;
  --line: #e3e6e1;
  --accent: #128c5e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3ea;
  --warn: #c98a12;
  --warn-soft: #fbf1dc;
  --danger: #c2412d;
  --danger-soft: #fbe6e2;
  --bubble-in: #ffffff;
  --bubble-out: #dcf4e6;
  --chat-bg: #eef0ea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; font-size: 14px; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; color: var(--ink); font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1em; margin: 6px 0 0; }

.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f7f8f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px; }
.link:hover { color: var(--ink); text-decoration: underline; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 16px; padding: 6px 8px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: #f0f1ee; color: var(--ink); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 360px; }
.login-card .btn { width: 100%; margin-top: 6px; padding: 10px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* Layout */
.app { display: grid; grid-template-columns: 210px 1fr; height: 100vh; }
.sidebar { background: #16201b; color: #dfe6e1; display: flex; flex-direction: column; padding: 16px 10px; }
.sidebar .brand { color: #fff; padding: 4px 8px 18px; }
.sidebar .brand-dot { box-shadow: 0 0 0 4px rgba(18,140,94,.35); }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: #b9c4bd; user-select: none; }
#nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
#nav a.active { background: rgba(18,140,94,.25); color: #fff; }
#nav .ico { width: 20px; text-align: center; }
.badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 7px; }
.badge.soft { background: rgba(255,255,255,.15); }
.sidebar-foot { margin-top: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.sidebar-foot .link { color: #8e9a93; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 20px; background: rgba(255,255,255,.08); }
.pill.ok { background: rgba(18,140,94,.3); color: #c7f0d9; }
.pill.bad { background: rgba(194,65,45,.3); color: #ffd7cf; }
.main-wrap { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
main { overflow: auto; min-width: 0; flex: 1; min-height: 0; }
.mp-banner { background: var(--accent); color: #fff; padding: 9px 18px; font-weight: 600; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.mp-banner:hover { filter: brightness(1.06); }

.page { padding: 22px 26px; max-width: 1100px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head .spacer { flex: 1; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tabs { display: inline-flex; background: #e9ebe6; border-radius: 8px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 6px 10px; white-space: nowrap; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #fafbf9; }
.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 10px; color: #fff; margin: 0 3px 3px 0; font-weight: 500; }
.chip { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #eef0ec; color: var(--muted); font-weight: 500; }
.chip.ok { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--danger-soft); color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* Chats */
.chats { display: grid; grid-template-columns: 340px 1fr; height: 100%; }
.chat-list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.chat-list-head { padding: 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.chat-items { overflow: auto; flex: 1; }
.chat-item { padding: 11px 14px; border-bottom: 1px solid #f0f1ee; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.chat-item:hover { background: #f8f9f7; }
.chat-item.active { background: var(--accent-soft); }
.chat-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { font-size: 11px; color: var(--muted); }
.chat-item .prev { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .meta { grid-column: 1 / -1; display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.unread { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; justify-self: end; align-self: center; }
.wait { font-size: 11px; font-weight: 600; }
.wait.g { color: var(--accent); } .wait.y { color: var(--warn); } .wait.r { color: var(--danger); }

.conv { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.conv-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.conv-head .who { flex: 1; min-width: 160px; }
.conv-head .who b { display: block; font-size: 15px; }
.conv-head select { width: auto; padding: 5px 8px; font-size: 13px; }
.conv-tags { padding: 6px 16px; background: #fafbf9; border-bottom: 1px solid var(--line); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.msgs { flex: 1; overflow: auto; padding: 18px 6%; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: rgba(255,255,255,.8); font-size: 11px; color: var(--muted); padding: 3px 10px; border-radius: 8px; margin: 10px 0 6px; }
.bubble { max-width: 70%; padding: 7px 10px 5px; border-radius: 10px; background: var(--bubble-in); box-shadow: 0 1px 1px rgba(0,0,0,.05); white-space: pre-wrap; word-wrap: break-word; align-self: flex-start; }
.bubble.out { background: var(--bubble-out); align-self: flex-end; }
.bubble .t { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 2px; }
.bubble .type { font-size: 12px; color: var(--muted); font-style: italic; }
.bubble.sched { background: #fff; border: 1.5px dashed var(--accent); align-self: flex-end; opacity: .95; }
.bubble.sched .t { display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 12px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; resize: none; }
.conv-empty { flex: 1; display: grid; place-items: center; color: var(--muted); }
.back-btn { display: none; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(15,20,17,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; padding: 18px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; flex: 1; font-size: 17px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; color: var(--ink); font-size: 13px; }
.check input { width: auto; margin-top: 2px; }
.preview-list { background: #f7f8f6; border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.preview-list div { margin-bottom: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2320; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--danger); }
.qr-box { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.qr-box img { width: 260px; height: 260px; border-radius: 8px; border: 1px solid var(--line); }
.steps { margin: 0; padding-left: 18px; line-height: 1.8; }
.appt-day { font-weight: 600; margin: 18px 0 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.appt { display: flex; gap: 14px; align-items: center; }
.appt .hour { font-size: 18px; font-weight: 700; width: 64px; }
.appt .info { flex: 1; }

/* Mobile */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; height: 100dvh; }
  .sidebar { order: 2; flex-direction: row; padding: 4px; }
  .sidebar .brand, .sidebar-foot { display: none; }
  #nav { flex-direction: row; flex: 1; justify-content: space-around; }
  #nav a { flex-direction: column; gap: 2px; font-size: 10px; padding: 6px 4px; position: relative; }
  #nav .badge { position: absolute; top: 0; right: 0; margin: 0; }
  main { order: 1; }
  .main-wrap { order: 1; height: auto; min-height: 0; }
  .chats { grid-template-columns: 1fr; height: 100%; }
  .chats.open .chat-list { display: none; }
  .chats:not(.open) .conv { display: none; }
  .back-btn { display: inline-block; }
  .page { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .bubble { max-width: 85%; }
  .msgs { padding: 14px 10px; }
  .hide-m { display: none; }
  #nav { overflow-x: auto; justify-content: flex-start; }
  #nav a { flex: 0 0 auto; min-width: 58px; }
  .stat { padding: 2px 10px 2px 0; margin-right: 10px; }
  .stat b { font-size: 17px; }
}

/* Selector de fecha y hora 24 h */
.dt { display: flex; gap: 6px; align-items: center; margin: 4px 0 4px; flex-wrap: wrap; }
.dt input[type=date] { width: auto; flex: 1; min-width: 150px; }
.dt select { width: auto; padding: 8px 6px; }
.dt-hint { min-height: 18px; margin-bottom: 10px; }

/* MatchProp */
.mp-req { padding: 0; overflow: hidden; }
.mp-req-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.mp-req-head .who { flex: 1; min-width: 200px; }
.mp-msg { background: #f7f8f6; border-left: 3px solid var(--line); padding: 8px 12px; margin: 8px 0 0; font-size: 13px; white-space: pre-wrap; color: #3b423e; max-height: 120px; overflow: auto; border-radius: 4px; }
.mp-crit { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.mp-match { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; padding: 10px 16px; border-bottom: 1px solid #f0f1ee; align-items: center; }
.mp-match:last-child { border-bottom: 0; }
.mp-match.reviewed { opacity: .6; }
.mp-thumb { width: 64px; height: 48px; border-radius: 6px; background: #eef0ec center/cover no-repeat; display: grid; place-items: center; font-size: 20px; }
.mp-price { font-weight: 700; }
.mp-actions { padding: 10px 16px; background: #fafbf9; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.mp-groups { max-height: 340px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.mp-groups label { margin: 6px 0; }
.warn-box { background: var(--warn-soft); color: #7a5208; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 10px; }
.stat { display: inline-flex; flex-direction: column; padding: 4px 18px 4px 0; margin-right: 18px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat b { font-size: 20px; }
@media (max-width: 820px) { .mp-match { grid-template-columns: 48px 1fr; } .mp-match > .mp-side { grid-column: 1 / -1; } .mp-thumb { width: 48px; height: 40px; } }
