/* ═══════════════════════════════════════════════════════════════
   Panel Atlas · 414 Capital
   Paleta y tipografías tomadas de 414capital.com:
     navy   #002545  (color dominante del sitio)
     teal   #07AAA5  (acento: nav activo, botones, highlights)
     azul   #004882  (secundario: títulos, links)
     Poppins (UI) · Raleway (display ligero) · Open Sans (lectura)
   ═══════════════════════════════════════════════════════════════ */

:root {
  --navy:       #002545;
  --navy-deep:  #001526;
  --navy-soft:  #0a3a63;
  --teal:       #07AAA5;
  --teal-dark:  #058c88;
  --blue:       #004882;
  --ink:        #1b2733;
  --muted:      #64748b;
  --paper:      #f5f7f9;
  --card:       #ffffff;
  --line:       #e2e8ee;
  --danger:     #c0392b;

  --font-ui:      'Poppins', sans-serif;
  --font-display: 'Raleway', sans-serif;
  --font-body:    'Open Sans', sans-serif;

  --shadow-sm: 0 1px 3px rgba(0, 37, 69, .08);
  --shadow-md: 0 6px 24px rgba(0, 37, 69, .12);
  --shadow-lg: 0 24px 64px rgba(0, 21, 38, .35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button { font-family: var(--font-ui); cursor: pointer; }

/* ─────────────────────────── LOGIN ─────────────────────────── */

.login {
  position: fixed; inset: 0;
  background:
    radial-gradient(1200px 700px at 75% -10%, rgba(7,170,165,.14), transparent 60%),
    linear-gradient(160deg, var(--navy) 0%, var(--navy-deep) 100%);
  display: grid; place-items: center;
  overflow: hidden;
}

.login-watermark {
  position: absolute; right: -4rem; bottom: -7rem;
  font-family: var(--font-display); font-weight: 100;
  font-size: clamp(18rem, 40vw, 34rem); line-height: 1;
  color: rgba(255,255,255,.035);
  user-select: none; pointer-events: none;
  letter-spacing: -.04em;
}

.login-grid {
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: radial-gradient(900px 600px at 50% 40%, black, transparent 75%);
}

.login-card {
  position: relative;
  width: min(400px, calc(100vw - 2.5rem));
  background: var(--card);
  border-radius: 10px;
  padding: 2.6rem 2.4rem 2rem;
  box-shadow: var(--shadow-lg);
  animation: rise .55s cubic-bezier(.22,1,.36,1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(22px); }
  to   { opacity: 1; transform: none; }
}

.login-logo { width: 132px; display: block; margin-bottom: 1.6rem; }

.login-title {
  font-family: var(--font-display); font-weight: 200;
  font-size: 2.1rem; color: var(--navy); line-height: 1.1;
}

.login-sub {
  font-family: var(--font-ui); font-weight: 400;
  font-size: .72rem; letter-spacing: .18em; text-transform: uppercase;
  color: var(--teal); margin: .45rem 0 1.8rem;
}

.field { display: block; margin-bottom: 1rem; }

.field span {
  display: block;
  font-family: var(--font-ui); font-size: .68rem; font-weight: 500;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin-bottom: .4rem;
}

.field input {
  width: 100%;
  font-family: var(--font-body); font-size: .95rem;
  padding: .68rem .8rem;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fbfcfd; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus {
  outline: none; border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(7,170,165,.15);
}

.login-error {
  min-height: 1.2rem; font-size: .8rem; color: var(--danger);
  margin-bottom: .6rem;
}

.btn-primary {
  width: 100%;
  background: var(--teal); color: #fff; border: none;
  font-size: .78rem; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase;
  padding: .85rem; border-radius: 6px;
  transition: background .15s, transform .15s, box-shadow .15s;
}

.btn-primary:hover {
  background: var(--teal-dark);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(7,170,165,.35);
}

.btn-primary:disabled { opacity: .6; transform: none; }

.login-foot {
  margin-top: 1.6rem; text-align: center;
  font-size: .68rem; color: var(--muted);
}

/* ─────────────────────────── SHELL ─────────────────────────── */

.app { display: flex; height: 100vh; }

.sidebar {
  width: 232px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  display: flex; flex-direction: column;
  color: #fff;
}

.sidebar-brand { padding: 1.7rem 1.4rem 1.2rem; }

.sidebar-brand img { width: 118px; display: block; }

.sidebar-product {
  font-family: var(--font-display); font-weight: 200;
  font-size: 1.5rem; margin-top: .9rem; color: #fff;
}

.sidebar-product .dot { color: var(--teal); font-weight: 400; }

.sidebar-nav { flex: 1; padding: 1rem .8rem; display: flex; flex-direction: column; gap: .25rem; }

.nav-item {
  display: flex; align-items: center; gap: .7rem;
  width: 100%; text-align: left;
  background: none; border: none; border-radius: 6px;
  color: rgba(255,255,255,.62);
  font-size: .72rem; font-weight: 500;
  letter-spacing: .14em; text-transform: uppercase;
  padding: .72rem .8rem;
  border-left: 2px solid transparent;
  transition: color .15s, background .15s, border-color .15s;
}

.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.nav-item:hover { color: #fff; background: rgba(255,255,255,.05); }

.nav-item.active {
  color: var(--teal);
  background: rgba(7,170,165,.1);
  border-left-color: var(--teal);
  border-radius: 0 6px 6px 0;
}

.sidebar-foot {
  padding: 1rem 1.1rem 1.3rem;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
}

.user-chip { display: flex; align-items: center; gap: .6rem; min-width: 0; }

.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--teal); color: #fff;
  font-family: var(--font-ui); font-weight: 600; font-size: .8rem;
  display: grid; place-items: center; flex-shrink: 0;
}

.user-name {
  font-family: var(--font-ui); font-size: .78rem; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.logout {
  background: none; border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.7); border-radius: 5px;
  font-size: .65rem; letter-spacing: .1em; text-transform: uppercase;
  padding: .35rem .6rem;
  transition: color .15s, border-color .15s;
}

.logout:hover { color: #fff; border-color: var(--teal); }

/* ─────────────────────────── VISTAS ─────────────────────────── */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.view-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
  padding: 1.6rem 2.2rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.view-head h1 {
  font-family: var(--font-display); font-weight: 200;
  font-size: 1.9rem; color: var(--navy); line-height: 1.05;
}

.view-sub {
  font-size: .82rem; color: var(--muted); margin-top: .3rem;
}

.btn-ghost {
  background: none; border: 1px solid var(--line);
  color: var(--blue); border-radius: 6px;
  font-size: .7rem; font-weight: 500;
  letter-spacing: .12em; text-transform: uppercase;
  padding: .55rem .9rem; white-space: nowrap;
  text-decoration: none;
  transition: border-color .15s, color .15s, background .15s;
}

.btn-ghost:hover { border-color: var(--teal); color: var(--teal); }

.btn-ghost.small { padding: .35rem .7rem; font-size: .62rem; }

/* ─────────────────────────── CHAT ─────────────────────────── */

.messages {
  flex: 1; overflow-y: auto;
  padding: 1.6rem 2.2rem;
  display: flex; flex-direction: column; gap: 1rem;
}

.empty-state {
  margin: auto; text-align: center; color: var(--muted);
  font-size: .9rem; line-height: 1.6;
  animation: rise .5s ease both;
}

.empty-mark {
  width: 54px; height: 54px; margin: 0 auto .9rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--blue));
  color: #fff; font-family: var(--font-display); font-weight: 300;
  font-size: 1.6rem; display: grid; place-items: center;
}

.msg { display: flex; gap: .8rem; max-width: 780px; animation: msgIn .3s ease both; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; max-width: 640px; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center;
  font-family: var(--font-ui); font-weight: 600; font-size: .78rem;
  margin-top: 2px;
}

.msg.assistant .msg-avatar { background: linear-gradient(135deg, var(--teal), var(--blue)); color: #fff; }
.msg.user .msg-avatar { background: var(--navy); color: #fff; }

.msg-bubble {
  padding: .8rem 1.05rem;
  border-radius: 10px;
  font-size: .9rem; line-height: 1.62;
  min-width: 0;
}

.msg.user .msg-bubble {
  background: var(--navy); color: #fff;
  border-radius: 10px 3px 10px 10px;
  white-space: pre-wrap; word-break: break-word;
}

.msg.assistant .msg-bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--teal);
  border-radius: 3px 10px 10px 10px;
  box-shadow: var(--shadow-sm);
}

.msg-files {
  display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem;
}

.msg-files .chip {
  font-size: .7rem; font-family: var(--font-ui);
  background: rgba(255,255,255,.14); color: #fff;
  border-radius: 4px; padding: .2rem .5rem;
}

.caret {
  display: inline-block; width: 8px; height: 1em;
  background: var(--teal); vertical-align: text-bottom;
  margin-left: 2px; animation: blink .9s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.msg-error { color: var(--danger); font-size: .85rem; }

/* composer */

.composer {
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: .8rem 2.2rem 1.1rem;
}

.attach-chips { display: flex; flex-wrap: wrap; gap: .4rem; }

.attach-chips .chip {
  display: inline-flex; align-items: center; gap: .45rem;
  font-family: var(--font-ui); font-size: .72rem;
  background: rgba(7,170,165,.1); color: var(--teal-dark);
  border: 1px solid rgba(7,170,165,.3);
  border-radius: 5px; padding: .3rem .6rem; margin-bottom: .5rem;
}

.attach-chips .chip button {
  background: none; border: none; color: inherit; font-size: .8rem; line-height: 1;
}

.composer-row {
  display: flex; align-items: flex-end; gap: .6rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .5rem .6rem;
  transition: border-color .15s, box-shadow .15s;
}

.composer-row:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(7,170,165,.12);
}

#chat-input {
  flex: 1; resize: none; border: none; background: none;
  font-family: var(--font-body); font-size: .92rem; line-height: 1.5;
  color: var(--ink); padding: .45rem .2rem;
  max-height: 180px;
}

