:root {
  --bg: #f6f2ea;          /* creme quente */
  --panel: #ffffff;
  --ink: #232324;         /* grafite MoneyMentors */
  --ink-soft: #3a3a3c;
  --amber: #e2a00e;       /* âmbar MoneyMentors */
  --amber-dark: #c2870a;
  --muted: #857f74;
  --line: #e7e0d3;
  --code-bg: var(--code-bg);
  --shadow: rgba(35,35,36,.10);
  --radius: 18px;
  font-size: 16px;
}

[data-theme="dark"] {
  --bg: #1a1a1c;          /* fundo escuro quente */
  --panel: #232324;       /* grafite MoneyMentors */
  --ink: #ece7db;         /* texto claro */
  --ink-soft: #c7c2b6;
  --amber: #e2a00e;
  --amber-dark: #f0b429;
  --muted: #918b7f;
  --line: #34343a;
  --code-bg: #2c2c30;
  --shadow: rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand-left { display: flex; align-items: center; gap: 14px; }
.brand-left img.logo { height: 38px; width: auto; display: block; }
/* Troca de logo por tema (sem flash, só CSS) */
.logo-dark, .wlogo-dark { display: none !important; }
[data-theme="dark"] .logo-light, [data-theme="dark"] .wlogo-light { display: none !important; }
[data-theme="dark"] .logo-dark { display: block !important; }
[data-theme="dark"] .wlogo-dark { display: inline-block !important; }
.brand-sep { width: 1px; height: 30px; background: var(--line); }
.brand-name { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name .n { font-weight: 700; font-size: 1.05rem; letter-spacing: .2px; }
.brand-name .r { font-size: .72rem; color: var(--muted); font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.logout {
  background: transparent; color: var(--ink-soft); border: 1px solid var(--line);
  padding: 7px 16px; border-radius: 999px; cursor: pointer; font: inherit; font-size: .85rem;
  transition: all .15s;
}
.logout:hover { border-color: var(--amber); color: var(--amber-dark); }
.theme-toggle {
  width: 36px; height: 36px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 1rem;
  display: grid; place-items: center; transition: all .15s; line-height: 1;
}
.theme-toggle:hover { border-color: var(--amber); color: var(--amber-dark); }

/* Chat area */
.chat {
  flex: 1; overflow-y: auto; padding: 34px 0;
  display: flex; flex-direction: column; align-items: center;
}
.welcome { text-align: center; margin: auto 0; color: var(--muted); max-width: 520px; padding: 0 24px; }
.welcome .wlogo { height: 64px; margin-bottom: 20px; opacity: .95; }
.welcome h1 { color: var(--ink); font-weight: 700; font-size: 1.7rem; margin: 0 0 8px; }
.welcome p { margin: 0; }

.msg {
  width: 100%; max-width: 780px; padding: 0 24px; margin: 0 auto 24px;
  display: flex; gap: 14px;
}
.msg .avatar {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; font-size: .78rem; font-weight: 700;
}
.msg.user .avatar { background: var(--ink); color: #f6f2ea; }
.msg.assistant .avatar { background: var(--amber); color: var(--ink); }
.msg .body { padding-top: 4px; color: var(--ink); min-width: 0; word-wrap: break-word; overflow-wrap: anywhere; }

/* Markdown dentro da resposta */
.body p { margin: 0 0 12px; }
.body p:last-child { margin-bottom: 0; }
.body strong { font-weight: 700; }
.body em { font-style: italic; }
.body ul, .body ol { margin: 8px 0 14px; padding-left: 22px; }
.body li { margin: 4px 0; }
.body h1, .body h2, .body h3 { margin: 16px 0 8px; line-height: 1.3; font-weight: 700; }
.body h1 { font-size: 1.3rem; } .body h2 { font-size: 1.15rem; } .body h3 { font-size: 1.02rem; }
.body code { background: var(--code-bg); padding: 1px 6px; border-radius: 6px; font-size: .9em; font-family: ui-monospace, Menlo, monospace; }
.body pre { background: var(--code-bg); padding: 12px 14px; border-radius: 10px; overflow-x: auto; margin: 0 0 12px; }
.body pre code { background: none; padding: 0; }
.body blockquote { border-left: 3px solid var(--amber); margin: 0 0 12px; padding: 2px 0 2px 14px; color: var(--ink-soft); }
.body a { color: var(--amber-dark); }

/* Composer */
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 16px; }
#form {
  max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 10px 10px 10px 18px;
  transition: border-color .15s;
}
#form:focus-within { border-color: var(--amber); }
#input {
  flex: 1; background: transparent; border: none; color: var(--ink);
  resize: none; font: inherit; max-height: 200px; outline: none;
}
#input::placeholder { color: var(--muted); }
#send {
  width: 40px; height: 40px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--amber); color: var(--ink); font-size: 1.2rem; font-weight: 700; flex-shrink: 0;
  transition: background .15s;
}
#send:hover { background: var(--amber-dark); color: #fff; }
#send:disabled { opacity: .4; cursor: default; }

