/* ==========================================================================
   Mi Expediente — Chat Pro
   --------------------------------------------------------------------------
   Namespaced `.mec-page`. Reusa _shared.css palette + mi-expediente.css base.
   Sprint Wave 1 Agent E · 2026-04-26.
   ========================================================================== */

.mec-page {
  --mec-sidebar-w: 280px;
  --mec-thread-max: 820px;
  --mec-composer-h: 152px;

  /* Reuse _shared / me palette */
  --mec-navy-900: var(--pro-navy-900, #0b1e3f);
  --mec-navy-800: var(--pro-navy-800, #11294f);
  --mec-navy-700: var(--pro-navy-700, #1b3a6b);
  --mec-navy-300: var(--pro-navy-300, #6b86b6);
  --mec-navy-100: var(--pro-navy-100, #dbe4f3);
  --mec-gold-500: var(--pro-gold-500, #f59e0b);
  --mec-gold-100: var(--pro-gold-100, #fef3c7);
  --mec-gold-700: var(--pro-gold-700, #92400e);
  --mec-line: var(--pro-line, #e2e8f0);
  --mec-line-2: var(--pro-line-strong, #cbd5e1);
  --mec-bg: var(--pro-bg, #fafbfc);
  --mec-bg-alt: var(--pro-bg-alt, #f1f5f9);
  --mec-paper: var(--pro-surface, #ffffff);
  --mec-ink: var(--pro-ink, #0f1f3d);
  --mec-body: var(--pro-body, #334155);
  --mec-mute: var(--pro-mute, #64748b);
  --mec-subtle: var(--pro-subtle, #94a3b8);

  background: var(--mec-bg);
  min-height: 100vh;
}

/* Layout: sidebar + stage. The pro-shell topnav sits above. */
.mec-shell {
  display: grid;
  grid-template-columns: var(--mec-sidebar-w) 1fr;
  min-height: calc(100vh - 60px);
  max-width: 1480px;
  margin: 0 auto;
  background: var(--mec-paper);
  border-left: 1px solid var(--mec-line);
  border-right: 1px solid var(--mec-line);
}
@media (max-width: 900px) {
  .mec-shell { grid-template-columns: 1fr; border: 0; }
}

/* ─── Sidebar ─────────────────────────────────────────────────────────── */
.mec-sidebar {
  border-right: 1px solid var(--mec-line);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--mec-bg-alt) 0%, var(--mec-paper) 60%);
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow: hidden;
}
@media (max-width: 900px) {
  .mec-sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--mec-line);
    max-height: 240px;
  }
}

.mec-sidebar-head {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--mec-line);
}
.mec-sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px 14px 14px;
}
.mec-sidebar-foot {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--mec-line);
  background: var(--mec-bg-alt);
}
.mec-side-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--mec-mute);
  margin: 0 4px 8px;
}
.mec-side-hint {
  margin: 0;
  font-size: 11.5px;
  color: var(--mec-mute);
  line-height: 1.4;
}

.mec-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mec-history-empty {
  padding: 12px 8px;
  font-size: 13px;
  color: var(--mec-mute);
  font-style: italic;
}

.mec-history-item {
  position: relative;
  padding: 10px 30px 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--mec-body);
  border: 1px solid transparent;
  transition: background .15s var(--pro-ease-out, ease), border-color .15s ease;
  line-height: 1.4;
}
.mec-history-item:hover {
  background: var(--mec-bg-alt);
  border-color: var(--mec-line);
}
.mec-history-item.is-active {
  background: var(--mec-navy-100);
  border-color: var(--mec-navy-300);
  color: var(--mec-navy-800);
  font-weight: 500;
}
.mec-history-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.mec-history-meta {
  margin-top: 4px;
  font-size: 10.5px;
  color: var(--mec-mute);
  font-weight: 500;
  letter-spacing: .02em;
}
.mec-history-del {
  position: absolute;
  top: 8px;
  right: 6px;
  width: 22px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--mec-subtle);
  cursor: pointer;
  display: none;
}
.mec-history-item:hover .mec-history-del,
.mec-history-item.is-active .mec-history-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.mec-history-del:hover { background: rgba(220, 38, 38, .1); color: #dc2626; }

/* ─── Stage (chat main) ──────────────────────────────────────────────── */
.mec-stage {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 60px);
  position: relative;
}

/* Hero (empty state) */
.mec-hero {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px calc(var(--mec-composer-h) + 32px);
}
.mec-hero-inner {
  max-width: var(--mec-thread-max);
  width: 100%;
  border-radius: 18px;
  padding: 36px 36px 32px;
  text-align: left;
}
.mec-hero h1 {
  font-family: var(--pro-font-display, "Source Serif 4", Georgia, serif);
  font-size: 38px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -.02em;
  margin: 12px 0 10px;
  color: var(--mec-navy-900);
}
.mec-hero h1 em {
  font-style: normal;
  background: linear-gradient(90deg, var(--mec-navy-700), var(--mec-gold-500));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.mec-hero-sub {
  font-size: 16px;
  color: var(--mec-body);
  max-width: 620px;
  line-height: 1.55;
  margin: 0 0 22px;
}
.mec-hero-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.mec-suggest {
  background: var(--mec-paper);
  border: 1px solid var(--mec-line-2);
  border-radius: 999px;
  padding: 8px 14px;
  font: 500 13px var(--pro-font-sans, "Inter", sans-serif);
  color: var(--mec-navy-800);
  cursor: pointer;
  transition: all .18s var(--pro-ease-out, ease);
  white-space: nowrap;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mec-suggest:hover {
  border-color: var(--mec-navy-700);
  background: var(--mec-navy-100);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px -4px rgba(11,30,63,.18);
}

/* ─── Thread ─────────────────────────────────────────────────────────── */
.mec-thread {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px calc(var(--mec-composer-h) + 32px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}
.mec-msg {
  max-width: var(--mec-thread-max);
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: mec-msg-in .26s var(--pro-ease-out, cubic-bezier(.22,.61,.36,1));
}
@keyframes mec-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.mec-msg-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--mec-mute);
  font-weight: 500;
}
.mec-msg-head strong {
  color: var(--mec-navy-800);
  font-weight: 700;
}
.mec-msg-time {
  color: var(--mec-subtle);
  font-size: 11px;
}

.mec-bubble {
  position: relative;
  background: var(--mec-paper);
  border: 1px solid var(--mec-line);
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--mec-body);
  word-wrap: break-word;
}
.mec-msg--user .mec-bubble {
  background: var(--mec-navy-100);
  border-color: var(--mec-navy-300);
  color: var(--mec-navy-900);
}
.mec-msg--assistant .mec-bubble {
  box-shadow: 0 1px 3px rgba(11,30,63,.05);
}
.mec-bubble.is-streaming {
  border-color: var(--mec-gold-500);
  box-shadow: 0 0 0 3px rgba(245,158,11,.08);
}

/* Markdown light styling inside bubble */
.mec-bubble p { margin: 0 0 .65em; }
.mec-bubble p:last-child { margin-bottom: 0; }
.mec-bubble strong { color: var(--mec-navy-800); font-weight: 700; }
.mec-bubble em { color: var(--mec-navy-700); }
.mec-bubble ul, .mec-bubble ol {
  margin: .4em 0 .8em;
  padding-left: 1.5em;
}
.mec-bubble li { margin: .25em 0; }
.mec-bubble code {
  background: var(--mec-bg-alt);
  border: 1px solid var(--mec-line);
  border-radius: 4px;
  padding: 1px 6px;
  font: 500 13px var(--pro-font-mono, ui-monospace, monospace);
  color: var(--mec-navy-800);
}
.mec-bubble pre {
  background: var(--mec-navy-900);
  color: #e2e8f0;
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: .6em 0;
  font: 500 13px var(--pro-font-mono, ui-monospace, monospace);
  line-height: 1.55;
}
.mec-bubble pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}
.mec-bubble a {
  color: var(--mec-navy-700);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.mec-bubble a:hover { color: var(--mec-gold-700); }

/* Skeleton placeholder before first token */
.mec-typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  height: 20px;
}
.mec-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mec-navy-300);
  animation: mec-typing-pulse 1.2s infinite ease-in-out;
}
.mec-typing-dot:nth-child(2) { animation-delay: .15s; }
.mec-typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes mec-typing-pulse {
  0%, 60%, 100% { transform: scale(.8); opacity: .55; }
  30% { transform: scale(1.15); opacity: 1; }
}

/* Sources accordion */
.mec-sources {
  margin-top: 10px;
}
.mec-sources-toggle {
  background: transparent;
  border: 1px solid var(--mec-line);
  border-radius: 8px;
  padding: 6px 12px;
  font: 500 12px var(--pro-font-sans, "Inter", sans-serif);
  color: var(--mec-navy-700);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .15s ease;
}
.mec-sources-toggle:hover {
  border-color: var(--mec-navy-700);
  background: var(--mec-bg-alt);
}
.mec-sources-toggle svg {
  transition: transform .2s ease;
}
.mec-sources[open] .mec-sources-toggle svg {
  transform: rotate(180deg);
}
.mec-sources-body {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.mec-source-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--mec-bg-alt);
  border: 1px solid var(--mec-line);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  color: var(--mec-navy-800);
  text-decoration: none;
  font-weight: 500;
  transition: all .14s ease;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mec-source-chip:hover {
  background: var(--mec-navy-100);
  border-color: var(--mec-navy-300);
  color: var(--mec-navy-900);
  text-decoration: none;
}
.mec-source-chip-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--mec-navy-700);
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
}

/* Foot meta line under assistant bubble */
.mec-msg-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 11.5px;
  color: var(--mec-mute);
}
.mec-msg-foot strong { color: var(--mec-navy-700); font-weight: 600; }
.mec-msg-cost {
  background: var(--mec-gold-100);
  border: 1px solid #fbd38d;
  color: var(--mec-gold-700);
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11px;
}
.mec-msg-deep {
  background: var(--mec-navy-100);
  border: 1px solid var(--mec-navy-300);
  color: var(--mec-navy-800);
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11px;
}

