:root {
  --paper: #fbf8f3; --ink: #15110d; --muted: #7a6e5e;
  --paper-2: #f0e9dc; --paper-3: #e5dcc8; --ink-2: #3d342a;
  --line: #15110d; --line-soft: #d9cfbe;
  --amber: #d97706; --amber-soft: #fbbf24; --online: #16a34a;
  --display: "Instrument Serif", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; margin: 0; }
button, input, textarea, select { font: inherit; }
button:focus-visible,
textarea:focus-visible,
select:focus-visible,
input[type="range"]:focus-visible,
.pick:focus-within {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}
html, body { height: 100%; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--sans);
  height: 100vh; display: flex; flex-direction: column; overflow: hidden;
}
header {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 24px; border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
header h1 { font-family: var(--display); font-weight: 400; font-size: 26px; letter-spacing: -0.02em; }
.meta { font-family: var(--mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }

/* Roster: avatares apilados que se separan en hover para facilitar el click. */
#roster { display: flex; align-items: center; padding-left: 12px; }
#roster .ava {
  width: 42px; height: 42px; border-radius: 50%; border: none; padding: 0;
  background: #fff; display: grid; place-items: center; font-size: 21px; cursor: pointer;
  margin-left: -16px; transition: margin 160ms ease, transform 160ms ease, box-shadow 160ms ease;
  box-shadow: 0 0 0 1px var(--line-soft); position: relative; overflow: hidden;
}
#roster .ava img { display: block; width: 100%; height: 100%; object-fit: cover; }
#roster .ava:first-child { margin-left: 0; }
#roster:hover .ava { margin-left: 6px; }
#roster:hover .ava:first-child { margin-left: 0; }
#roster .ava:hover { transform: translateY(-3px); box-shadow: 0 0 0 2px var(--line); z-index: 5; }
#roster .ava.active { box-shadow: 0 0 0 2px var(--amber); transform: translateY(-2px); z-index: 4; }
#who { display: flex; flex-direction: column; line-height: 1.15; }
#who .n { font-weight: 600; font-size: 14px; }
#who .t { font-size: 11.5px; color: var(--muted); }
#right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
#mode.mock { color: var(--amber); } #mode.real { color: var(--online); }
#user { font-family: var(--mono); font-size: 11px; color: var(--muted); }

#main { flex: 1 1 auto; display: flex; min-height: 0; }
#conversation-menu {
  width: 196px; flex: 0 0 196px; border-right: 1px solid var(--line-soft);
  background: var(--paper); display: flex; flex-direction: column; min-height: 0;
}
.conversation-menu-head {
  height: 43px; padding: 0 10px 0 14px; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase;
}
.conversation-new {
  width: 26px; height: 26px; border: 1px solid var(--line); background: transparent;
  color: var(--ink); cursor: pointer; display: grid; place-items: center; line-height: 1;
  font-family: var(--mono); font-size: 17px;
}
.conversation-new:hover { background: var(--ink); color: var(--paper); }
.conversation-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 3px; }
.conversation-item {
  width: 100%; border: 0; border-left: 2px solid transparent; background: transparent;
  color: var(--ink); padding: 9px 8px 9px 10px; cursor: pointer; text-align: left;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; align-items: start;
}
.conversation-item:hover { background: var(--paper-2); }
.conversation-item.active { border-left-color: var(--amber); background: #fff; }
.conversation-title {
  font-size: 11.5px; line-height: 1.35; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.conversation-item time {
  font-family: var(--mono); color: var(--muted); font-size: 8.5px; white-space: nowrap;
}
.conversation-empty, .conversation-loading, .conversation-error {
  padding: 12px 8px; color: var(--muted); font-size: 11px; line-height: 1.45;
}
.conversation-error { color: #dc2626; }
#chat-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#chat { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 72ch; padding: 12px 16px; font-size: 15px; line-height: 1.55; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--ink); color: var(--paper); }
.msg.agent { align-self: flex-start; border: 1px solid var(--line); background: #fff; }
.evt { align-self: flex-start; font-family: var(--mono); font-size: 11.5px; color: var(--muted); padding: 2px 0; }
.evt.task, .evt.goal { color: var(--amber); } .evt.memory { color: var(--online); } .evt.error { color: #dc2626; }
.hint { align-self: center; color: var(--muted); font-size: 14px; margin: auto 0; text-align: center; }

form.chatform { display: flex; border-top: 1px solid var(--line); background: #fff; flex: 0 0 auto; }
textarea#input {
  flex: 1; border: none; outline: none; resize: none; padding: 16px 20px;
  font-family: var(--sans); font-size: 15px; background: transparent; color: var(--ink);
  transition: background 120ms ease;
}
textarea#input:focus { background: var(--paper); }
button.primary {
  border: none; border-left: 1px solid var(--line); background: var(--ink);
  color: var(--paper); font-family: var(--mono); font-size: 12px;
  letter-spacing: 0.12em; text-transform: uppercase; padding: 0 28px; cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
button.primary:not(:disabled):hover { background: var(--amber); border-left-color: var(--amber); }
button.primary:disabled { background: var(--line-soft); color: var(--muted); cursor: wait; }

@media (max-width: 1040px) {
  #conversation-menu { width: 154px; flex-basis: 154px; }
  #office { width: 340px; }
}

/* Oficina: siempre visible. */
#office { width: 380px; border-left: 1px solid var(--line); display: flex; flex-direction: column; background: #fff; min-height: 0; }
#office-tabs { display: flex; border-bottom: 1px solid var(--line-soft); flex: 0 0 auto; }
#office-tabs button {
  flex: 1; border: none; background: none; padding: 11px 4px; cursor: pointer;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  border-bottom: 2px solid transparent;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
#office-tabs button:hover { background: var(--paper-2); color: var(--ink); }
#office-tabs button.active { color: var(--ink); border-bottom-color: var(--amber); background: var(--paper); }
#office-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card {
  border: 1px solid var(--line-soft); padding: 10px 12px; font-size: 13px;
  background: #fff; transition: border-color 120ms ease, background 120ms ease;
}
.card.is-clickable { cursor: pointer; }
.card.is-clickable:hover { border-color: var(--line); background: var(--paper); }
.card .head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; font-weight: 600; }
.card .sub { font-family: var(--mono); font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.card .body { margin-top: 6px; white-space: pre-wrap; font-size: 12.5px; max-height: 160px; overflow-y: auto; }
.badge { display: inline-flex; align-items: center; flex: 0 0 auto; white-space: nowrap; font-family: var(--mono); font-size: 10px; line-height: 1.35; padding: 1px 6px; border: 1px solid var(--line-soft); color: var(--muted); }
.badge.done, .badge.real, .badge.confirmed, .badge.team { color: var(--online); border-color: var(--online); }
.badge.pending, .badge.mock, .badge.tentative, .badge.user { color: var(--amber); border-color: var(--amber); }
.badge.failed, .badge.cancelled { color: #dc2626; border-color: #dc2626; }
.badge.attendance-accepted { color: #15803d; border-color: #15803d; background: #f0fdf4; }
.badge.attendance-declined { color: #dc2626; border-color: #dc2626; background: #fef2f2; }
.badge.attendance-tentative { color: #2563eb; border-color: #2563eb; background: #eff6ff; }
.badge.attendance-needs_action { color: #b45309; border-color: #d97706; background: #fffbeb; }
.action {
  border: 1px solid var(--line); background: var(--ink); color: var(--paper);
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 8px; cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.action:not(:disabled):hover { background: var(--amber); border-color: var(--amber); }
.action:disabled { background: var(--line-soft); color: var(--muted); }
.action.secondary { background: transparent; color: var(--ink); }
.action.secondary:not(:disabled):hover { background: var(--paper-2); border-color: var(--line); }
.action.danger { background: transparent; color: #b91c1c; border-color: #b91c1c; }
.action.danger:not(:disabled):hover { background: #b91c1c; color: #fff; border-color: #b91c1c; }
.action-row { display: flex; gap: 8px; margin-top: 10px; }
.action-row .action { flex: 1; }
.decision-result {
  min-height: 0; margin-top: 8px; font-family: var(--mono); font-size: 10px;
  line-height: 1.45; color: var(--muted);
}
.decision-result:empty { display: none; }
.decision-result.is-pending { color: var(--muted); }
.decision-result.is-error { color: #b91c1c; }
.office-toolbar { display: grid; gap: 7px; padding-bottom: 12px; border-bottom: 1px solid var(--line-soft); }
.office-toolbar .note { color: var(--muted); font-size: 11.5px; line-height: 1.45; }
.mail-result { font-family: var(--mono); font-size: 10.5px; line-height: 1.45; color: var(--muted); padding: 8px 0 2px; }
.candidate-list { display: grid; gap: 5px; margin-top: 8px; }
.candidate { display: grid; grid-template-columns: 1fr auto; gap: 8px; font-size: 12px; }
.candidate span:last-child { color: var(--muted); font-family: var(--mono); font-size: 10px; }
.candidate-list.approval-entities { gap: 0; border: 1px solid var(--line-soft); }
.approval-entity {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px;
  padding: 9px 10px; min-width: 0;
}
.approval-entity + .approval-entity { border-top: 1px solid var(--line-soft); }
.approval-entity-label {
  grid-column: 1 / -1; color: var(--muted); font-family: var(--mono);
  font-size: 9px; letter-spacing: 0.09em; text-transform: uppercase;
}
.approval-entity strong { min-width: 0; font-size: 12.5px; line-height: 1.35; }
.approval-entity-detail {
  min-width: 0; max-width: 190px; color: var(--muted); font-family: var(--mono);
  font-size: 9.5px; line-height: 1.4; overflow-wrap: anywhere; text-align: right;
}
.memory-card { position: relative; padding-bottom: 34px; }
.icon-action {
  width: 26px; height: 26px; display: grid; place-items: center;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.icon-action svg { width: 14px; height: 14px; }
.icon-action path { stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-action:not(:disabled):hover { color: #b91c1c; border-color: #b91c1c; background: #fff7f7; }
.icon-action:disabled { opacity: .45; cursor: wait; }
.memory-delete { position: absolute; right: 8px; bottom: 7px; }
.memform { display: flex; flex-direction: column; gap: 8px; border: 1px solid var(--line-soft); padding: 10px; background: var(--paper); }
.memform select, .memform textarea {
  border: 1px solid var(--line-soft); padding: 8px 10px; font-family: var(--sans); font-size: 13px; background: #fff;
  color: var(--ink); transition: border-color 120ms ease, background 120ms ease;
}
.memform select:hover, .memform textarea:hover { border-color: var(--line); }
.memform select:focus, .memform textarea:focus { background: var(--paper-2); outline: none; }
.memform label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 0; }
.planning-card { display: grid; gap: 9px; }
.planning-description { font-size: 12.5px; line-height: 1.5; color: var(--ink-2); }
.planning-content { display: grid; gap: 10px; }
.planning-section { border-top: 1px solid var(--line-soft); padding-top: 8px; }
.planning-section h4 { font-family: var(--mono); font-size: 9px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.planning-section ul { padding-left: 17px; display: grid; gap: 4px; font-size: 11.5px; line-height: 1.4; }
.planning-permission { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 7px 0; border-top: 1px solid var(--paper-2); }
.planning-permission:first-of-type { border-top: none; }
.planning-permission strong { font-size: 11.5px; }
.planning-permission span { font-size: 10px; color: var(--muted); text-align: right; }
.planning-permission small { grid-column: 1 / -1; font-family: var(--mono); font-size: 9px; color: var(--muted); }
.plan-history > summary { cursor: pointer; font-family: var(--mono); font-size: 9px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.plan-history .plan-version { margin-top: 8px; padding-left: 8px; border-left: 2px solid var(--line-soft); }
.plan-strategy { font-size: 11.5px; line-height: 1.45; color: var(--ink-2); margin-bottom: 8px; }
.plan-steps { padding-left: 20px; display: grid; gap: 10px; }
.plan-steps > li { position: relative; padding-right: 64px; }
.plan-steps strong { display: block; font-size: 11.5px; line-height: 1.4; }
.plan-steps > li > .badge { position: absolute; right: 0; top: 0; height: auto; min-height: 18px; align-self: start; }
.plan-steps p { margin-top: 3px; font-size: 10.5px; line-height: 1.4; color: var(--muted); }
.plan-tasks { margin-top: 5px; padding-left: 15px; color: var(--ink-2); font-size: 10.5px; }
.plan-reminder { margin-top: 7px; padding: 5px 7px; border-left: 2px solid var(--orange); color: var(--muted); font-size: 10px; line-height: 1.35; }
.plan-reminder.cancelled, .plan-reminder.completed { border-color: var(--green); color: var(--green); }
.plan-reminder.failed { border-color: var(--red); color: var(--red); }

/* Editar avatar: overlay en el avatar activo al hover. */
#roster .ava .edit { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(21,17,13,.68); opacity: 0; transition: opacity 120ms ease; cursor: pointer; }
#roster .ava .edit svg { width: 18px; height: 18px; stroke: #fff; fill: none; }
#roster .ava.active:hover .edit { opacity: 1; }

/* Modal de recorte. */
#avatar-modal { position: fixed; inset: 0; background: rgba(21,17,13,.56); backdrop-filter: blur(8px); display: none; align-items: center; justify-content: center; z-index: 50; }
#avatar-modal.open { display: flex; }
#avatar-modal .box { background: var(--paper); border: 1px solid var(--line); width: 360px; max-width: 92vw; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
#avatar-modal h3 { font-family: var(--display); font-weight: 400; font-size: 22px; }
#crop-stage { width: 260px; height: 260px; border-radius: 50%; overflow: hidden; margin: 0 auto; background: var(--paper-2); cursor: grab; box-shadow: 0 0 0 1px var(--line), 0 0 0 10px var(--paper-3); position: relative; touch-action: none; }
#crop-stage canvas { display: block; }
#crop-stage.dragging { cursor: grabbing; }
#crop-stage.empty::after { content: 'Elige una imagen'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
#avatar-modal .zoom { display: flex; align-items: center; gap: 12px; }
#avatar-modal .zoom span { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
#avatar-modal input[type=range] { flex: 1; accent-color: var(--amber); }
#avatar-modal .pick {
  text-align: center; border: 1px solid var(--line); padding: 10px; cursor: pointer;
  font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink); background: transparent;
  transition: background 120ms ease, color 120ms ease;
}
#avatar-modal .pick:hover { background: var(--ink); color: var(--paper); }
#avatar-modal .actions { display: flex; gap: 10px; }
#avatar-modal .actions button {
  flex: 1; padding: 10px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  cursor: pointer; border: 1px solid var(--line); background: transparent; color: var(--ink);
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, opacity 120ms ease;
}
#avatar-modal .actions button:not(:disabled):hover { background: var(--ink); color: var(--paper); }
#avatar-modal .actions .save { background: var(--ink); color: var(--paper); }
#avatar-modal .actions .save:not(:disabled):hover { background: var(--amber); border-color: var(--amber); }
#avatar-modal .actions button:disabled { background: var(--line-soft); color: var(--muted); border-color: var(--line-soft); cursor: not-allowed; opacity: 1; }