.footer-note {
  text-align: center; color: var(--muted); font-size: .72rem; margin: 10px 0 0;
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
}
.footer-note .hey { font-weight: 700; color: var(--ink-soft); letter-spacing: .2px; }

/* Botões pill / clip */
.pill-btn {
  background: transparent; color: var(--ink-soft); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-size: .85rem;
  transition: all .15s;
}
.pill-btn:hover { border-color: var(--amber); color: var(--amber-dark); }
.clip-btn {
  width: 40px; height: 40px; border-radius: 12px; border: none; cursor: pointer;
  background: transparent; color: var(--muted); font-size: 1.15rem; flex-shrink: 0;
}
.clip-btn:hover { color: var(--amber-dark); }

/* Chip de anexo acima do input */
.attach-chip {
  max-width: 780px; margin: 0 auto 8px; display: flex; align-items: center; gap: 8px;
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 10px; font-size: .82rem; color: var(--ink-soft); width: fit-content;
}
.attach-chip button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: .9rem; }
.attach-chip button:hover { color: #c0392b; }

/* Gaveta de materiais */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 380px; max-width: 90vw; z-index: 50;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px -20px var(--shadow); display: flex; flex-direction: column;
  transform: translateX(0); transition: transform .22s ease;
}
.drawer.hidden { transform: translateX(105%); display: flex; }
.drawer-overlay.hidden { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 12px; }
.drawer-head h2 { margin: 0; font-size: 1.15rem; }
.drawer-close { background: none; border: none; font-size: 1.1rem; color: var(--muted); cursor: pointer; }
.drawer-close:hover { color: var(--ink); }
.quota { padding: 0 22px 8px; }
.quota-bar { height: 8px; background: var(--code-bg); border-radius: 999px; overflow: hidden; }
.quota-fill { height: 100%; width: 0%; background: var(--amber); transition: width .3s, background .3s; }
.quota-fill.warn { background: #e67e22; }
.quota-fill.full { background: #c0392b; }
.quota-text { font-size: .74rem; color: var(--muted); margin-top: 6px; }
.upload-btn {
  margin: 10px 22px 14px; padding: 11px; border: 1.5px dashed var(--line); background: transparent;
  color: var(--amber-dark); border-radius: 12px; cursor: pointer; font: inherit; font-weight: 600;
}
.upload-btn:hover { border-color: var(--amber); background: var(--code-bg); }
.upload-btn:disabled { opacity: .5; cursor: default; }
.mat-list { flex: 1; overflow-y: auto; padding: 0 22px 22px; display: flex; flex-direction: column; gap: 8px; }
.mat-empty { color: var(--muted); font-size: .85rem; text-align: center; margin-top: 24px; }
.mat-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px;
}
.mat-icon { font-size: 1.2rem; flex-shrink: 0; cursor: pointer; }
.mat-meta { flex: 1; min-width: 0; cursor: pointer; }
.mat-meta:hover .mat-name { color: var(--amber-dark); }
.mat-name { font-size: .86rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mat-sub { font-size: .72rem; color: var(--muted); }
.mat-src { display: inline-block; font-size: .64rem; padding: 1px 6px; border-radius: 999px; background: var(--code-bg); margin-left: 6px; }
.mat-actions { display: flex; gap: 6px; flex-shrink: 0; }
.mat-actions button { background: none; border: none; cursor: pointer; font-size: .95rem; color: var(--muted); }
.mat-actions button:hover { color: var(--amber-dark); }
.mat-actions button.del:hover { color: #c0392b; }

/* Esconde utilitários (input de ficheiro sempre oculto; chip quando vazio). */
input#fileInput { display: none; }
.attach-chip.hidden { display: none; }

/* ===== Calendário ===== */
.cal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 60; display: grid; place-items: center; padding: 20px; }
.cal-overlay.hidden { display: none; }
.cal-modal { width: 96vw; max-width: 1040px; height: 88vh; background: var(--panel); border-radius: 20px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 30px 70px -30px var(--shadow); }
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.cal-head h2 { margin: 0; font-size: 1.15rem; }
.cal-actions { display: flex; align-items: center; gap: 8px; }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); padding: 8px 16px 0; gap: 6px; }
.cal-weekdays span { font-size: .72rem; color: var(--muted); font-weight: 600; text-align: center; }
.cal-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; padding: 8px 16px 16px; }
.cal-day { min-height: 96px; border: 1px solid var(--line); border-radius: 10px; padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; transition: border-color .12s; }
.cal-day:hover { border-color: var(--amber); }
.cal-day.other { opacity: .4; }
.cal-day .dnum { font-size: .72rem; color: var(--muted); font-weight: 600; }
.cal-day.today .dnum { color: var(--amber-dark); }
.cal-chip { font-size: .68rem; padding: 3px 6px; border-radius: 6px; border-left: 3px solid var(--muted); background: var(--code-bg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-a-fazer { border-left-color: #9aa0a6; }
.st-fazendo { border-left-color: #3b82f6; }
.st-producao { border-left-color: #e2a00e; }
.st-aprovacao { border-left-color: #8b5cf6; }
.st-aprovado { border-left-color: #22a06b; }
.st-publicado { border-left-color: #0d9488; }

/* Editor de entrada */
.entry-modal { width: 96vw; max-width: 480px; max-height: 90vh; overflow-y: auto; background: var(--panel); border-radius: 20px; box-shadow: 0 30px 70px -30px var(--shadow); }
.entry-modal label { display: block; font-size: .78rem; color: var(--muted); font-weight: 600; margin: 14px 22px 5px; }
.entry-modal input, .entry-modal select, .entry-modal textarea {
  width: calc(100% - 44px); margin: 0 22px; padding: 10px 12px; background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 10px; color: var(--ink); font: inherit;
}
.entry-modal textarea { resize: vertical; }
.entry-modal input:focus, .entry-modal select:focus, .entry-modal textarea:focus { outline: none; border-color: var(--amber); }
.entry-buttons { display: flex; justify-content: space-between; padding: 18px 22px 22px; }
.save-btn { background: var(--amber); color: var(--ink); border: none; padding: 10px 22px; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer; }
.save-btn:hover { background: var(--amber-dark); color: #fff; }
.del-btn { background: transparent; color: #c0392b; border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px; font: inherit; cursor: pointer; }
.del-btn:hover { border-color: #c0392b; }

/* Cartão de proposta da Emily no chat */
.agenda-card { border: 1px solid var(--line); border-left: 3px solid var(--amber); border-radius: 12px; padding: 12px 14px; margin: 10px 0; background: var(--code-bg); }
.agenda-card .ac-top { font-size: .72rem; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.agenda-card .ac-tema { font-weight: 600; font-size: .95rem; }
.agenda-card .ac-meta { font-size: .76rem; color: var(--muted); margin: 2px 0 8px; }
.agenda-card button { background: var(--amber); color: var(--ink); border: none; padding: 7px 14px; border-radius: 8px; font: inherit; font-size: .82rem; font-weight: 700; cursor: pointer; }
.agenda-card button:hover { background: var(--amber-dark); color: #fff; }
.agenda-card button.added { background: #22a06b; color: #fff; cursor: default; }

.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--amber); }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

@media (max-width: 640px) {
  .msg, #form { padding-left: 16px; padding-right: 16px; }
  .brand-name .r { display: none; }
}
