/* =========================================================
   Ёж Лориен — style.css (LIGHT / CLEAN / STABLE)
   - One theme only (no neon)
   - Predictable layout
   - Chat scrolls inside #chat-window (not body)
   - Sticky input row
   - Mobile drawer sidebar
   - color-card protected (state snapshot)
   ========================================================= */

/* === Reset === */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

html{
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

body{
  margin: 0;
  background: #F7F8FA;
  color: #111827;
  line-height: 1.55;

  /* ВАЖНО: чтобы не скроллилась страница вместо чата */
  overflow: hidden;
}

/* === Tokens === */
:root{
  --bg: #F7F8FA;
  --card: #FFFFFF;
  --text: #111827;
  --muted: rgba(17,24,39,.65);
  --border: #E5E7EB;
  --text-on-dark: #F9FAFB; /* белый, но мягкий */
  --accent: #4A6CF7;
  --accent-weak: rgba(74,108,247,.12);

  --shadow: 0 10px 28px rgba(17,24,39,.08);

  --r-card: 18px;
  --r-btn: 14px;

  --fs-title: 20px;
  --fs-base: 16px;
  --fs-chat: 15px;
  --fs-small: 14px;
  
}

/* =========================================================
   Layout
   ========================================================= */

/* wrapper занимает весь экран и не даёт body скроллиться */
.lp-wrapper{
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;

  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 16px;
}

/* =========================================================
   Left column
   ========================================================= */
.lp-left{
  min-width: 0;
  height: calc(100vh - 32px);
  overflow: auto;
}

.brand-card{
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);

  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand-avatar{
  position: relative;
  width: 110px;
  height: 110px;
  margin: 0 auto 6px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
}

.avatar-glow{
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, rgba(74,108,247,.22), transparent 60%);
  pointer-events: none;
}

.brand-logo{
  position: relative;
  z-index: 1;
  max-width: 78px;
  max-height: 78px;
  border-radius: 14px;
}

.brand-title{
  margin: 0;
  font-size: var(--fs-title);
  font-weight: 800;
  line-height: 1.2;
}

.brand-subtitle{
  margin: 0;
  font-size: var(--fs-small);
  color: var(--muted);
}

.brand-text{
  margin: 0;
  font-size: var(--fs-chat);
  color: var(--text);
}

.brand-tags{
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.brand-tags span{
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: #F3F4F6;
  border: 1px solid var(--border);
  color: var(--text);
}

.brand-actions{ margin-top: 8px; }
.chat-presets{ display: grid; gap: 10px; }

/* =========================================================
   Right column (Chat)
   ========================================================= */
.lp-right{
  min-width: 0;
  height: calc(100vh - 32px);

  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);

  padding: 16px;

  display: flex;
  flex-direction: column;
  overflow: hidden; /* важно, чтобы скролл был внутри #chat-window */
}

/* Header */
.chat-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--card);
}

.chat-title{
  font-weight: 800;
  font-size: 18px;
  line-height: 1.2;
}

.chat-subtitle{
  font-size: var(--fs-small);
  color: var(--muted);
  margin-top: 2px;
}

.chat-status{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.dot-online{
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22C55E;
}

/* Chat window scroll container */
#chat-window{
  flex: 1 1 auto;
  min-height: 0;          /* КРИТИЧНО для overflow в flex */
  overflow-y: auto;
  overscroll-behavior: contain;

  margin: 10px 0;
  padding: 12px;

  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--card);
}

/* scrollbar */
#chat-window::-webkit-scrollbar{ width: 8px; }
#chat-window::-webkit-scrollbar-track{ background: transparent; }
#chat-window::-webkit-scrollbar-thumb{
  background: rgba(17,24,39,.18);
  border-radius: 999px;
}

/* Messages */
.msg-row{
  display: flex;
  margin-bottom: 6px;
  align-items: flex-start;
}

.msg-row.user{ justify-content: flex-end; }
.msg-row.bot{ justify-content: flex-start; }

.msg-avatar{
  width: 42px;
  height: 42px;
  border-radius: 12px;
  margin-right: 10px;
  object-fit: cover;
}

.msg-bubble{
  max-width: 75%;
  padding: 10px 12px;
  border-radius: 16px;

  font-size: var(--fs-chat);
  line-height: 1.45;
  white-space: pre-wrap;

  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--text);
}

.msg-row.user .msg-bubble{
  background: var(--accent-weak);
  border-color: rgba(74,108,247,.20);
}

/* Topic links: НЕ синие (не отвлекают) */
.msg-bubble .lorien-topic-link{
  display: block;
  padding: 2px 0;
  line-height: 1.25;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  color: var(--text);
}
.msg-bubble .lorien-topic-link:hover{ text-decoration: underline; }
.msg-bubble .lorien-topic-link b{ font-weight: 800; }
.msg-bubble .lorien-topic-short{ color: var(--muted); font-weight: 400; }

