/* Asistente Mario — hoja única. Tokens según DESIGN.md (marca del ecosistema MB). */
:root {
  --ink: #0B1622;
  --ink-2: #24384d;
  --muted: #5b6b7c;
  --paper: #FBF9F4;
  --paper-2: #F3EFE4;
  --line: #e4ddcc;
  --gold: #C19A49;
  --gold-deep: #8f6f2e;
  --rust: #A8542F;
  --sage: #4F6F5C;
  --white: #ffffff;
  --font-ui: -apple-system, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  --font-brand: "New York", "Iowan Old Style", Georgia, serif;
  --radius-bubble: 18px;
  --z-drawer-backdrop: 40;
  --z-drawer: 50;
  --z-toast: 70;
  --sab: env(safe-area-inset-bottom, 0px);
  --sat: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { height: 100%; }
body {
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--gold); outline-offset: 2px;
}

/* ── Estructura ── */
.app {
  display: flex; height: 100%; height: 100dvh;
}
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* App bar */
.appbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--sat)) 12px 8px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.appbar .iconbtn {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; font-size: 21px; color: var(--ink-2);
}
.appbar .iconbtn:active { background: var(--paper-2); }
.appbar-title { flex: 1; min-width: 0; }
.appbar-title .t {
  font-family: var(--font-brand); font-weight: 700; font-size: 18px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.status.on .dot { background: var(--sage); }
.status.proc .dot { background: var(--gold); animation: pulse 1.2s ease-out infinite; }
.status.off .dot { background: var(--rust); }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: .35; } 100% { opacity: 1; } }

/* ── Hilo ── */
.thread {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 18px 14px 8px;
  overscroll-behavior: contain;
}
.thread-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 4px; }

.row { display: flex; margin: 3px 0; }
.row.me { justify-content: flex-end; }
.bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: var(--radius-bubble);
  word-wrap: break-word; overflow-wrap: break-word;
  user-select: text; -webkit-user-select: text;
  animation: rise .2s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.row.me .bubble {
  background: var(--ink); color: var(--paper);
  border-bottom-right-radius: 6px;
}
.row.ai .bubble {
  background: var(--paper-2); border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.row.ai.err .bubble { border-color: var(--rust); color: var(--rust); background: #faf1ec; }

/* Markdown dentro de burbujas */
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 17px; margin: 10px 0 6px; line-height: 1.3; }
.bubble a { color: var(--gold-deep); text-decoration: underline; }
.row.me .bubble a { color: var(--gold); }
.bubble code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px;
  background: rgba(11, 22, 34, .07); padding: 1px 5px; border-radius: 5px;
}
.bubble pre { background: var(--ink); color: var(--paper); padding: 10px 12px; border-radius: 10px; overflow-x: auto; margin: 6px 0; }
.bubble pre code { background: none; color: inherit; padding: 0; }
.bubble table { border-collapse: collapse; margin: 6px 0; font-size: 14px; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.bubble blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--ink-2); margin: 6px 0; }

/* Copiar */
.copyrow { display: flex; margin: -2px 0 4px 4px; }
.copybtn {
  font-size: 13px; color: var(--muted); padding: 5px 10px; border-radius: 8px;
  min-height: 32px;
}
.copybtn:active { background: var(--paper-2); }
.copybtn.done { color: var(--sage); }

/* Chips de herramienta (informativos) */
.toolchip {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13.5px; color: var(--muted);
  background: none; border: 1px dashed var(--line); border-radius: 999px;
  padding: 5px 12px; margin: 2px 0;
}
.toolchip .ok { color: var(--sage); } .toolchip .ok.bad { color: var(--rust); }

/* Imágenes pegadas (pendientes de enviar) */
.attach-strip { display: flex; gap: 8px; padding: 6px 0; flex-wrap: wrap; }
.attach-thumb { position: relative; }
.attach-thumb.file {
  display: flex; align-items: center; gap: 7px;
  height: 44px; padding: 0 12px; max-width: 180px;
  background: var(--white); border: 1.5px solid var(--gold); border-radius: 12px;
  font-size: 12.5px; color: var(--ink);
}
.attach-thumb.file .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-thumb img {
  width: 60px; height: 60px; object-fit: cover; border-radius: 12px;
  border: 1.5px solid var(--gold); display: block;
}
.attach-thumb button {
  position: absolute; top: -7px; right: -7px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--ink); color: var(--paper); font-size: 11px;
  display: grid; place-items: center;
}

/* Imágenes dentro de burbujas */
.bubble .imgs img {
  max-width: min(240px, 100%); max-height: 260px;
  border-radius: 12px; display: block; margin: 2px 0 6px;
}
.bubble .files { display: flex; flex-direction: column; gap: 4px; margin: 2px 0 6px; }
.bubble .files a {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 12px; border-radius: 10px;
  background: rgba(255, 255, 255, .16); color: inherit; text-decoration: none;
  font-size: 13.5px; max-width: 260px;
}
.bubble .files a .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Sugerencias */
.suggest {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 4px 0 2px;
  animation: rise .25s ease-out;
}
.suggest button {
  border: 1.5px solid var(--gold-deep); color: var(--gold-deep);
  border-radius: 999px; padding: 8px 14px; font-size: 14.5px;
  min-height: 40px; text-align: left;
}
.suggest button:active { background: var(--gold); border-color: var(--gold); color: var(--ink); }

