/* ============================================================
   Joanna — assistente de agenda
   Visual "Siri": fundo azul profundo, orbe e elementos coloridos.
   Tema claro/escuro, responsivo para mobile/tablet.
   ============================================================ */

/* ---------- Tokens: tema claro ---------- */
:root {
  --bg: #eef4fb;
  --aura-1: rgba(0, 160, 255, .16);
  --aura-2: rgba(236, 64, 160, .12);
  --aura-3: rgba(52, 211, 153, .10);
  --glow-1: rgba(56, 132, 255, .32);
  --glow-2: rgba(236, 64, 160, .24);

  --glass: rgba(255, 255, 255, .72);
  --glass-2: rgba(255, 255, 255, .55);
  --surface-2: #e4eef9;
  --surface-3: #d8e6f5;
  --border: rgba(70, 120, 180, .18);
  --border-strong: rgba(70, 120, 180, .32);

  --text: #0e2136;
  --text-muted: #51677f;
  --text-faint: #8ba0b8;

  --accent: #0ea5e9;
  --accent-hover: #0284c7;
  --accent-soft: #e0f2fe;
  --accent-text: #0369a1;
  --accent-grad: linear-gradient(120deg, #06b6d4, #3b82f6 38%, #8b5cf6 68%, #ec4899);
  --on-accent: #ffffff;

  --danger: #e0455f;
  --danger-soft: #fce7ec;
  --danger-text: #a5304a;

  --top-highlight: rgba(255, 255, 255, .7);
  --shadow-sm: 0 1px 2px rgba(15, 35, 60, .06);
  --shadow-md: 0 10px 34px rgba(20, 50, 90, .12);
  --shadow-lg: 0 28px 70px rgba(15, 40, 80, .22);
  --ring: 0 0 0 3px rgba(14, 165, 233, .24);

  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;
  --r-xl: 24px;
  --r-pill: 999px;

  --topbar-h: 62px;
  --blur: blur(20px) saturate(150%);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --font-display: "Space Grotesk", var(--font);
  --font-mono: "DM Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- Tokens: tema escuro ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #061320;
    --aura-1: rgba(38, 150, 255, .30);
    --aura-2: rgba(236, 64, 160, .22);
    --aura-3: rgba(45, 212, 191, .16);
    --glow-1: rgba(56, 140, 255, .55);
    --glow-2: rgba(236, 64, 160, .42);

    --glass: rgba(13, 30, 49, .58);
    --glass-2: rgba(16, 35, 56, .44);
    --surface-2: rgba(24, 47, 74, .55);
    --surface-3: rgba(31, 58, 90, .5);
    --border: rgba(120, 180, 240, .16);
    --border-strong: rgba(120, 180, 240, .3);

    --text: #eef6ff;
    --text-muted: #9fb6d0;
    --text-faint: #647f9c;

    --accent: #38bdf8;
    --accent-hover: #5fcdfb;
    --accent-soft: rgba(56, 189, 248, .16);
    --accent-text: #9ad8fb;
    --accent-grad: linear-gradient(120deg, #22d3ee, #3b82f6 38%, #a855f7 66%, #ec4899);
    --on-accent: #041525;

    --danger: #ff7a92;
    --danger-soft: rgba(255, 122, 146, .16);
    --danger-text: #ffa8b8;

    --top-highlight: rgba(190, 224, 255, .08);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 14px 40px rgba(0, 0, 0, .5);
    --shadow-lg: 0 30px 74px rgba(0, 0, 0, .62);
    --ring: 0 0 0 3px rgba(56, 189, 248, .32);
  }
}

:root[data-theme="dark"] {
  --bg: #061320;
  --aura-1: rgba(38, 150, 255, .30);
  --aura-2: rgba(236, 64, 160, .22);
  --aura-3: rgba(45, 212, 191, .16);
  --glow-1: rgba(56, 140, 255, .55);
  --glow-2: rgba(236, 64, 160, .42);
  --glass: rgba(13, 30, 49, .58);
  --glass-2: rgba(16, 35, 56, .44);
  --surface-2: rgba(24, 47, 74, .55);
  --surface-3: rgba(31, 58, 90, .5);
  --border: rgba(120, 180, 240, .16);
  --border-strong: rgba(120, 180, 240, .3);
  --text: #eef6ff;
  --text-muted: #9fb6d0;
  --text-faint: #647f9c;
  --accent: #38bdf8;
  --accent-hover: #5fcdfb;
  --accent-soft: rgba(56, 189, 248, .16);
  --accent-text: #9ad8fb;
  --accent-grad: linear-gradient(120deg, #22d3ee, #3b82f6 38%, #a855f7 66%, #ec4899);
  --on-accent: #041525;
  --danger: #ff7a92;
  --danger-soft: rgba(255, 122, 146, .16);
  --danger-text: #ffa8b8;
  --top-highlight: rgba(190, 224, 255, .08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 14px 40px rgba(0, 0, 0, .5);
  --shadow-lg: 0 30px 74px rgba(0, 0, 0, .62);
  --ring: 0 0 0 3px rgba(56, 189, 248, .32);
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
/* fundo azul com clarão central + auras coloridas (pegada Siri) */
body::before {
  content: "";
  position: fixed;
  inset: -10% -10% 0;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(60vw 50vw at 50% 34%, var(--aura-1), transparent 66%),
    radial-gradient(42vw 40vw at 8% 4%, var(--aura-3), transparent 60%),
    radial-gradient(48vw 44vw at 94% 92%, var(--aura-2), transparent 58%),
    radial-gradient(40vw 38vw at 88% 12%, rgba(245, 158, 11, .10), transparent 60%);
}
/* granulado sutil por cima */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.035'/%3E%3C/svg%3E");
}

h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.025em; line-height: 1.14; font-weight: 600; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 clamp(16px, 4vw, 32px);
  background: var(--glass);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark {
  width: 34px; height: 34px; flex: none;
  display: block;
  border-radius: 50%;
  overflow: hidden;
  background: var(--accent-grad);
  box-shadow: 0 6px 18px -5px var(--glow-1);
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 18px; letter-spacing: -.02em; }

.main-nav {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--glass-2);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
}
.main-nav a {
  padding: 6px 16px;
  border-radius: var(--r-pill);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 550;
  transition: color .15s, background .15s;
}
.main-nav a:hover { color: var(--text); }
.main-nav a.active { background: var(--accent-grad); color: #fff; box-shadow: 0 4px 14px -4px var(--glow-1); }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.conn { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 11.5px; letter-spacing: .04em; color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 10px #34d399; flex: none; }
.status-dot.off { background: var(--text-faint); box-shadow: none; }
.connect-inline {
  padding: 6px 13px;
  border-radius: var(--r-pill);
  background: var(--accent-grad);
  color: #fff;
  font-size: 12.5px;
  font-weight: 650;
  text-decoration: none;
  box-shadow: 0 4px 14px -4px var(--glow-1);
}
.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--glass-2);
  color: var(--text-muted);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: block; }

/* ---------- Layout ---------- */
main {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(22px, 4vw, 44px) clamp(16px, 4vw, 32px) 64px;
}
body:has(#view-conversa:not([hidden])) main { max-width: 820px; }

footer {
  padding: 20px;
  text-align: center;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
}

/* painéis de vidro */
.chat-shell, .filters, .calendar-panel, .modal-card {
  background: var(--glass);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md), inset 0 1px 0 var(--top-highlight);
}

/* ---------- Botões ---------- */
.primary-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px;
  border-radius: var(--r-pill);
  background: var(--accent-grad);
  color: #fff;
  font-weight: 650;
  font-size: 13.5px;
  box-shadow: 0 8px 22px -8px var(--glow-1);
  transition: filter .15s, transform .05s, box-shadow .15s;
}
.primary-button:hover { filter: brightness(1.08); box-shadow: 0 10px 26px -6px var(--glow-1); }
.primary-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: .55; cursor: wait; }
.ghost-button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 15px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-strong);
  background: var(--glass-2);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 550;
}
.ghost-button:hover { border-color: var(--accent); color: var(--accent-text); }
.danger-button {
  padding: 9px 15px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  background: var(--danger-soft);
  color: var(--danger-text);
  font-size: 13.5px;
  font-weight: 600;
}
.danger-button:hover { filter: brightness(1.05); }
.link-button { color: var(--accent-text); font-family: var(--font-mono); font-size: 11.5px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; }
.link-button:hover { text-decoration: underline; }