/* =========================================================
   Input row (sticky bottom)
   ========================================================= */
.chat-input-row{
  flex: 0 0 auto;

  position: sticky;
  bottom: 0;
  z-index: 50;

  display: flex;
  align-items: flex-end;
  gap: 10px;

  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));

  border-radius: 16px;
}

.chat-input{
  flex: 1;
  resize: none;

  min-height: 48px;
  max-height: 160px;
  overflow-y: auto;

  font-size: var(--fs-base);
  line-height: 1.45;

  padding: 12px 14px;
  border-radius: 14px;

  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  outline: none;
}

.chat-input::placeholder{ color: rgba(17,24,39,.40); }

.chat-input:focus{
  border-color: rgba(74,108,247,.55);
  box-shadow: 0 0 0 4px rgba(74,108,247,.12);
}

/* Hint */
.chat-hint{
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  text-align: right;
}

/* =========================================================
   Buttons
   - sidebar/action buttons: calm (white)
   - send button: accent (only one)
   ========================================================= */

/* Base button shape */
.pill-btn,
.lorien-action-btn,
.preset-btn,
.send-btn{
  height: 48px;
  padding: 0 16px;
  border-radius: var(--r-btn);
  font-size: 14px;       /* на 1–2 пункта меньше */
  font-weight: 500;

  border: 1px solid transparent;
  cursor: pointer;

  transition: background .15s ease, color .15s ease, box-shadow .15s ease, transform .08s ease;
}

/* Secondary (default): calm */
.pill-btn,
.preset-btn,
.lorien-action-btn{
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.pill-btn:hover,
.preset-btn:hover,
.lorien-action-btn:hover{
  background: #F3F4F6;
}

.pill-btn:active,
.preset-btn:active,
.lorien-action-btn:active{
  background: #E5E7EB;
}

/* Send: primary accent */
.send-btn{
  width: 48px;
  padding: 0;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  font-size: 18px;

  background: var(--accent);
  color: #fff;
  border: 1px solid rgba(0,0,0,0);
  box-shadow: 0 10px 20px rgba(17,24,39,.12);
}

.send-btn:active{
  transform: translateY(1px);
  box-shadow: 0 6px 12px rgba(17,24,39,.10);
}
/* Убираем подчёркивание у кнопок-ссылок */
a.pill-btn,
a.preset-btn {
  text-decoration: none;
}
a.pill-btn:hover,
a.pill-btn:focus,
a.preset-btn:hover,
a.preset-btn:focus {
  text-decoration: none;
}
/* Унификация кнопок: текст всегда по центру */
button,
a.pill-btn,
a.preset-btn,
.pill-btn,
.preset-btn,
.lorien-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
button,
a.pill-btn,
a.preset-btn {
  font-weight: 500;
}


/* =========================================================
   Mobile drawer sidebar
   JS toggles: body.sidebar-open
   Overlay: .mvp-overlay (created by JS)
   Menu btn: .mvp-menu-btn (inserted into .chat-header)
   ========================================================= */
.mvp-overlay{
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.25);
  z-index: 900;
}

.mvp-menu-btn{
  height: 40px;
  min-width: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: none;
  margin-right: 10px;
}
#preset-buttons.hidden { display: none !important; }

/* Mobile layout */
@media (max-width: 768px){
  body{ overflow: hidden; }

.lp-wrapper{
  height: 100svh;
  min-height: 100svh;
  max-width: 100%;
  padding: 8px;
  gap: 8px;
  grid-template-columns: 1fr;
}

.lp-right{
  height: 100svh;
  min-height: 0;
  padding: 10px;
}


  /* Drawer left */
  .lp-left{
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 86vw;
    max-width: 360px;
    z-index: 1000;

    transform: translateX(-105%);
    transition: transform 0.22s ease;

    background: #fff;
    border-right: 1px solid var(--border);
    box-shadow: 0 12px 30px rgba(0,0,0,0.12);

    overflow-y: auto;
    padding: 12px;
  }

  body.sidebar-open .mvp-overlay{ display: block; }
  body.sidebar-open .lp-left{ transform: translateX(0); }
}

/* Desktop: ensure drawer styles do not leak */
@media (min-width: 769px){
  body.sidebar-open .mvp-overlay{ display: none; }
  .mvp-overlay{ display: none; }

  .lp-left{
    position: static;
    height: calc(100vh - 32px);
    width: auto;
    max-width: none;
    transform: none;
    transition: none;
    z-index: auto;
    box-shadow: none;
    border-right: none;
    overflow: auto;
    padding: 0;
  }
}
/* =========================================================
    блок вверху рядом с названием
   ========================================================= */
.brand-title-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}

   
   
   
/* =========================================================
   State snapshot protection (color cards)
   ========================================================= */

/* Не даём общим стилям кнопок убить градиенты */
.color-card{
  background: linear-gradient(160deg, var(--c1), var(--c2)) !important;
}