/* Typing */
.typing { display: inline-flex; gap: 5px; padding: 12px 16px; align-self: flex-start; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--gold-deep);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }

/* Vacío */
.empty { text-align: center; color: var(--muted); padding: 56px 24px; }
.empty .brand { font-family: var(--font-brand); font-size: 22px; color: var(--ink); margin-bottom: 8px; }
.empty p { max-width: 34ch; margin: 0 auto; font-size: 15px; }

/* ── Composer ── */
.composer-zone { flex-shrink: 0; padding: 8px 12px calc(10px + var(--sab)); background: var(--paper); border-top: 1px solid var(--line); }
.composer-inner { max-width: 760px; margin: 0 auto; }
.composer { display: flex; align-items: flex-end; gap: 8px; }
.composer .input {
  flex: 1; border: 1.5px solid var(--line); border-radius: 22px;
  background: var(--white); color: var(--ink);
  padding: 11px 16px; font: inherit; font-size: 16px; line-height: 1.4;
  max-height: 120px; min-height: 44px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
  -webkit-user-select: text; user-select: text;
}
.composer .input:empty::before { content: attr(data-placeholder); color: #7d8a99; pointer-events: none; }
.composer .input:focus { border-color: var(--gold); outline: none; }
.sendbtn {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: var(--gold); color: var(--ink); font-size: 19px;
  display: grid; place-items: center;
  transition: transform .15s ease-out, background .15s ease-out;
}
.sendbtn:active { transform: scale(.92); }
.sendbtn:disabled { background: var(--line); color: var(--muted); }
.stopbtn {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  border: 1.5px solid var(--rust); color: var(--rust); font-size: 15px;
  display: grid; place-items: center;
}
.attachbtn {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  border: 1.5px solid var(--line); color: var(--muted); font-size: 22px;
  background: var(--white);
  display: grid; place-items: center;
  transition: transform .15s ease-out;
}
.attachbtn:active { transform: scale(.92); }

/* ── Drawer (conversaciones) ── */
.backdrop {
  position: fixed; inset: 0; background: rgba(11, 22, 34, .4);
  opacity: 0; pointer-events: none; transition: opacity .2s ease-out;
  z-index: var(--z-drawer-backdrop);
}
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(320px, 86vw);
  background: var(--paper-2);
  border-right: 1px solid var(--line);
  transform: translateX(-102%); transition: transform .22s ease-out;
  z-index: var(--z-drawer);
  display: flex; flex-direction: column;
  padding-top: var(--sat);
}
body.drawer-open .backdrop { opacity: 1; pointer-events: auto; }
body.drawer-open .drawer { transform: none; }