/* ---------- Conversa ---------- */
.chat-shell {
  border-radius: var(--r-xl);
  padding: clamp(18px, 3vw, 32px);
  display: flex;
  flex-direction: column;
}
.chat-welcome { text-align: center; padding: 16px 6px 20px; position: relative; }
.chat-welcome > *:not(.siri-wave) { position: relative; z-index: 1; }
.siri-wave {
  position: absolute;
  left: -6%;
  width: 112%;
  top: 40px;
  height: 130px;
  z-index: 0;
  pointer-events: none;
  opacity: .65;
  filter: drop-shadow(0 0 14px rgba(56, 140, 255, .35));
}

/* orbe da Joanna (pegada Siri: anel branco, swirl multicolor) */
.joanna-avatar {
  display: block;
  width: 96px; height: 96px;
  margin: 0 auto 16px;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 42% 38%, #ffffff 0%, #86dbff 16%, #3b82f6 42%, #7c3aed 68%, #0b1b3a 100%);
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, .55),
    0 0 72px -8px var(--glow-1),
    0 0 32px -6px var(--glow-2),
    inset 0 0 26px rgba(255, 255, 255, .28);
  animation: orb-breathe 6s ease-in-out infinite;
}
.joanna-avatar::before {
  content: "";
  position: absolute;
  inset: -35%;
  background: conic-gradient(from 0deg, #22d3ee, #3b82f6, #a855f7, #ec4899, #f59e0b, #34d399, #22d3ee);
  opacity: .45;
  mix-blend-mode: screen;
  animation: orb-spin 9s linear infinite;
}
.joanna-avatar::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 34%, rgba(255, 255, 255, .75), transparent 40%);
}
.joanna-avatar img { display: none; }
.joanna-avatar.has-img img { display: block; position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; object-fit: cover; object-position: center 22%; }
.joanna-avatar.has-img::before, .joanna-avatar.has-img::after { display: none; }
@keyframes orb-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }
@keyframes orb-spin { to { transform: rotate(360deg); } }