/* Error bubble */
.mec-msg--error .mec-bubble {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

/* ─── Composer ───────────────────────────────────────────────────────── */
.mec-composer {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 18px 16px;
  z-index: 20;
  margin-top: auto;
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(250,251,252,.85) 35%, var(--mec-bg) 100%);
}
.mec-composer-inner {
  max-width: var(--mec-thread-max);
  margin: 0 auto;
  border-radius: 16px;
  padding: 10px 12px 10px;
  border: 1px solid var(--mec-line-2);
}

.mec-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 8px;
  flex-wrap: wrap;
}
.mec-toolbar-spacer { flex: 1; }

.mec-segment {
  display: inline-flex;
  background: var(--mec-bg-alt);
  border: 1px solid var(--mec-line);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.mec-seg-btn {
  background: transparent;
  border: 0;
  padding: 5px 11px;
  font: 600 12px var(--pro-font-sans, "Inter", sans-serif);
  color: var(--mec-mute);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all .14s var(--pro-ease-out, ease);
}
.mec-seg-btn:hover { color: var(--mec-navy-800); }
.mec-seg-btn.is-active {
  background: var(--mec-paper);
  color: var(--mec-navy-900);
  box-shadow: 0 1px 2px rgba(11,30,63,.1);
}

.mec-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 999px;
  letter-spacing: .02em;
}
.mec-pill--gold {
  background: var(--mec-gold-100);
  color: var(--mec-gold-700);
  border: 1px solid #fbd38d;
}

