/* ═══════════════════════════════════════════════════════════════════════════
   Mateo Panel — style.css
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-start: #0a0a0a;
  --bg-end: #1a1a2e;
  --glass-bg: rgba(255,255,255,.03);
  --glass-border: rgba(255,255,255,.08);
  --glass-blur: 20px;
  --accent: #6366f1;
  --accent2: #a855f7;
  --accent-glow: rgba(99,102,241,.25);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --danger: #ef4444;
  --success: #22c55e;
  --warn: #f59e0b;
  --info: #3b82f6;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --header-h: 56px;
  --tabnav-h: 44px;
  --sidebar-w: 240px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
  background-attachment: fixed;
  overflow: hidden;
}

a { color: var(--accent); }
button { cursor: pointer; font-family: inherit; font-size: inherit; }
input, textarea { font-family: inherit; font-size: inherit; }
ul, ol { list-style: none; }

/* ─── Scroll ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 99px; }

/* ─── Utility ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); font-size: .85em; }
.loading-text, .empty-text { color: var(--text-muted); padding: 1rem; text-align: center; }
.error-text { color: var(--danger); padding: 1rem; text-align: center; }

/* ─── Glass ────────────────────────────────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
}

/* ─── Screens ──────────────────────────────────────────────────────────────── */
.screen { display: none; width: 100%; height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius-sm); padding: .45rem .9rem;
  font-weight: 500; transition: background .15s, opacity .15s, transform .1s;
  white-space: nowrap; gap: .35rem;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 0 16px var(--accent-glow);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }

.btn-ghost {
  background: rgba(255,255,255,.06);
  color: var(--text);
  border: 1px solid var(--glass-border);
}
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,.1); }

.btn-icon {
  background: none; border: none; color: var(--text-muted);
  padding: .3rem .5rem; border-radius: var(--radius-sm);
  font-size: 1rem;
}
.btn-icon:hover { color: var(--text); background: rgba(255,255,255,.07); }

.btn-block { width: 100%; }
.btn-sm { font-size: .82rem; padding: .3rem .65rem; }

/* ─── Alert ────────────────────────────────────────────────────────────────── */
.alert { border-radius: var(--radius-sm); padding: .6rem .9rem; font-size: .88rem; }
.alert-error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }

/* ═══════════════════════════ LOGIN ═══════════════════════════════════════ */
#screen-login {
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
}

.login-wrapper { width: 100%; max-width: 380px; padding: 1rem; }

.login-card {
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}