.bot-message,
.chat-message.bot,
.chat-bubble.bot {
  color: #f7f8fa;
}
/* Big test intro — text on dark background */
.lorien-bigtest-intro,
.lorien-bigtest-intro * {
  color: var(--text-on-dark);
}
/* FIX: bigtest card — сделать фон светлым */
.msg-row.bot .msg-bubble .lorien-bigtest-intro{
  background: var(--card) !important;
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text);
}
.msg-row.bot .msg-bubble{ background: var(--card); }
/* Big test card — text on light background */
.msg-row.bot .msg-bubble .lorien-bigtest-intro,
.msg-row.bot .msg-bubble .lorien-bigtest-intro * {
  color: var(--text);
}
/* =========================================================
   Side panel (Balance / Menu / Tools)
   ========================================================= */
   
/* FIX: прокрутка контента на инфо-страницах (баланс/программы/инструменты) */
.lp-right {
  min-height: 0;
}

.lp-right .chat-window {
  overflow-y: auto;
  min-height: 0;
}
/* новые правила для экрана мобильного  */
/* === MOBILE DRAWER FIX (FULL HEIGHT + SCROLL) === */

@media (max-width: 768px){

  /* корректная высота экрана */
  body.sidebar-open {
    height: 100dvh;
    overflow: hidden;
  }

  /* overlay — на весь экран */
  .mvp-overlay {
    inset: 0;
    height: 100dvh;
  }

  /* drawer меню */
  .lp-left{
    top: 0;
    bottom: 0;                 /* КЛЮЧ */
    height: 100dvh;            /* КЛЮЧ */
    max-height: 100dvh;
    overflow-y: auto;          /* КЛЮЧ */
    -webkit-overflow-scrolling: touch;

    padding-bottom: calc(
      16px + env(safe-area-inset-bottom)
    );                          /* iPhone safe-area */
  }


}

/* oracul*/
/* FIX: hidden должен убирать клики тоже */
.hidden{display:none !important; pointer-events:none !important;}

/* === FIX: ORACLE MODAL classes match HTML (oracle-*) === */
.oracle-modal{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.55);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:9999;
}
.oracle-modal.hidden{
  display:none !important;
  pointer-events:none !important;
}
.oracle-card{
  max-width:520px;
  width:92%;
  background:#111;
  border-radius:16px;
  padding:18px;
  box-shadow:0 12px 40px rgba(0,0,0,.35);
  color:#f7f8fa;
}
/* === Library mobile scroll fix === */
body.library-screen{
  overflow-y: auto;
  overflow-x: hidden;
  height: auto;
  min-height: 100dvh;
}

body.library-screen .library-page{
  min-height: 100dvh;
}

@media (max-width: 768px){
  body.library-screen{
    overflow-y: auto;
    overflow-x: hidden;
    height: auto;
    min-height: 100dvh;
  }

  body.library-screen .library-page{
    min-height: 100dvh;
  }
}

.oracle-title{font-size:18px;margin-bottom:10px;}
.oracle-text{font-size:16px;line-height:1.5;margin-bottom:12px;}
.oracle-sub{opacity:.7;font-size:13px;margin-bottom:12px;}

/* (оставлено как было — если где-то используются .modal классы) */
.modal{position:fixed;inset:0;background:rgba(0,0,0,.55);display:flex;align-items:center;justify-content:center;z-index:9999;}
.modal-card{max-width:520px;width:92%;background:#111;border-radius:16px;padding:18px;box-shadow:0 12px 40px rgba(0,0,0,.35);}
.modal-title{font-size:18px;margin-bottom:10px;}
.modal-text{font-size:16px;line-height:1.5;margin-bottom:12px;}
.modal-sub{opacity:.7;font-size:13px;margin-bottom:12px;}
/* ===== FIX: Library modal — white background ===== */
/* =========================================================
   Library cards — cover fix
   ========================================================= */

.library-card{
  display: flex;
  gap: 16px;
  align-items: stretch;
  overflow: hidden;
}

.library-card-cover{
  width: 140px;
  min-width: 140px;
  height: 190px;
  border-radius: 14px;
  overflow: hidden;
  background: #E5E7EB;
  flex-shrink: 0;
}

.library-card-cover img{
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center;
}

.library-card-body{
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.library-card-title{
  margin: 0 0 8px;
  line-height: 1.2;
}

.library-card-excerpt{
  margin: 0 0 10px;
  color: var(--muted);
}

.library-card-actions{
  margin-top: auto;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 768px){
  .library-card{
    flex-direction: column;
  }

  .library-card-cover{
    width: 100%;
    min-width: 100%;
    height: 220px;
    border-radius: 14px;
  }
}

#libModal .oracle-card{
  background: #ffffff !important;
  color: #111827 !important;
}

#libModal .oracle-title,
#libModal .oracle-text,
#libModal .oracle-sub{
  color: #111827 !important;
}