.mec-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 0 4px;
}
.mec-input {
  flex: 1;
  border: 0;
  background: transparent;
  resize: none;
  font: 400 15px var(--pro-font-sans, "Inter", sans-serif);
  color: var(--mec-ink);
  line-height: 1.5;
  padding: 8px 4px;
  max-height: 200px;
  outline: none;
}
.mec-input::placeholder { color: var(--mec-subtle); }

.mec-send,
.mec-stop {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .15s ease;
}
.mec-send {
  background: linear-gradient(135deg, var(--mec-navy-700), var(--mec-navy-800));
  color: #fff;
  box-shadow: 0 6px 16px -6px rgba(11,30,63,.45);
}
.mec-send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px -8px rgba(11,30,63,.55);
}
.mec-send:disabled {
  opacity: .4;
  cursor: not-allowed;
  box-shadow: none;
}
.mec-stop {
  background: #dc2626;
  color: #fff;
}
.mec-stop:hover { background: #b91c1c; }

.mec-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px 0;
  font-size: 11.5px;
  color: var(--mec-mute);
}
.mec-foot-counter { font-variant-numeric: tabular-nums; }

/* ─── Buttons (sidebar) ──────────────────────────────────────────────── */
.mec-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 9px;
  border: 1px solid var(--mec-line);
  background: var(--mec-paper);
  padding: 9px 14px;
  font: 600 13px var(--pro-font-sans, "Inter", sans-serif);
  color: var(--mec-navy-800);
  cursor: pointer;
  transition: all .15s var(--pro-ease-out, ease);
  text-decoration: none;
}
.mec-btn:hover {
  border-color: var(--mec-navy-700);
  color: var(--mec-navy-900);
}
.mec-btn--primary {
  background: linear-gradient(135deg, var(--mec-navy-700), var(--mec-navy-800));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 10px -4px rgba(11,30,63,.4);
}
.mec-btn--primary:hover {
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 8px 18px -8px rgba(11,30,63,.55);
}
.mec-btn--block { width: 100%; }

