:root {
  --bg: #f5f7f7; --card: #fff; --text: #1b2626; --muted: #64748b; --line: #e2e8e8;
  --primary: #0f766e; --primary-2: #115e59; --primary-soft: #ccfbf1;
  --danger: #dc2626; --warn: #d97706; --ok: #16a34a; --wa: #25d366;
  --radius: 14px; --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); }
[hidden] { display: none !important; }

#topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  background: var(--primary); color: #fff; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); min-height: 56px; }
#topbar h1 { flex: 1; font-size: 18px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top-actions { display: flex; gap: 6px; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 28px; line-height: 1; padding: 4px 10px; cursor: pointer; }
#topbar .btn { background: rgba(255,255,255,.18); color: #fff; }

main { padding: 12px; padding-bottom: calc(var(--tabbar) + var(--safe-b) + 24px); max-width: 900px; margin: 0 auto; }
.loading { text-align: center; color: var(--muted); padding: 40px; }

#tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: #fff;
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); height: calc(var(--tabbar) + var(--safe-b)); }
#tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 12px; color: var(--muted); text-decoration: none; gap: 2px; }
#tabbar a span { font-size: 22px; }
#tabbar a.active { color: var(--primary); font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card h2, .card h3 { margin: 0 0 10px; font-size: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.right { text-align: right; }
.between { justify-content: space-between; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pre { white-space: pre-wrap; word-break: break-word; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 10px;
  background: var(--primary); color: #fff; font: inherit; font-weight: 600; padding: 10px 14px; min-height: 44px;
  cursor: pointer; text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn.secondary { background: #e6efee; color: var(--primary-2); }
.btn.danger { background: #fee2e2; color: var(--danger); }
.btn.wa { background: var(--wa); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: 14px; }
.btn[disabled] { opacity: .6; }
.fab { position: fixed; right: 16px; bottom: calc(var(--tabbar) + var(--safe-b) + 16px); z-index: 9; width: 58px; height: 58px;
  border-radius: 50%; font-size: 30px; box-shadow: 0 6px 16px rgba(15,118,110,.35); padding: 0; }

label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
label .req { color: var(--danger); }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--text); }
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 16px; }
.check input { width: 22px; height: 22px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }
.form-actions .btn { flex: 1; }

.seg { display: flex; background: #e6efee; border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; font: inherit; font-size: 14px; color: var(--primary-2); cursor: pointer; }
.seg button.on { background: #fff; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.datebar { display: flex; align-items: center; gap: 6px; margin: 10px 0; }
.datebar .label { flex: 1; text-align: center; font-weight: 600; }
.datebar button { min-width: 44px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a.item { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: inherit; text-decoration: none; }

.appt { display: flex; gap: 10px; align-items: stretch; }
.appt .time { width: 56px; font-weight: 700; font-size: 15px; color: var(--primary-2); }
.appt .time small { display: block; font-weight: 400; color: var(--muted); }
.appt .info { flex: 1; min-width: 0; cursor: pointer; }
.appt.cancelada { opacity: .5; }
.appt.cancelada .info b { text-decoration: line-through; }

.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #e2e8f0; color: #334155; font-weight: 600; }
.chip.agendada { background: #e0f2fe; color: #0369a1; }
.chip.confirmada { background: #dcfce7; color: #15803d; }
.chip.compareceu { background: #ccfbf1; color: #0f766e; }
.chip.faltou { background: #fee2e2; color: #b91c1c; }
.chip.cancelada { background: #f1f5f9; color: #64748b; }
.chip.pend { background: #fef3c7; color: #b45309; }
.chip.paid { background: #dcfce7; color: #15803d; }

.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-2);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }

.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.month .dow { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.month .d { aspect-ratio: 1; background: #fff; border-radius: 10px; border: 1px solid var(--line); padding: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; cursor: pointer; font-size: 14px; }
.month .d.out { opacity: .35; }
.month .d.today { border-color: var(--primary); border-width: 2px; font-weight: 700; }
.month .d .n { font-size: 11px; background: var(--primary); color: #fff; border-radius: 99px; padding: 0 6px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 4px 0 10px; }
.tabs button { border: 0; background: #e6efee; color: var(--primary-2); padding: 8px 14px; border-radius: 99px; font: inherit; font-size: 14px; white-space: nowrap; cursor: pointer; }
.tabs button.on { background: var(--primary); color: #fff; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
.kpi { background: #fff; border-radius: var(--radius); padding: 12px; }
.kpi .v { font-size: 20px; font-weight: 700; }
.kpi .l { font-size: 13px; color: var(--muted); }
.kpi.ok .v { color: var(--ok); } .kpi.warn .v { color: var(--warn); }
.bar { height: 8px; background: #e6efee; border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.days { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.days > div { flex: 1; background: var(--primary-soft); border-radius: 4px 4px 0 0; position: relative; min-height: 2px; }
.days > div > i { position: absolute; bottom: 0; left: 0; right: 0; background: var(--primary); border-radius: 4px 4px 0 0; }

.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.thumbs .t { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #e6efee;
  display: flex; align-items: center; justify-content: center; text-align: center; font-size: 12px; padding: 4px; cursor: pointer; color: var(--text); text-decoration: none; }
.thumbs .t img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.err { color: var(--danger); font-size: 14px; margin-top: 8px; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + var(--safe-b) + 90px);
  background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; }

dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, 96vw); max-height: 92vh; }
dialog::backdrop { background: rgba(0,0,0,.4); }
#modal-body { padding: 16px; overflow: auto; max-height: 92vh; }
#modal-body h2 { margin: 0 0 6px; font-size: 18px; }
@media (max-width: 600px) {
  dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; }
  #modal-body { padding-bottom: calc(16px + var(--safe-b)); }
}

.login { max-width: 380px; margin: 12vh auto 0; }
.login .logo { width: 72px; height: 72px; display: block; margin: 0 auto 10px; }
.login h1 { text-align: center; font-size: 20px; margin: 0 0 4px; }

@media (min-width: 700px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .thumbs { grid-template-columns: repeat(5, 1fr); }
}
