/* ===== Paleta ShackleChat ===== */
:root {
  --pink:   #F294C0;
  --blue:   #495F8C;
  --orange: #D95436;
  --red:    #BF5A50;

  --primary: #4f6fb3;          /* azul de acción (botones) */
  --primary-soft: #eaf0fb;
  --primary-ink: #2f3f63;

  --bg:      #eef2f8;
  --panel:   #ffffff;
  --ink:     #1f2733;
  --muted:   #8b95a7;
  --line:    #e7ecf4;
  --hover:   #f3f6fc;
  --active:  #e7eefb;

  --radius:  14px;
  --shadow:  0 1px 3px rgba(28,44,80,.06), 0 8px 30px rgba(28,44,80,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
svg { width: 18px; height: 18px; }
.icon-btn svg, .search-box svg, .send-btn svg, .account-chip svg {
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ===================== LOGIN ===================== */
.login-view {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #f7e3ec 0%, var(--bg) 55%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 34px 30px 30px;
  text-align: center;
}
.login-logo { width: 76px; height: 76px; }
.login-card h1 { margin: 6px 0 2px; font-size: 26px; letter-spacing: -.4px; }
.login-sub { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin: 0 0 18px; }
.login-card form { text-align: left; display: flex; flex-direction: column; }
.login-card label { font-size: 12.5px; color: var(--primary-ink); font-weight: 600; margin: 12px 0 6px; }
.login-card input {
  height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.btn-primary {
  margin-top: 20px; height: 46px; border: 0; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: filter .15s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.login-msg { margin-top: 12px; font-size: 13px; color: var(--orange); min-height: 18px; text-align: center; }

/* ===================== APP SHELL ===================== */
.app-view { display: flex; height: 100vh; overflow: hidden; }

/* ----- Sidebar ----- */
.sidebar {
  width: 300px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 16px 14px;
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 4px 6px 14px; }
.sidebar-logo { width: 30px; height: 30px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -.3px; }

.btn-newchat {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--primary); font-weight: 600; font-size: 15px;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.btn-newchat:hover { background: var(--primary-soft); border-color: #d7e2f6; }
.btn-newchat .plus { font-size: 20px; line-height: 1; font-weight: 700; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 0 6px; padding: 0 12px; height: 42px;
  background: var(--hover); border-radius: 12px; color: var(--muted);
}
.search-box input { border: 0; background: transparent; outline: none; flex: 1; font-size: 13.5px; color: var(--ink); }

.conv-list { flex: 1; overflow-y: auto; margin: 8px -4px 0; padding: 0 4px; }
.conv-group-label {
  font-size: 12px; font-weight: 700; color: var(--ink);
  padding: 14px 8px 6px;
}
.conv-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  color: #44506a; position: relative; transition: background .12s;
}
.conv-item:hover { background: var(--hover); }
.conv-item.active { background: var(--active); }
.conv-item.dragging { opacity: .4; }
.conv-item.drag-over { box-shadow: inset 0 2px 0 var(--primary); }
.conv-item .bubble {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 9px;
  display: grid; place-items: center; background: var(--primary-soft); color: var(--primary);
}
.conv-item.active .bubble { background: #fff; }
.conv-item .meta { flex: 1; min-width: 0; }
.conv-item .title {
  font-size: 13.5px; font-weight: 500; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item .time { font-size: 11.5px; color: var(--muted); }
.conv-item .kebab {
  opacity: 0; border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 18px; padding: 0 4px; line-height: 1; flex-shrink: 0;
}
.conv-item:hover .kebab, .conv-item.active .kebab { opacity: 1; }

.reorder-hint {
  margin-top: 8px; padding: 11px; border: 1px dashed var(--line); border-radius: 12px;
  text-align: center; color: var(--muted); font-size: 12.5px; user-select: none;
}
.reorder-hint .grip { margin-right: 6px; }

/* ----- Main ----- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.topbar {
  height: 64px; flex-shrink: 0; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 22px;
}
.topbar-title { font-weight: 600; font-size: 15px; color: var(--ink); }
.topbar-actions { display: flex; align-items: center; gap: 8px; position: relative; }
.icon-btn {
  width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); cursor: pointer; display: grid; place-items: center; transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.active { background: var(--primary-soft); color: var(--primary); }
.account-chip {
  width: 38px; height: 38px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; cursor: pointer; margin-left: 4px;
}
.account-menu {
  position: absolute; top: 48px; right: 0; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 12px; min-width: 180px;
}
.account-menu .account-name { font-size: 13px; color: var(--muted); padding: 4px 6px 10px; border-bottom: 1px solid var(--line); margin-bottom: 8px; word-break: break-all; }
.account-menu button {
  width: 100%; height: 38px; border: 0; border-radius: 8px; cursor: pointer;
  background: transparent; color: var(--orange); font-weight: 600; font-size: 13.5px;
}
.account-menu button:hover { background: #fdeee9; }
.account-menu button.menu-link { color: var(--primary); }
.account-menu button.menu-link:hover { background: var(--primary-soft); }

/* ----- Modal de perfil ----- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(28, 44, 80, .38);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: 100%; max-width: 540px; max-height: 86vh; overflow-y: auto;
  background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); padding: 22px 24px 20px;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
.modal-account { display: flex; gap: 12px; align-items: center; }
.modal-avatar { width: 46px; height: 46px; border-radius: 13px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; }
.modal-avatar svg { width: 24px; height: 24px; }
.modal-title { font-size: 18px; font-weight: 700; }
.modal-sub { font-size: 13px; color: var(--muted); word-break: break-all; }
.modal-close { border: 0; background: transparent; font-size: 18px; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.modal-close:hover { background: var(--hover); color: var(--ink); }

.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px; }
.profile-stat { background: var(--hover); border-radius: 12px; padding: 12px; text-align: center; }
.profile-stat .num { font-size: 21px; font-weight: 700; color: var(--primary-ink); }
.profile-stat .lbl { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.profile-section-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 10px; }
.profile-shares { display: flex; flex-direction: column; gap: 6px; }
.share-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px;
}
.share-row.no-access { opacity: .72; background: #fbfcfe; }
.share-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.share-row.access .share-icon { background: #e7f5ee; color: #2e9e6b; }
.share-row.no-access .share-icon { background: #f3f0ee; color: var(--red); }
.share-icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.share-main { flex: 1; min-width: 0; }
.share-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.share-count { font-size: 12px; color: var(--muted); }
.share-badge { font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.share-row.access .share-badge { background: #e7f5ee; color: #2e9e6b; }
.share-row.no-access .share-badge { background: #f6ece9; color: var(--red); }
.profile-note { font-size: 12px; color: var(--muted); margin-top: 16px; line-height: 1.5; }
.profile-loading { text-align: center; color: var(--muted); padding: 24px; }

/* ----- Chat ----- */
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 26px clamp(16px, 8vw, 120px); }
.msg { display: flex; gap: 14px; margin-bottom: 22px; max-width: 880px; }
.msg .avatar {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 11px;
  display: grid; place-items: center; overflow: hidden;
}
.msg.assistant .avatar { background: var(--primary-soft); }
.msg.assistant .avatar img { width: 30px; height: 30px; }
.msg .bubble-text {
  background: var(--hover); border-radius: 14px; padding: 13px 16px;
  font-size: 14.5px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word;
}
/* Markdown renderizado (respuestas del bot) */
.bubble-text.markdown { white-space: normal; }
.bubble-text.markdown p { margin: 0 0 10px; }
.bubble-text.markdown p:last-child { margin-bottom: 0; }
.bubble-text.markdown strong { font-weight: 700; color: var(--ink); }
.bubble-text.markdown em { font-style: italic; }
.bubble-text.markdown ul, .bubble-text.markdown ol { margin: 6px 0 10px; padding-left: 22px; }
.bubble-text.markdown li { margin: 3px 0; }
.bubble-text.markdown h1, .bubble-text.markdown h2,
.bubble-text.markdown h3, .bubble-text.markdown h4 { margin: 12px 0 6px; line-height: 1.3; }
.bubble-text.markdown h1 { font-size: 19px; }
.bubble-text.markdown h2 { font-size: 17px; }
.bubble-text.markdown h3 { font-size: 15.5px; }
.bubble-text.markdown h4 { font-size: 14.5px; }
.bubble-text.markdown code {
  background: rgba(28,44,80,.07); border-radius: 5px; padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
}
.bubble-text.markdown a { color: var(--primary); }
.bubble-text.markdown .cite {
  display: inline-block; font-size: 11.5px; font-weight: 600; color: var(--primary);
  background: var(--primary-soft); border-radius: 5px; padding: 0 5px; margin: 0 1px;
  vertical-align: baseline;
}
.msg.user { flex-direction: row-reverse; margin-left: auto; }
.msg.user .avatar { background: var(--blue); color: #fff; }
.msg.user .bubble-text { background: var(--primary); color: #fff; }
.msg .col { min-width: 0; max-width: 100%; }
.msg.user .col { display: flex; flex-direction: column; align-items: flex-end; }

.sources { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.sources .src-title { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.src {
  font-size: 12.5px; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: #fff;
}
.src .src-path { font-weight: 600; color: var(--primary-ink); word-break: break-all; }
.src-link { color: var(--primary); text-decoration: none; }
.src-link:hover { text-decoration: underline; }
.src-ext { font-size: 11px; margin-left: 3px; opacity: .7; }
.src .src-meta { color: var(--muted); }
.src .src-prev { color: #5a6577; margin-top: 3px; }

.typing span {
  display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%;
  background: var(--muted); animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* Empty state */
.empty-state { height: 100%; display: grid; place-items: center; text-align: center; color: var(--muted); }
.empty-state img { width: 92px; height: 92px; opacity: .95; }
.empty-state h3 { margin: 16px 0 6px; color: var(--ink); font-size: 19px; }
.empty-state p { margin: 0; font-size: 14px; }

/* Composer */
.composer { padding: 14px clamp(16px, 8vw, 120px) 20px; border-top: 1px solid var(--line); }
.composer-inner {
  display: flex; align-items: flex-end; gap: 10px;
  border: 1px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 16px;
  background: var(--panel); box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s;
}
.composer-inner:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
#chat-input {
  flex: 1; border: 0; outline: none; resize: none; font-family: var(--font);
  font-size: 14.5px; line-height: 1.5; max-height: 180px; padding: 8px 0; background: transparent; color: var(--ink);
}
.send-btn {
  width: 42px; height: 42px; flex-shrink: 0; border: 0; border-radius: 12px;
  background: var(--primary); color: #fff; cursor: pointer; display: grid; place-items: center; transition: filter .15s;
}
.send-btn:hover { filter: brightness(1.07); }
.send-btn:disabled { opacity: .5; cursor: default; }
.send-btn svg { width: 20px; height: 20px; }
.composer-hint { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 8px; }

/* ----- Historial ----- */
.history-view { flex: 1; overflow-y: auto; padding: 26px clamp(16px, 6vw, 80px); }
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 14px; flex-wrap: wrap; }
.history-head h2 { margin: 0; font-size: 21px; }
.history-filters { display: flex; gap: 10px; }
.history-filters input, .history-filters select {
  height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font-size: 13.5px; outline: none; background: var(--panel); color: var(--ink);
}
.history-filters input:focus, .history-filters select:focus { border-color: var(--primary); }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.history-table td { padding: 14px 12px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
.history-table tr:hover td { background: var(--hover); }
.history-table .h-title { font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.history-table .h-title .bubble { width: 30px; height: 30px; border-radius: 9px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; flex-shrink: 0; }
.history-table .h-last { color: var(--muted); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-table .h-date { color: var(--muted); white-space: nowrap; }
.h-act { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; }
.history-empty { text-align: center; color: var(--muted); padding: 50px; }
.history-pager { display: flex; justify-content: center; gap: 6px; margin-top: 18px; }
.history-pager button {
  min-width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
  cursor: pointer; color: var(--ink); font-size: 13px;
}
.history-pager button.active { background: var(--primary-soft); border-color: #d7e2f6; color: var(--primary); font-weight: 600; }
.history-pager button:disabled { opacity: .4; cursor: default; }

/* ----- Menú contextual conversación ----- */
.conv-menu {
  position: fixed; z-index: 40; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 150px;
}
.conv-menu button { width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 7px; cursor: pointer; font-size: 13.5px; color: var(--ink); }
.conv-menu button:hover { background: var(--hover); }
.conv-menu button.danger { color: var(--orange); }

/* Scrollbars discretos */
.conv-list::-webkit-scrollbar, .messages::-webkit-scrollbar, .history-view::-webkit-scrollbar { width: 9px; }
.conv-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb, .history-view::-webkit-scrollbar-thumb { background: #d9e0ec; border-radius: 9px; }

/* ===================== RESPONSIVE ===================== */
/* Helpers ocultos en escritorio */
.hamburger, .sidebar-close { display: none; }
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.topbar-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-backdrop { display: none; }

/* Tablet / pantallas medianas */
@media (max-width: 1024px) {
  .sidebar { width: 260px; }
  .messages, .composer { padding-left: clamp(16px, 4vw, 60px); padding-right: clamp(16px, 4vw, 60px); }
  .history-view { padding-left: clamp(16px, 4vw, 40px); padding-right: clamp(16px, 4vw, 40px); }
}

/* Móvil: la sidebar pasa a ser un drawer deslizante */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
    width: 86vw; max-width: 320px;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 0 0 40px rgba(28, 44, 80, .18);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(28, 44, 80, .4); opacity: 0; pointer-events: none; transition: opacity .25s;
  }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .hamburger { display: grid; }
  .sidebar-close {
    display: grid; place-items: center; margin-left: auto;
    width: 32px; height: 32px; border: 0; background: transparent;
    color: var(--muted); font-size: 16px; cursor: pointer; border-radius: 8px;
  }
  .sidebar-close:hover { background: var(--hover); }

  .topbar { height: 58px; padding: 0 12px; }
  .topbar-title { font-size: 14px; }
  .messages { padding: 18px 14px; }
  .composer { padding: 10px 12px 14px; }
  .msg { gap: 10px; margin-bottom: 18px; }
  .msg .bubble-text { font-size: 14px; }
  .msg.user { max-width: 100%; }

  /* Historial: la tabla se apila en tarjetas */
  .history-view { padding: 18px 14px; }
  .history-head { flex-direction: column; align-items: stretch; }
  .history-filters { flex-direction: column; }
  .history-filters input, .history-filters select { width: 100%; }
  .history-table, .history-table thead, .history-table tbody,
  .history-table tr, .history-table td { display: block; width: 100%; }
  .history-table thead { display: none; }
  .history-table tr { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; padding: 8px 12px; }
  .history-table td { border: 0; padding: 5px 0; }
  .history-table .h-last { max-width: 100%; white-space: normal; }

  .account-menu { right: 4px; }
}

/* Móvil estrecho */
@media (max-width: 420px) {
  .brand { font-size: 16px; }
  .icon-btn, .account-chip { width: 34px; height: 34px; }
  .send-btn { width: 38px; height: 38px; }
  .login-card { padding: 26px 20px; }
  .composer-hint { font-size: 11px; }
}