.chat-welcome .eyebrow { margin-bottom: 14px; }
.chat-welcome h1 { font-size: clamp(23px, 3.7vw, 30px); font-weight: 700; }
.chat-welcome h1 strong {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.chat-welcome > p { color: var(--text-muted); max-width: 46ch; margin: 10px auto 0; font-size: 14.5px; }

.chat-suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.chat-suggestions button {
  padding: 8px 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--glass-2);
  color: var(--text-muted);
  font-size: 12.5px;
  transition: color .15s, border-color .15s;
}
.chat-suggestions button:hover { color: var(--text); border-color: var(--accent); }

#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: min(52vh, 460px);
  padding: 4px 2px;
  scrollbar-width: thin;
}
#messages:empty { display: none; }
.user, .assistant {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
}
.user .msg-text, .assistant .msg-text {
  margin: 0;
  white-space: pre-wrap;
}
.user {
  align-self: flex-end;
  background: var(--accent-grad);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 8px 22px -10px var(--glow-1);
}
.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 5px;
}
.voice-pending .msg-text { opacity: .7; font-style: italic; }
.replay-btn {
  margin-top: 8px;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--glass-2);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.replay-btn:hover { border-color: var(--accent); }

/* Joanna "digitando…" */
.assistant.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 14px 15px;
}
.assistant.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: joanna-typing 1.2s infinite ease-in-out;
}
.assistant.typing span:nth-child(2) { animation-delay: .16s; }
.assistant.typing span:nth-child(3) { animation-delay: .32s; }
@keyframes joanna-typing {
  0%, 65%, 100% { opacity: .3; transform: translateY(0); }
  32% { opacity: 1; transform: translateY(-3px); }
}