#chat-input:focus { outline: none; }

.icon-btn {
  background: none; border: none; color: var(--muted);
  width: 38px; height: 38px; border-radius: 8px;
  display: grid; place-items: center; flex-shrink: 0;
  transition: color .15s, background .15s;
}

.icon-btn svg { width: 19px; height: 19px; }

.icon-btn:hover { color: var(--teal); background: rgba(7,170,165,.08); }

.send-btn {
  background: var(--teal); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 9px;
  display: grid; place-items: center; flex-shrink: 0;
  transition: background .15s, transform .15s;
}

.send-btn svg { width: 19px; height: 19px; }

.send-btn:hover { background: var(--teal-dark); transform: translateY(-1px); }

.send-btn:disabled { background: var(--line); color: var(--muted); transform: none; }

/* ─────────────── markdown dentro de burbujas y modal ─────────────── */

.md h1, .md h2, .md h3, .md h4 {
  font-family: var(--font-display); font-weight: 300;
  color: var(--navy); margin: 1.1em 0 .45em; line-height: 1.25;
}

.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.28em; }
.md h3 { font-size: 1.12em; } .md h4 { font-size: 1em; font-weight: 400; }

.md p { margin: .55em 0; }
.md ul, .md ol { margin: .55em 0 .55em 1.4em; }
.md li { margin: .25em 0; }
.md strong { color: var(--navy); }
.md a { color: var(--blue); }
.md hr { border: none; border-top: 1px solid var(--line); margin: 1em 0; }