/* ─── Avatar ───────────────────────────────────────────────────────────────── */
.avatar-lg {
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: #fff;
  box-shadow: 0 0 24px var(--accent-glow);
}
.avatar-sm {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

/* ─── Brand ────────────────────────────────────────────────────────────────── */
.brand-title {
  font-size: 2rem; font-weight: 700; letter-spacing: -.5px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-sub { color: var(--text-muted); font-size: .88rem; text-align: center; }

.brand-title-sm {
  font-size: 1rem; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-sub-sm { font-size: .75rem; color: var(--text-muted); }

/* ─── Form fields ──────────────────────────────────────────────────────────── */
.login-card form { width: 100%; display: flex; flex-direction: column; gap: .85rem; }

.field { display: flex; flex-direction: column; gap: .35rem; }
.field label { font-size: .82rem; color: var(--text-muted); font-weight: 500; }
.field input {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ═══════════════════════════ SHELL ═══════════════════════════════════════ */
#screen-shell { overflow: hidden; }

/* ─── Header ───────────────────────────────────────────────────────────────── */
.shell-header {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem;
  border-radius: 0;
  border-top: none; border-left: none; border-right: none;
  flex-shrink: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: .65rem; cursor: pointer; }
.header-titles { display: flex; flex-direction: column; }
.header-right { display: flex; align-items: center; gap: .75rem; }

/* ─── Indicador ARIEL ──────────────────────────────────────────────────────── */
.ariel-status { display: flex; align-items: center; gap: .4rem; font-size: .85rem; }
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background .3s;
}
.status-dot.up { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.down { background: var(--danger); box-shadow: 0 0 6px var(--danger); animation: blink 1s infinite; }

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ─── Tab nav ──────────────────────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  height: var(--tabnav-h);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
  overflow-x: auto;
}
.tab-btn {
  flex: 1; background: none; border: none;
  color: var(--text-muted); font-size: .88rem; font-weight: 500;
  padding: 0 .5rem;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
  min-width: 90px;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text); }

/* ─── Tab panels ───────────────────────────────────────────────────────────── */
.tab-panel {
  display: none; flex: 1; overflow: hidden;
}
.tab-panel.active { display: flex; flex-direction: column; }

/* ─── Panel content genérico ───────────────────────────────────────────────── */
.panel-content {
  flex: 1; overflow-y: auto; padding: 1rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
}
.panel-header h2 { font-size: 1.15rem; font-weight: 600; }
.panel-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ═══════════════════════════ CHAT ═══════════════════════════════════════ */
.chat-layout {
  flex: 1; display: flex; overflow: hidden;
}

/* ─── Sidebar conversaciones ───────────────────────────────────────────────── */
.conv-sidebar {
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--glass-border);
  border-radius: 0;
  flex-shrink: 0;
  overflow: hidden;
}
.conv-sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.sidebar-title { font-size: .82rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

.conv-list { overflow-y: auto; flex: 1; padding: .4rem; }
.conv-item {
  display: flex; align-items: center; gap: .4rem;
  padding: .55rem .65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s;
}
.conv-item:hover { background: rgba(255,255,255,.05); }
.conv-item.active { background: rgba(99,102,241,.15); border: 1px solid rgba(99,102,241,.25); }
.conv-name { flex: 1; font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del { opacity: 0; font-size: .75rem; padding: .2rem .35rem; }
.conv-item:hover .conv-del { opacity: .6; }
.conv-del:hover { opacity: 1 !important; color: var(--danger); }

/* ─── Chat main ────────────────────────────────────────────────────────────── */
.chat-main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0;
}
.messages-area {
  flex: 1; overflow-y: auto; padding: 1rem;
  display: flex; flex-direction: column; gap: .75rem;
}

/* ─── Burbujas ─────────────────────────────────────────────────────────────── */
.bubble-wrap { display: flex; max-width: 82%; }
.bubble-wrap.user { align-self: flex-end; flex-direction: row-reverse; }
.bubble-wrap.assistant { align-self: flex-start; }

.bubble {
  padding: .7rem 1rem; border-radius: var(--radius);
  line-height: 1.6; font-size: .9rem; word-break: break-word;
}
.bubble-user {
  background: rgba(99,102,241,.2);
  border: 1px solid rgba(99,102,241,.3);
  border-bottom-right-radius: 4px;
}
.bubble-assistant {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 4px;
}

/* ─── Chips de herramienta ─────────────────────────────────────────────────── */
.tool-chip-wrap { align-self: flex-start; max-width: 90%; }
.tool-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  background: rgba(255,255,255,.04); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); padding: .35rem .7rem;
  font-size: .8rem; color: var(--text-muted);
  transition: background .12s;
}
.tool-chip:hover { background: rgba(255,255,255,.08); }
.tool-chip.ok { border-color: rgba(34,197,94,.35); color: #86efac; }
.tool-chip.err { border-color: rgba(239,68,68,.35); color: #fca5a5; }
.tool-chip.running { border-color: rgba(99,102,241,.4); color: var(--accent); animation: pulse-border .8s infinite; }

@keyframes pulse-border { 0%,100%{border-color:rgba(99,102,241,.4)} 50%{border-color:rgba(99,102,241,.8)} }

.tool-detail {
  margin-top: .3rem;
  background: rgba(0,0,0,.3); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); padding: .5rem .75rem;
  font-size: .78rem; color: var(--text-muted);
  max-height: 300px; overflow-y: auto;
}
.tool-detail pre { white-space: pre-wrap; word-break: break-all; font-family: var(--mono); }

/* ─── Quick chips ──────────────────────────────────────────────────────────── */
.quick-chips {
  display: flex; gap: .5rem; padding: .5rem 1rem;
  flex-wrap: wrap;
}
.chip {
  background: rgba(99,102,241,.1); border: 1px solid rgba(99,102,241,.2);
  color: var(--text); border-radius: 99px; padding: .35rem .85rem;
  font-size: .82rem; transition: background .12s, border-color .12s;
}
.chip:hover { background: rgba(99,102,241,.2); border-color: rgba(99,102,241,.4); }

/* ─── Input area ───────────────────────────────────────────────────────────── */
.input-area {
  border-top: 1px solid var(--glass-border);
  border-radius: 0;
  padding: .65rem .85rem;
  display: flex; flex-direction: column; gap: .4rem;
  flex-shrink: 0;
}
.input-row { display: flex; align-items: flex-end; gap: .5rem; }
.input-row textarea {
  flex: 1; background: rgba(255,255,255,.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: .55rem .75rem;
  color: var(--text); resize: none; outline: none;
  max-height: 200px; line-height: 1.5;
  transition: border-color .15s, box-shadow .15s;
}
.input-row textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.btn-send { height: 38px; width: 42px; padding: 0; border-radius: var(--radius-sm); flex-shrink: 0; }

/* ─── Thinking indicator ───────────────────────────────────────────────────── */
.thinking-indicator {
  display: flex; align-items: center; gap: .5rem;
  color: var(--text-muted); font-size: .82rem; padding: .1rem 0;
}
.dots { display: flex; gap: 4px; }
.dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); animation: bounce .9s infinite;
}
.dots span:nth-child(2) { animation-delay: .15s; }
.dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100%{transform:translateY(0)} 40%{transform:translateY(-6px)} }