#chat-form {
  position: relative;
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
#chat-form input {
  flex: 1;
  min-width: 0;
  padding: 12px 15px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-strong);
  background: var(--glass-2);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#chat-form input:focus { border-color: var(--accent); box-shadow: var(--ring); }
#chat-form button[type="submit"] {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 8px 20px -8px var(--glow-1);
}
#chat-form button[type="submit"]:hover { filter: brightness(1.08); }
#chat-form button[type="submit"] svg { width: 18px; height: 18px; }
#chat-form input:disabled { opacity: .55; }
.input-hint { text-align: center; color: var(--text-faint); font-size: 11px; margin-top: 10px; }

/* ---------- Botão de microfone (estilo WhatsApp) ---------- */
.mic-btn {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--glass-2);
  color: var(--text);
  transition: transform .12s, background .12s, color .12s;
  touch-action: none;
}
.mic-btn svg { width: 19px; height: 19px; }
.mic-btn:hover { border-color: var(--accent); }
.mic-btn:disabled { opacity: .45; }
#chat-form[data-mode="voice"] #send-btn { display: none; }
#chat-form[data-mode="text"] #mic-btn { display: none; }

#chat-form.recording .mic-btn {
  background: var(--accent-grad);
  color: #fff;
  transform: scale(1.12);
  animation: mic-pulse 1.3s infinite ease-in-out;
}
#chat-form.will-cancel .mic-btn {
  background: #ef4444;
  animation: none;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--glow-1); }
  50% { box-shadow: 0 0 0 10px transparent; }
}

.rec-overlay {
  position: absolute;
  inset: 16px 60px 0 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-radius: var(--r-pill);
  background: var(--glass-2);
  border: 1px solid var(--border-strong);
  font-size: 13px;
  color: var(--text-faint);
}
.rec-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #ef4444;
  animation: rec-blink 1s infinite steps(1);
}
.rec-time { font-variant-numeric: tabular-nums; color: var(--text); }
.rec-hint { margin-left: auto; }
#chat-form.will-cancel .rec-hint { color: #ef4444; font-weight: 600; }
@keyframes rec-blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: .2; } }

@media (prefers-reduced-motion: reduce) {
  #chat-form.recording .mic-btn { animation: none; }
  .rec-dot { animation: none; }
}

/* ---------- Agenda: cabeçalho ---------- */
.agenda-topline {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.agenda-topline h1 { font-size: clamp(22px, 4vw, 30px); font-weight: 700; }
.agenda-subtitle { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }
.agenda-topline-actions { display: flex; gap: 8px; }
.filters-toggle { display: none; }

/* ---------- Agenda: layout ---------- */
.agenda-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 18px;
  align-items: start;
}
.agenda-layout > * { min-width: 0; }

.filters {
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  border-radius: var(--r-lg);
}
.filters-head { display: flex; align-items: center; justify-content: space-between; }
.filters-title { font-family: var(--font-mono); font-size: 11px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; color: var(--text-faint); }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field > span, .field legend { font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 0; }
.field input, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--glass-2);
  outline: none;
  font-size: 13.5px;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: var(--ring); }
.field .row { display: flex; align-items: center; gap: 8px; color: var(--text-faint); }
.field .row input { flex: 1; min-width: 0; }
.field small { color: var(--text-faint); font-size: 11.5px; line-height: 1.4; }
.checks { gap: 10px; }
.checks label { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--text); cursor: pointer; }
.checks input { width: 16px; height: 16px; flex: none; accent-color: var(--accent); }
.filter-count { font-family: var(--font-mono); font-size: 11px; letter-spacing: .04em; color: var(--accent-text); margin: 0; }