/* ─── Hide utility (defer to mi-expediente.css .me-hidden as fallback) */
.mec-page .me-hidden,
.me-hidden { display: none !important; }

/* ─── Reduced motion ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .mec-msg { animation: none; }
  .mec-typing-dot { animation: none; opacity: .6; }
  .mec-sources-toggle svg { transition: none; }
  .mec-suggest:hover { transform: none; }
}


/* 2026-04-26: Markdown rendering polish (tables, headings, lists, blockquotes) inside chat bubbles */
.mec-md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13.5px;
  border: 1px solid var(--pro-line, #e2e8f0);
  border-radius: var(--pro-r-sm, 8px);
  overflow: hidden;
}
.mec-md-table th, .mec-md-table td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--pro-line, #e2e8f0);
  vertical-align: top;
}
.mec-md-table thead th {
  background: var(--pro-bg-alt, #f1f5f9);
  font-weight: 700;
  color: var(--pro-navy-800, #11294f);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.mec-md-table tbody tr:last-child td { border-bottom: 0; }
.mec-md-table tbody tr:hover { background: var(--pro-bg-alt, #f1f5f9); }
.mec-bubble h1, .mec-bubble h2, .mec-bubble h3, .mec-bubble h4 {
  font-family: var(--pro-font-display, "Source Serif 4", Georgia, serif);
  color: var(--pro-navy-900, #0b1e3f);
  margin: 16px 0 8px;
  line-height: 1.2;
}
.mec-bubble h1 { font-size: 22px; font-weight: 700; }
.mec-bubble h2 { font-size: 19px; font-weight: 700; }
.mec-bubble h3 { font-size: 16.5px; font-weight: 600; }
.mec-bubble h4 { font-size: 15px; font-weight: 600; }
.mec-bubble h1:first-child, .mec-bubble h2:first-child, .mec-bubble h3:first-child, .mec-bubble h4:first-child { margin-top: 0; }
.mec-bubble blockquote {
  border-left: 3px solid var(--pro-gold-500, #f59e0b);
  margin: 10px 0;
  padding: 4px 12px;
  background: rgba(252, 211, 77, .08);
  color: var(--pro-body, #334155);
  font-style: italic;
}
.mec-bubble ol, .mec-bubble ul { padding-left: 22px; margin: 8px 0; }
.mec-bubble li { margin: 3px 0; }
.mec-bubble hr { border: 0; border-top: 1px solid var(--pro-line, #e2e8f0); margin: 16px 0; }
.mec-bubble pre { background: var(--pro-bg-alt, #f1f5f9); padding: 10px; border-radius: 6px; overflow-x: auto; font-size: 12.5px; }
.mec-bubble code { background: rgba(11,30,63,.06); padding: 1px 5px; border-radius: 4px; font-size: 92%; }
.mec-bubble pre code { background: transparent; padding: 0; }
.mec-history-meta { white-space: nowrap; }