/* ─── Provider badge ───────────────────────────────────────────────────────── */
.provider-badge {
  font-size: .75rem; color: var(--text-dim);
  padding: .1rem .4rem;
  border-radius: 99px;
  border: 1px solid var(--glass-border);
  align-self: flex-start;
}

/* ─── Chat error ───────────────────────────────────────────────────────────── */
.chat-error {
  align-self: center; background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.25); border-radius: var(--radius-sm);
  padding: .5rem 1rem; font-size: .85rem; color: #fca5a5;
}

/* ─── Code blocks ──────────────────────────────────────────────────────────── */
.code-block {
  background: rgba(0,0,0,.4); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); padding: .75rem 1rem;
  overflow-x: auto; font-family: var(--mono); font-size: .82rem;
  margin: .4rem 0; position: relative;
}
.code-lang {
  display: block; font-size: .7rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: .4rem;
}
.inline-code {
  background: rgba(99,102,241,.15); border-radius: 4px;
  padding: .1em .35em; font-family: var(--mono); font-size: .88em;
}

/* ═══════════════════════════ BITÁCORA ═══════════════════════════════════ */
.changelog-list { display: flex; flex-direction: column; gap: .75rem; }

.changelog-card {
  border-radius: var(--radius);
  padding: 1rem;
  display: flex; flex-direction: column; gap: .4rem;
}
.cl-header { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.cl-id { font-family: var(--mono); font-size: .78rem; color: var(--text-muted); }
.cl-ts { margin-left: auto; font-size: .78rem; color: var(--text-dim); }
.cl-what { font-size: .9rem; }
.cl-why, .cl-files { font-size: .8rem; }

.cl-status { font-size: .75rem; padding: .15rem .5rem; border-radius: 99px; font-weight: 600; }
.status-ok  { background: rgba(34,197,94,.12); color: #86efac; border: 1px solid rgba(34,197,94,.2); }
.status-err { background: rgba(239,68,68,.12); color: #fca5a5; border: 1px solid rgba(239,68,68,.2); }
.status-warn { background: rgba(245,158,11,.12); color: #fde68a; border: 1px solid rgba(245,158,11,.2); }
.status-info { background: rgba(59,130,246,.12); color: #93c5fd; border: 1px solid rgba(59,130,246,.2); }

.cl-detail-btn { align-self: flex-start; margin-top: .25rem; }

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); }
.modal-card {
  position: relative; border-radius: var(--radius-lg);
  width: 100%; max-width: 760px; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-body { overflow-y: auto; padding: 1.25rem; flex: 1; }

/* ─── Detalle de changelog ─────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; font-size: .88rem; margin-bottom: 1rem; }
.detail-grid dt { color: var(--text-muted); font-weight: 500; }
.detail-grid dd { word-break: break-all; }

/* ─── Diff ─────────────────────────────────────────────────────────────────── */
.diff-block { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--glass-border); }
.diff-pre { font-family: var(--mono); font-size: .78rem; padding: .75rem; white-space: pre; }
.diff-add  { display: block; color: #86efac; background: rgba(34,197,94,.08); }
.diff-del  { display: block; color: #fca5a5; background: rgba(239,68,68,.08); }
.diff-hunk { display: block; color: #93c5fd; background: rgba(59,130,246,.08); }
.diff-ctx  { display: block; color: var(--text-muted); }

/* ═══════════════════════════ MONITOREO ══════════════════════════════════ */
.monitor-summary {
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex; flex-wrap: wrap; gap: 1.25rem;
  align-items: center;
}
.monitor-stat { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.stat-label { color: var(--text-muted); font-size: .82rem; }
.stat-val { font-weight: 600; }
.stat-err { color: var(--danger); }

.monitor-checks { overflow-y: auto; }
.checks-title { font-size: .88rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin: .5rem 0; }

.checks-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.checks-table th { color: var(--text-muted); font-weight: 500; padding: .4rem .6rem; text-align: left; border-bottom: 1px solid var(--glass-border); }
.checks-table td { padding: .45rem .6rem; border-bottom: 1px solid rgba(255,255,255,.04); }
.checks-table tr:last-child td { border-bottom: none; }
.checks-table tr:hover td { background: rgba(255,255,255,.02); }

/* ═══════════════════════════ RESPONSIVE ════════════════════════════════ */
@media (max-width: 640px) {
  :root { --sidebar-w: 0px; }

  .conv-sidebar {
    position: fixed;
    top: calc(var(--header-h) + var(--tabnav-h));
    left: 0;
    bottom: 0;
    width: 220px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 200;
    border-right: 1px solid var(--glass-border);
  }
  .conv-sidebar.open { transform: translateX(0); }

  .chat-main { width: 100%; }
  .bubble-wrap { max-width: 95%; }

  .login-card { padding: 1.75rem 1.25rem; }

  .monitor-summary { flex-direction: column; align-items: flex-start; gap: .75rem; }
  .checks-table { font-size: .75rem; }
  .checks-table th:nth-child(4),
  .checks-table td:nth-child(4) { display: none; }

  .panel-header { flex-direction: column; align-items: flex-start; }
}

@media (min-width: 641px) {
  .conv-sidebar.open { transform: none; }
}

/* ─── Selección de texto ───────────────────────────────────────────────────── */
::selection { background: rgba(99,102,241,.3); color: var(--text); }

/* ─── Cerebro (modelo principal / respaldo) ─────────────────────────────────── */
.brain-badge {
  font-size: .72rem; color: var(--text-dim);
  padding: .15rem .5rem; margin-right: .6rem;
  border-radius: 99px; border: 1px solid var(--glass-border);
  white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis;
}
