:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --border: #dfe2dc;
  --text: #1c211e;
  --muted: #66706a;
  --accent: #0f7b5f;
  --accent-soft: #dcefe8;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --danger-soft: #f8e1de;
  --warn: #b7791f;
  --warn-soft: #fbf0d9;
  --vip: #d69e2e;
  --bubble-in: #ffffff;
  --bubble-out: #d9f2e6;
  --bubble-owner: #e3ecfb;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1311;
    --surface: #171c19;
    --surface-2: #1f2622;
    --border: #2b332e;
    --text: #e6ebe7;
    --muted: #93a098;
    --accent: #34c08f;
    --accent-soft: #173a2e;
    --accent-text: #06140f;
    --danger: #ef6b5b;
    --danger-soft: #3a1d19;
    --warn: #e2b04a;
    --warn-soft: #362a12;
    --bubble-in: #1f2622;
    --bubble-out: #173a2e;
    --bubble-owner: #1c2840;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
small, .muted { color: var(--muted); }
code { font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 650; }
.brand-dot { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: var(--accent-text); font-size: 15px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 10px; }
.main { padding: 26px 30px 60px; max-width: 1120px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.5rem; font-weight: 650; margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 550; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.07); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.btn-icon { padding: 6px; border: none; background: none; }

input[type=text], input[type=password], input[type=number], input[type=time], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 8px 11px;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 550; margin-bottom: 5px; font-size: .92rem; }
.help { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.switch { position: relative; width: 50px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(22px); }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-ok { background: var(--accent-soft); color: var(--accent); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.star { color: var(--vip); }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item.clickable { cursor: pointer; border-radius: 8px; padding-left: 8px; padding-right: 8px; }
.list-item.clickable:hover { background: var(--surface-2); }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.list-sub { color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 650; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: none; font: inherit; font-weight: 550; color: var(--muted); padding: 9px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- conversas ---------- */
.thread { display: flex; flex-direction: column; gap: 8px; max-height: 58vh; overflow-y: auto; padding: 6px 2px 10px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; border: 1px solid var(--border); }
.bubble small { display: block; font-size: .72rem; margin-top: 3px; }
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-color: transparent; border-bottom-right-radius: 4px; }
.bubble.owner { align-self: flex-end; background: var(--bubble-owner); border-color: transparent; border-bottom-right-radius: 4px; }
.composer { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.composer textarea { min-height: 44px; max-height: 160px; }
.typing { color: var(--muted); font-size: .88rem; display: flex; align-items: center; gap: 8px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.qr { display: grid; place-items: center; padding: 14px; background: #fff; border-radius: 12px; width: fit-content; margin: 8px auto; }
.qr img { width: 260px; height: 260px; image-rendering: pixelated; }
.pairing { font-family: ui-monospace, monospace; font-size: 1.4rem; letter-spacing: .2em; text-align: center; }

.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; cursor: pointer; user-select: none; }
.days input { display: none; }
.days label:has(input:checked) { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.toast { position: fixed; right: 20px; bottom: 20px; background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 50; max-width: calc(100vw - 40px); }
.toast.error { background: var(--danger); color: #fff; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; margin-bottom: 10px; font-size: .9rem; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 20;
    flex-direction: row; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); border-right: none; border-top: 1px solid var(--border);
  }
  .brand, .sidebar-foot { display: none; }
  .nav { display: flex; width: 100%; justify-content: space-between; overflow-x: auto; }
  .nav a { flex-direction: column; gap: 2px; font-size: .68rem; padding: 6px 8px; min-width: 56px; }
  .main { padding: 18px 16px 96px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .bubble { max-width: 88%; }
  .thread { max-height: 52vh; }
}
