:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --ink: #1d2a28;
  --muted: #5d6b68;
  --line: #dfe5e3;
  --brand: #0f5c55;
  --brand-soft: #e3f0ee;
  --accent: #c2410c;
  --accent-soft: #fdf0e8;
  --danger: #b42318;
  --ok: #138a52;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 40, 36, 0.06), 0 6px 20px rgba(16, 40, 36, 0.05);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

button { font: inherit; }

/* ----- barra do topo ----- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  flex: none;
}

.brand h1 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }
.brand-sub { color: var(--muted); font-size: 13px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.line-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 13px;
  white-space: nowrap;
}
.line-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #a3aeab; }
.line-status[data-online="true"] .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(19, 138, 82, 0.15); }
.line-state { color: var(--muted); }
.line-status[data-online="true"] .line-state { color: var(--ok); font-weight: 600; }

/* ----- botões ----- */

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: #0c4c46; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--bg); }
.btn-lg { padding: 12px 26px; font-size: 16px; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }

/* ----- layout ----- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  grid-template-areas:
    "call agenda"
    "callbacks agenda";
  grid-template-rows: auto 1fr;
  gap: 20px;
  padding: 20px 24px 32px;
  max-width: 1400px;
  margin: 0 auto;
}

.call-card { grid-area: call; }
.callbacks-card { grid-area: callbacks; align-self: start; }
.agenda-card { grid-area: agenda; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card h2 { font-size: 16px; font-weight: 650; }

.empty, .transcript-empty { color: var(--muted); font-size: 14px; list-style: none; }

/* ----- ligação ----- */

.call-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.call-card h2 { font-size: 19px; }
.call-meta { color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.call-reason {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: #7a2e0b;
  font-weight: 500;
}
.call-error { margin-top: 10px; color: var(--danger); font-weight: 600; }
.call-actions { display: flex; gap: 8px; flex: none; }

.call-card[data-state="ai"] h2::before,
.call-card[data-state="human"] h2::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 10px;
  background: var(--ok);
  vertical-align: middle;
  animation: pulse 1.6s ease-in-out infinite;
}
.call-card[data-state="waiting"] { border-color: #f0b48f; box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.12), var(--shadow); }
.call-card[data-state="waiting"] h2 { color: var(--accent); }
.call-card[data-state="waiting"] #answerBtn { animation: ring 1.2s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes ring { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }

.transcript-wrap { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.transcript-wrap h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }

.transcript {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.turn { display: flex; flex-direction: column; max-width: 85%; padding: 8px 12px; border-radius: 12px; }
.turn-role { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.7; }
.turn-agent { align-self: flex-start; background: var(--brand-soft); border-top-left-radius: 4px; }
.turn-patient { align-self: flex-end; background: #eef1f0; border-top-right-radius: 4px; }

/* ----- retornos ----- */

.callbacks { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.callback {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "main btn" "reason btn" "time btn";
  column-gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: background 0.4s;
}
.cb-main { grid-area: main; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.cb-phone { color: var(--muted); font-variant-numeric: tabular-nums; }
.cb-reason { grid-area: reason; font-size: 14px; }
.cb-time { grid-area: time; color: var(--muted); font-size: 12px; }
.callback .btn { grid-area: btn; align-self: center; }

.is-new { animation: flash 10s ease-out; }
@keyframes flash {
  0%, 12%, 24% { background: #fff3c4; box-shadow: 0 0 0 2px #f2c94c; }
  6%, 18% { background: #fffbe8; box-shadow: 0 0 0 2px #f8e3a3; }
  100% { background: transparent; box-shadow: none; }
}

/* ----- agenda ----- */

.agenda-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.agenda-head select {
  font: inherit;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  max-width: 60%;
}

.day-strip {
  position: relative;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin: 14px -4px 16px;
  padding: 2px 4px 6px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.day {
  flex: none;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
  scroll-snap-align: center;
}
.day.is-active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

.agenda-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }

.doctor { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.doctor header { padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.doctor h3 { font-size: 14px; font-weight: 650; }
.doctor header p { color: var(--muted); font-size: 12px; }

.slots { list-style: none; margin: 0; padding: 4px 0; }
.slot { display: flex; gap: 12px; padding: 7px 12px; font-size: 14px; border-radius: 8px; }
.slot time { font-variant-numeric: tabular-nums; color: var(--muted); width: 44px; flex: none; }
.slot-free span { color: var(--ok); font-weight: 600; }
.slot-busy span { color: var(--ink); }
.slot-past { opacity: 0.45; }

/* ----- celular ----- */

@media (max-width: 760px) {
  body { font-size: 15px; }
  .topbar { padding: 10px 14px; flex-wrap: wrap; position: static; }
  #soundBtn { white-space: nowrap; min-height: 36px; padding: 6px 12px; }
  .brand h1 { font-size: 16px; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "call" "callbacks" "agenda";
    grid-template-rows: auto;
    gap: 14px;
    padding: 14px 12px 28px;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }
  .card { padding: 16px; }
  .call-head { flex-direction: column; }
  .call-actions, .call-actions .btn { width: 100%; }
  .btn-lg { min-height: 52px; }
  .transcript { max-height: 280px; }
  .agenda-grid { grid-template-columns: minmax(0, 1fr); }
  .agenda-head select { max-width: 55%; }
}

/* ----- login ----- */

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card .brand-mark { margin: 0 auto 14px; width: 48px; height: 48px; font-size: 30px; }
.login-card h1 { font-size: 20px; }
.login-card p.sub { color: var(--muted); margin: 4px 0 22px; }
.login-card label { display: block; text-align: left; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.login-card input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 14px;
}
.login-card input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.login-card .btn { width: 100%; min-height: 48px; }
.login-error { color: var(--danger); font-weight: 600; margin-bottom: 12px; }
