:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn-soft: #fef3c7;
  --ok: #16a34a;
  --chat-bg: #e7e1d8;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 8px rgb(0 0 0 / 0.04);
  --nav-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #2dd4bf;
    --primary-dark: #14b8a6;
    --primary-soft: #134e4a;
    --bg: #0f1514;
    --card: #1a2120;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #2b3533;
    --danger: #f87171;
    --danger-soft: #3f1d1d;
    --warn-soft: #3a2f12;
    --chat-bg: #0b1412;
    --bubble-in: #1f2a28;
    --bubble-out: #144d37;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- layout */
.shell { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--primary); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: var(--card); color: var(--text); border-bottom: 1px solid var(--line); } }
.topbar h1 { font-size: 18px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon-btn { color: inherit; }
main {
  flex: 1; width: 100%; max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; max-width: 190px; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 500;
}
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a.active { color: var(--primary); }

/* ---------- components */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.card h2 { font-size: 16px; margin-bottom: 4px; }
.card > p:first-of-type { margin-top: 4px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--primary); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none;
}
@media (prefers-color-scheme: dark) { .btn { color: #042f2e; } }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: transparent; color: var(--primary); border-color: var(--line); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 10px; cursor: pointer; color: var(--text); display: inline-flex; }
.icon-btn svg { width: 22px; height: 22px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
label.field small { display: block; color: var(--muted); margin-top: 4px; font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=url], input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); outline: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
input[readonly] { color: var(--muted); }
.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; min-width: 0; }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 26px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(18px); }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary-dark); }
@media (prefers-color-scheme: dark) { .badge { color: var(--primary); } }
.badge.gray { background: var(--line); color: var(--muted); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: #dcfce7; color: #166534; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px;
  background: var(--bg); border: 1px solid var(--line); font-size: 14px; cursor: pointer;
}
.chip.selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.status { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--warn-soft); }
.status.ok { background: var(--primary-soft); }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: #d97706; flex-shrink: 0; }
.status.ok .dot { background: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

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

/* ---------- modal (bottom sheet) */
dialog.sheet {
  border: 0; padding: 0; width: 100%; max-width: 560px; margin: auto auto 0; border-radius: 18px 18px 0 0;
  background: var(--card); color: var(--text); max-height: 90vh;
}
@media (min-width: 640px) { dialog.sheet { margin: auto; border-radius: 18px; } }
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet-head { display: flex; align-items: center; padding: 14px 16px 6px; gap: 8px; }
.sheet-head h2 { flex: 1; font-size: 17px; }
.sheet-body { padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); }

/* ---------- login */
.login { max-width: 380px; margin: 0 auto; padding: 48px 20px; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 16px; }
.login h1 { text-align: center; font-size: 24px; margin-bottom: 4px; }
.login p.lead { text-align: center; margin: 0 0 24px; color: var(--muted); }
.login .form-error { color: var(--danger); margin: -4px 0 12px; }
.auth-switch { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 6px; }
.topbar h1 small { display: block; font-size: 12px; font-weight: 500; opacity: .8; margin-top: 2px; }