/* ---------- Agenda: painel do calendário ---------- */
.calendar-panel {
  border-radius: var(--r-lg);
  padding: 16px;
  min-height: 480px;
}
.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.nav-group { display: flex; gap: 6px; }
.nav-group button {
  min-width: 34px;
  padding: 7px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--glass-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
}
.nav-group button:hover { border-color: var(--border-strong); color: var(--accent-text); }
.period-label { flex: 1; text-align: center; min-width: 150px; font-family: var(--font-display); font-size: 16px; font-weight: 600; }
.view-switch {
  display: flex;
  padding: 3px;
  gap: 2px;
  background: var(--glass-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
}
.view-switch button {
  padding: 6px 14px;
  border-radius: var(--r-pill);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 550;
}
.view-switch button.active { background: var(--accent-grad); color: #fff; }

.calendar-status {
  padding: 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  margin-bottom: 12px;
}
.calendar-grid { overflow-x: auto; }

/* --- mês --- */
.month-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.month-head span { text-align: center; font-family: var(--font-mono); font-size: 10px; font-weight: 500; color: var(--text-faint); text-transform: uppercase; letter-spacing: .1em; }
.month-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(92px, 1fr);
  gap: 6px;
}
.day-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--glass-2);
  cursor: pointer;
  overflow: hidden;
  transition: border-color .12s, background .12s;
}
.day-cell:hover { border-color: var(--accent); }
.day-cell.outside { opacity: .4; }
.day-cell.today { border-color: var(--accent); background: var(--accent-soft); }
.day-num { align-self: flex-start; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.day-cell.today .day-num { color: var(--accent-text); }
.day-cell .more { font-family: var(--font-mono); font-size: 10px; color: var(--accent-text); text-align: left; }

.chip {
  display: flex;
  gap: 5px;
  align-items: baseline;
  width: 100%;
  padding: 3px 7px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 550;
  text-align: left;
  overflow: hidden;
}
.chip .chip-time { flex: none; opacity: .75; font-variant-numeric: tabular-nums; }
.chip .chip-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.all-day { background: var(--surface-3); color: var(--text-muted); }
.chip.dim { opacity: .36; }

/* --- semana / dia --- */
.time-grid {
  --col: minmax(0, 1fr);
  display: grid;
  grid-template-columns: 52px repeat(var(--days), var(--col));
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.tg-corner { background: var(--glass-2); border-bottom: 1px solid var(--border); }
.tg-dayhead {
  display: flex; flex-direction: column; gap: 1px;
  padding: 7px 4px;
  text-align: center;
  background: var(--glass-2);
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.tg-dayhead span { font-family: var(--font-mono); font-size: 9.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .08em; }
.tg-dayhead strong { font-family: var(--font-display); font-size: 15px; font-weight: 600; }
.tg-dayhead.today strong { color: var(--accent-text); }
.tg-allday-label {
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 3px;
  font-family: var(--font-mono); font-size: 8.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em;
  background: var(--glass-2);
  border-bottom: 1px solid var(--border);
}
.tg-allday {
  min-height: 26px;
  padding: 3px;
  display: flex; flex-direction: column; gap: 3px;
  background: var(--glass-2);
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.tg-scroll {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 52px repeat(var(--days), var(--col));
  max-height: 560px;
  overflow-y: auto;
  position: relative;
  scrollbar-width: thin;
}
.tg-hours { display: flex; flex-direction: column; }
.tg-hour {
  height: 48px;
  padding-right: 6px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-faint);
  transform: translateY(-6px);
}
.tg-col { position: relative; border-left: 1px solid var(--border); }
.tg-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); opacity: .5; }
.event-box {
  position: absolute;
  left: 3px; right: 3px;
  display: flex; flex-direction: column; gap: 1px;
  padding: 3px 7px;
  border-radius: 7px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 600;
  text-align: left;
  overflow: hidden;
}
.event-box span { font-weight: 500; opacity: .8; font-variant-numeric: tabular-nums; }
.event-box.dim { opacity: .34; }

/* --- lista (intervalo) --- */
.agenda-list { display: flex; flex-direction: column; gap: 18px; }
.agenda-day-label { font-family: var(--font-display); font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.agenda-row {
  display: flex;
  gap: 14px;
  width: 100%;
  align-items: baseline;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--glass-2);
  text-align: left;
  color: var(--text);
  transition: border-color .12s;
}
.agenda-row:hover { border-color: var(--accent); }
.agenda-time { flex: none; min-width: 68px; font-family: var(--font-mono); font-size: 12px; color: var(--accent-text); font-variant-numeric: tabular-nums; }
.agenda-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.agenda-info strong { font-weight: 600; }
.agenda-info em { font-style: normal; font-size: 11.5px; color: var(--text-muted); }
.agenda-row.dim { opacity: .42; }
.empty-list { text-align: center; color: var(--text-muted); font-size: 13px; padding: 28px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 4, 20, .55); backdrop-filter: blur(4px); }
.modal-card {
  position: relative;
  width: min(96vw, 460px);
  max-height: 90dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg), inset 0 1px 0 var(--top-highlight);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-card .field > span { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.modal-card .row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-error { color: var(--danger-text); font-size: 12.5px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.modal-actions .spacer { flex: 1; }

/* ---------- Nav inferior (mobile) ---------- */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  background: var(--glass);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.mobile-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 8px;
  text-decoration: none;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 550;
}
.mobile-nav a svg { width: 21px; height: 21px; }
.mobile-nav a.active { color: var(--accent-text); }

/* ============================================================
   Responsivo
   ============================================================ */
@media (max-width: 1024px) {
  .agenda-layout { grid-template-columns: 1fr; }
  .filters { position: static; display: none; }
  .filters.filters--open { display: flex; }
  .filters-toggle { display: inline-flex; }
}

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  main { padding: 18px 14px calc(76px + env(safe-area-inset-bottom)); }

  .main-nav { display: none; }
  .mobile-nav { display: flex; }

  .topbar { gap: 8px; padding: 0 14px; }
  .conn-label { display: none; }
  .brand-name { font-size: 16px; }

  .chat-shell { border-radius: var(--r-lg); padding: 16px; }
  #messages { max-height: 58vh; }
  .user, .assistant { max-width: 88%; }
  .chat-welcome { padding: 10px 4px 14px; }
  .joanna-avatar { width: 76px; height: 76px; }

  .agenda-topline { margin-bottom: 14px; }
  .agenda-topline > div:first-child { flex: 1; }
  .agenda-subtitle { display: none; }

  .calendar-panel { padding: 12px; border-radius: var(--r-md); }
  .calendar-toolbar { gap: 8px; }
  .period-label { order: 3; flex-basis: 100%; text-align: left; font-size: 15px; }
  .nav-group { order: 1; }
  .view-switch { order: 2; }

  .month-body { grid-auto-rows: minmax(62px, 1fr); gap: 4px; }
  .day-cell { padding: 4px; border-radius: 7px; }
  .chip { font-size: 10px; padding: 2px 6px; }
  .chip .chip-time { display: none; }

  .time-grid { --col: 104px; width: max-content; min-width: 100%; }
  .time-grid--day { --col: minmax(0, 1fr); width: auto; }
  .tg-scroll { max-height: 60vh; }

  .modal { padding: 0; align-items: flex-end; }
  .modal-card {
    width: 100%;
    max-width: none;
    max-height: 92dvh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  }
  .modal-card .row.two { grid-template-columns: 1fr; }

  footer { padding-bottom: calc(20px + 64px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .joanna-avatar, .joanna-avatar::before { animation: none; }
  .assistant.typing span { animation: none; opacity: .55; }
}
