:root {
  --bg: #f3f5f4;
  --card: #ffffff;
  --text: #17201c;
  --muted: #66736d;
  --line: #e1e6e3;
  --brand: #0f7b5f;
  --brand-soft: #e2f3ec;
  --danger: #c92a2a;
  --warn: #e8a400;
  --bubble: #dcf5e7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412; --card: #19201d; --text: #e6ece9; --muted: #92a19a; --line: #2a332f;
    --brand: #2bb48b; --brand-soft: #173a2f; --bubble: #1f4a3a; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
h1, h2, h3 { margin: 0; }

/* Login */
.screen { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card img { border-radius: 18px; }
.login-card h1 { margin-top: 12px; font-size: 26px; }
.login-card form { margin-top: 24px; display: grid; gap: 12px; }

/* Layout */
#app { min-height: 100%; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--brand); color: #fff;
}
.topbar h1 { font-size: 19px; font-weight: 650; }
#view { padding: 16px; max-width: 720px; margin: 0 auto; display: grid; gap: 14px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px;
  padding: 8px 0 10px; display: grid; justify-items: center; gap: 2px; cursor: pointer;
}
.tabbar .ico { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--brand); font-weight: 600; }
.tabbar button.active .ico { filter: none; opacity: 1; }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border: 1px solid var(--line); }
.card h2 { font-size: 16px; margin-bottom: 10px; }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }

.qr { display: grid; justify-items: center; gap: 10px; text-align: center; }
.qr img { width: 240px; max-width: 100%; background: #fff; padding: 8px; border-radius: 12px; }
.qr ol { text-align: left; color: var(--muted); font-size: 14px; padding-left: 20px; margin: 0; }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.progress > div { height: 100%; background: var(--brand); transition: width .4s; }

/* Badges / chips */
.badge { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: rgba(255,255,255,.2); color: #fff; white-space: nowrap; }
.badge.ok::before, .badge.bad::before, .badge.wait::before { content: "●"; margin-right: 5px; }
.badge.ok::before { color: #8cf5c9; } .badge.bad::before { color: #ffb3b3; } .badge.wait::before { color: #ffe08a; }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--brand-soft); color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 99px; padding: 7px 12px; font: inherit; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
}
.chip.on { background: var(--brand-soft); border-color: var(--brand); font-weight: 600; }

/* Lista de agendamentos */
.campaign { display: grid; gap: 8px; cursor: pointer; }
.campaign .time { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.campaign .meta { color: var(--muted); font-size: 13px; }
.campaign.off { opacity: .55; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }

/* Botões */
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; border-radius: 10px; padding: 10px 16px; cursor: pointer;
}
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.fab {
  position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 4;
  width: 56px; height: 56px; border-radius: 18px; border: 0; font-size: 28px;
  background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.25); cursor: pointer;
}

/* Formulários */
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; }
legend { font-weight: 650; margin-bottom: 8px; padding: 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.switch input { width: 20px; height: 20px; accent-color: var(--brand); }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.days button { padding: 9px 0; font: inherit; font-size: 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; }
.days button.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.msg-item { position: relative; }
.msg-item .remove { position: absolute; top: 6px; right: 6px; border: 0; background: var(--card); color: var(--muted); border-radius: 8px; width: 28px; height: 28px; cursor: pointer; }
.vars { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.vars button { font: 12px ui-monospace, monospace; border: 1px dashed var(--brand); color: var(--brand); background: transparent; border-radius: 8px; padding: 4px 8px; cursor: pointer; }
.preview { background: var(--bg); border-radius: 12px; padding: 10px 12px; border: 1px solid var(--line); }
.preview-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.bubble { background: var(--bubble); border-radius: 10px 10px 10px 2px; padding: 8px 10px; white-space: pre-wrap; margin-top: 6px; min-height: 2em; font-size: 14px; }

/* Editor (bottom sheet) */
dialog#editor {
  width: 100%; max-width: 720px; height: 100%; max-height: 100%; margin: 0 auto;
  border: 0; padding: 0; background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
.sheet-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: var(--card); border-bottom: 1px solid var(--line);
}
.sheet-body { padding: 16px; display: grid; gap: 22px; padding-bottom: 40px; }

/* Histórico */
.hist { display: grid; gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hist:last-child { border-bottom: 0; }
.hist .top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.hist .txt { color: var(--muted); font-size: 13px; white-space: pre-wrap; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ok-c { color: var(--brand); } .bad-c { color: var(--danger); }

.label-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.label-row:last-child { border-bottom: 0; }
.label-row .name { flex: 1; font-weight: 600; }
.contact-list { font-size: 14px; color: var(--muted); padding: 0 0 10px 19px; display: grid; gap: 2px; }

.warn-box { background: color-mix(in srgb, var(--warn) 14%, var(--card)); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