.md blockquote {
  border-left: 3px solid var(--teal);
  padding: .2em .9em; margin: .7em 0;
  color: var(--muted); background: rgba(7,170,165,.05);
}

.md code {
  font-family: 'Consolas', 'Menlo', monospace; font-size: .84em;
  background: rgba(0,37,69,.07); border-radius: 4px; padding: .12em .4em;
}

.md pre {
  background: var(--navy-deep); color: #d8e4ee;
  border-radius: 8px; padding: .9em 1.1em; overflow-x: auto; margin: .7em 0;
}

.md pre code { background: none; padding: 0; color: inherit; }

.md table {
  border-collapse: collapse; margin: .8em 0; font-size: .92em;
  display: block; overflow-x: auto; max-width: 100%;
}

.md th {
  font-family: var(--font-ui); font-weight: 500; font-size: .78em;
  letter-spacing: .08em; text-transform: uppercase;
  background: var(--navy); color: #fff;
  padding: .5em .8em; text-align: left;
}

.md td { border-bottom: 1px solid var(--line); padding: .5em .8em; }
.md tr:nth-child(even) td { background: rgba(0,37,69,.03); }

/* ─────────────────────── ENTREGABLES ─────────────────────── */

.ent-list {
  flex: 1; overflow-y: auto;
  padding: 1.6rem 2.2rem;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: .9rem; align-content: start;
}