/* ---------- agenda */
.weekbar { display: flex; align-items: center; gap: 4px; margin-bottom: 12px; }
.weekbar .label { flex: 1; text-align: center; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }
.day { margin-bottom: 16px; }
.day-head { display: flex; align-items: baseline; gap: 8px; padding: 0 4px 6px; }
.day-head h3 { font-size: 15px; }
.day-head.today h3 { color: var(--primary); }
.day-head .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.appt {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
}
.appt .time { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 48px; color: var(--primary); }
.appt .who { flex: 1; min-width: 0; }
.appt .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .who span { font-size: 13px; color: var(--muted); }
.appt.cancelled { opacity: .55; }
.appt.cancelled .time, .appt.cancelled b { text-decoration: line-through; }
.appt.done .time { color: var(--muted); }
.day-empty { font-size: 13px; color: var(--muted); padding: 10px 12px; border: 1px dashed var(--line); border-radius: 12px; }
.fab {
  position: fixed; right: max(20px, calc(50% - 360px)); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--primary); color: #fff;
  box-shadow: 0 6px 16px rgb(0 0 0 / 0.2); cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 9;
}
@media (prefers-color-scheme: dark) { .fab { color: #042f2e; } }
.fab svg { width: 28px; height: 28px; }
.detail-list { list-style: none; padding: 0; margin: 0 0 8px; }
.detail-list li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.detail-list li span:first-child { color: var(--muted); width: 90px; flex-shrink: 0; }

/* ---------- horários */
.sched-day { display: grid; grid-template-columns: 44px 1fr; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: start; }
.sched-day:last-child { border-bottom: 0; }
.sched-day .name { font-weight: 600; padding-top: 8px; }
.sched-day .times { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sched-day .times label { font-size: 11px; color: var(--muted); display: block; }
.sched-day.off .times { display: none; }
.sched-day .head { display: flex; align-items: center; gap: 10px; grid-column: 2; }
.sched-day .head .muted { font-size: 13px; }

/* ---------- whatsapp */
.steps { padding-left: 20px; margin: 8px 0 0; }
.steps li { margin-bottom: 8px; }
details summary { cursor: pointer; font-weight: 600; }
code { background: var(--bg); padding: 1px 6px; border-radius: 6px; font-size: 13px; word-break: break-all; }

/* ---------- simulador */
.chat-wrap { display: flex; flex-direction: column; height: calc(100dvh - 210px - env(safe-area-inset-bottom) - env(safe-area-inset-top)); min-height: 360px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.chat-head .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.chat { flex: 1; overflow-y: auto; padding: 14px 12px; background: var(--chat-bg); display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 85%; padding: 8px 10px; border-radius: 10px; box-shadow: 0 1px 1px rgb(0 0 0 / 0.08); white-space: normal; word-wrap: break-word; }
.bubble.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 2px; }
.bubble.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 2px; }
.bubble .opts { display: flex; flex-direction: column; margin: 8px -10px -8px; border-top: 1px solid var(--line); }
.bubble .opts button { background: none; border: 0; border-bottom: 1px solid var(--line); padding: 9px 12px; text-align: left; color: var(--primary); cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.bubble .opts button:last-child { border-bottom: 0; }
.bubble .opts button .n { font-size: 12px; color: var(--muted); min-width: 14px; }
.bubble .opts button .d { display: block; font-size: 12px; color: var(--muted); }
.chat-input { display: flex; gap: 8px; padding: 8px; background: var(--card); border-top: 1px solid var(--line); }
.chat-input input { flex: 1; border-radius: 99px; }
.chat-input button { border-radius: 50%; width: 42px; padding: 0; }
.typing { align-self: flex-start; font-size: 13px; color: var(--muted); padding: 0 4px; }

/* ---------- login com o Google / perfil */
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  min-height: 44px; padding: 0 16px; border-radius: 99px; cursor: pointer;
  background: #fff; color: #1f1f1f; border: 1px solid #dadce0; font-weight: 600;
  font-family: Roboto, system-ui, sans-serif;
}
.btn-google:hover { background: #f8f9fa; }
.btn-google:disabled { opacity: .6; cursor: default; }
@media (prefers-color-scheme: dark) {
  .btn-google { background: #131314; color: #e3e3e3; border-color: #8e918f; }
  .btn-google:hover { background: #1f1f20; }
}
.divider { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.profile-head { display: flex; align-items: center; gap: 14px; }
.avatar-lg {
  width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700;
}
@media (prefers-color-scheme: dark) { .avatar-lg { color: #042f2e; } }
.google-linked { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.topbar a.icon-btn { text-decoration: none; }
.topbar a.icon-btn.active { background: rgb(255 255 255 / .15); }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.detail-list li span:last-child { min-width: 0; overflow-wrap: anywhere; }

/* ---------- mostrar/ocultar senha */
.password-field { position: relative; }
.password-field input { padding-right: 48px; }
.password-toggle {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 40px; height: 36px; border: 0; background: none; border-radius: 8px;
  color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.password-toggle:hover, .password-toggle[aria-pressed="true"] { color: var(--primary); }
.password-toggle svg { width: 20px; height: 20px; }
/* esconde o olho nativo do Edge para não ficar duplicado */
input::-ms-reveal, input::-ms-clear { display: none; }