.drawer-head {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.drawer-head .brand { font-family: var(--font-brand); font-weight: 700; font-size: 20px; }
.drawer-head .who { font-size: 13.5px; color: var(--muted); margin-top: 2px; }
.newconv {
  margin: 12px 16px 6px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--ink); color: var(--paper);
  border-radius: 12px; padding: 12px; font-size: 15.5px; font-weight: 600;
  min-height: 46px;
  transition: opacity .15s ease-out;
}
.newconv:active { opacity: .85; }
.convsearch { margin: 6px 16px; }
.convsearch input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--white); padding: 9px 12px; font: inherit; font-size: 15px;
}
.convlist { flex: 1; overflow-y: auto; padding: 6px 8px calc(8px + var(--sab)); }
.convitem {
  display: block; width: 100%; text-align: left;
  padding: 12px 12px; border-radius: 10px; min-height: 48px;
  border-bottom: 1px solid rgba(228, 221, 204, .6);
}
.convitem:last-child { border-bottom: 0; }
.convitem .t { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convitem .d { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.convitem.active { background: var(--paper); border-bottom-color: transparent; }
.convitem.active .t { font-weight: 600; }
.convitem .snippet { font-size: 13px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.drawer-foot { border-top: 1px solid var(--line); padding: 10px 16px calc(12px + var(--sab)); display: flex; flex-direction: column; gap: 4px; }
.drawer-foot button {
  text-align: left; padding: 10px 4px; font-size: 15px; color: var(--ink-2);
  min-height: 44px; display: flex; align-items: center; gap: 10px;
}
.drawer-foot button.danger { color: var(--rust); }

/* ── Vistas + tab bar ── */
.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.active { display: flex; }
.view-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 14px calc(16px + var(--sab)); }
.view-inner { max-width: 760px; margin: 0 auto; }

.tabbar {
  flex-shrink: 0;
  display: flex; justify-content: space-around;
  background: var(--paper); border-top: 1px solid var(--line);
  padding: 4px 8px calc(6px + var(--sab));
}
.tabbar button {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 11.5px; color: var(--muted);
  padding: 6px 4px; border-radius: 10px; min-height: 48px;
}
.tabbar button .ic { font-size: 20px; line-height: 1.2; }
.tabbar button.active { color: var(--gold-deep); font-weight: 600; }
.tabbar button:active { background: var(--paper-2); }
body.kb-open .tabbar { display: none; } /* con teclado abierto, todo el alto es para el chat */

/* ── Agenda ── */
.ag-group { margin-bottom: 20px; }
.ag-group h2 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 0 0 6px 4px; }
.ag-group.done { opacity: .7; }
.ag-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--white); border: 1px solid var(--line); border-radius: 14px;
  padding: 11px 12px; margin-bottom: 8px;
}
.ag-item.late { border-color: var(--rust); }
.ag-item.done .ag-title { text-decoration: line-through; color: var(--muted); }
.ag-check {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--gold-deep); color: var(--sage);
  display: grid; place-items: center; font-size: 15px; font-weight: 700;
}
.ag-item.done .ag-check { border-color: var(--sage); background: #eef3ef; }
.ag-main { flex: 1; min-width: 0; }
.ag-title { font-size: 15.5px; overflow-wrap: break-word; }
.ag-meta { font-size: 13px; color: var(--muted); margin-top: 1px; }
.ag-item.late .ag-meta { color: var(--rust); }
.ag-del { color: var(--muted); font-size: 15px; padding: 8px; min-width: 40px; min-height: 40px; }
.ag-del:active { color: var(--rust); }

.ag-add {
  background: var(--white); border: 1.5px solid var(--gold); border-radius: 14px;
  padding: 14px; margin-bottom: 16px;
}
.ag-add input[type="text"] {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font: inherit; font-size: 16px;
}
.ag-add-row { display: flex; gap: 8px; margin-top: 10px; }
.ag-add-row select, .ag-add-row input {
  flex: 1; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 9px 10px; font: inherit; font-size: 15px; background: var(--white); min-width: 0;
}
.ag-add-acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.ag-add-acts button { border-radius: 10px; padding: 10px 18px; font-size: 15px; min-height: 42px; }
.ag-add-acts .ag-cancel { color: var(--muted); }
.ag-add-acts .ag-save { background: var(--gold); color: var(--ink); font-weight: 700; }

/* ── Noticias ── */
.nw-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.nw-date { font-family: var(--font-brand); font-size: 17px; font-weight: 700; text-transform: capitalize; }
.nw-refresh {
  border: 1.5px solid var(--gold-deep); color: var(--gold-deep);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; min-height: 40px;
}
.nw-refresh:disabled { border-color: var(--line); color: var(--muted); }
.nw-group { margin-bottom: 22px; }
.nw-group h2 {
  font-family: var(--font-brand); font-size: 18px; margin: 0 0 8px;
  border-bottom: 2px solid var(--gold); display: inline-block; padding-bottom: 2px;
}
.nw-card {
  background: var(--white); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 15px; margin-bottom: 10px;
}
.nw-card h3 { font-size: 15.5px; margin: 0 0 5px; line-height: 1.35; }
.nw-card h3 a { color: var(--ink); text-decoration: none; }
.nw-card h3 a:active { color: var(--gold-deep); }
.nw-card p { font-size: 14.5px; color: var(--ink-2); margin: 0; }
.nw-src { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

/* ── Toast ── */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--sab)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 999px; font-size: 14.5px;
  z-index: var(--z-toast);
  animation: rise .2s ease-out;
  max-width: 88vw; text-align: center;
}

/* ── Login ── */
body.login-page {
  background: var(--ink);
  display: grid; place-items: center; padding: 24px;
  overflow: auto;
}
.login-card {
  width: min(400px, 100%);
  background: var(--paper); border-radius: 18px;
  padding: 36px 30px calc(30px + var(--sab));
}
.login-card .brand { font-family: var(--font-brand); font-size: 27px; font-weight: 700; text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 15px; margin: 6px 0 26px; }
.login-card label { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); margin: 14px 0 5px; }
.login-card input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--white); padding: 13px 14px; font: inherit; font-size: 17px;
}
.login-card input:focus { border-color: var(--gold); outline: none; }
.login-card .go {
  width: 100%; margin-top: 24px; background: var(--gold); color: var(--ink);
  font-weight: 700; font-size: 17px; border-radius: 12px; padding: 14px;
  min-height: 50px; transition: opacity .15s ease-out;
}
.login-card .go:active { opacity: .85; }
.login-card .err { color: var(--rust); font-size: 14.5px; text-align: center; margin-top: 14px; min-height: 20px; }

/* ── Escritorio ── */
@media (min-width: 900px) {
  .drawer { position: static; transform: none; width: 300px; flex-shrink: 0; }
  .backdrop { display: none; }
  .appbar .iconbtn.menu { display: none; }
  .thread { padding: 24px 24px 8px; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