.ent-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: .55rem;
  transition: transform .15s, box-shadow .15s, border-color .15s;
  animation: msgIn .3s ease both;
}

.ent-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: rgba(7,170,165,.4);
}

.ent-top { display: flex; align-items: center; gap: .6rem; min-width: 0; }

.ent-ext {
  font-family: var(--font-ui); font-weight: 600; font-size: .6rem;
  letter-spacing: .08em; color: #fff; background: var(--blue);
  border-radius: 4px; padding: .25rem .45rem; flex-shrink: 0;
}

.ent-ext.md { background: var(--teal); }

.ent-name {
  font-family: var(--font-ui); font-weight: 500; font-size: .85rem;
  color: var(--navy); word-break: break-all;
}

.ent-meta { font-size: .72rem; color: var(--muted); }

.ent-meta .folder { color: var(--teal-dark); font-weight: 600; }

.ent-actions { display: flex; gap: .45rem; margin-top: .2rem; }

.ent-empty, .hist-empty {
  grid-column: 1 / -1; text-align: center; color: var(--muted);
  font-size: .88rem; padding: 3rem 1rem; line-height: 1.6;
}

/* ─────────────────────── HISTORIAL ─────────────────────── */

.hist-list { flex: 1; overflow-y: auto; padding: 1.2rem 2.2rem; }

.hist-item {
  width: 100%; text-align: left;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 8px;
  padding: .9rem 1.2rem; margin-bottom: .6rem;
  font-family: var(--font-body);
  transition: border-color .15s, transform .15s, box-shadow .15s;
  animation: msgIn .3s ease both;
}

.hist-item:hover {
  border-color: rgba(7,170,165,.5);
  transform: translateX(3px);
  box-shadow: var(--shadow-sm);
}

.hist-title {
  font-size: .9rem; color: var(--ink); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.hist-meta { font-size: .72rem; color: var(--muted); flex-shrink: 0; text-align: right; }

/* ─────────────────────── MODAL ─────────────────────── */

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 21, 38, .55);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  animation: fadeIn .2s ease both;
}

@keyframes fadeIn { from { opacity: 0; } }

.modal-card {
  width: min(860px, calc(100vw - 2.5rem));
  max-height: calc(100vh - 4rem);
  background: var(--card); border-radius: 10px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: rise .3s cubic-bezier(.22,1,.36,1) both;
}

.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.4rem; border-bottom: 1px solid var(--line);
}

.modal-title {
  font-family: var(--font-ui); font-weight: 500; font-size: .9rem; color: var(--navy);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.modal-actions { display: flex; align-items: center; gap: .5rem; }

.modal-body {
  overflow-y: auto; padding: 1.4rem 1.8rem 2rem;
  font-size: .92rem; line-height: 1.65;
}

/* ─────────────────────── RESPONSIVE ─────────────────────── */

@media (max-width: 860px) {
  .sidebar { width: 74px; }
  .sidebar-brand img, .sidebar-product, .user-name, .logout { display: none; }
  .sidebar-brand { padding: 1.2rem .9rem .4rem; }
  .sidebar-brand::before {
    content: "414"; font-family: var(--font-display); font-weight: 300;
    color: #fff; font-size: 1.1rem;
  }
  .nav-item { justify-content: center; padding: .8rem .4rem; font-size: 0; gap: 0; }
  .nav-item svg { width: 20px; height: 20px; }
  .view-head, .messages, .composer, .ent-list, .hist-list { padding-left: 1.1rem; padding-right: 1.1rem; }
}

/* scrollbars discretos */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(0,37,69,.18); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,37,69,.32); }
