/* ============================================================
   Author.Today — Книжный помощник
   Premium Production Design System
   ============================================================ */

/* ---- Reset ---- */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{scroll-behavior:smooth}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  font-size:16px;line-height:1.5;color:#1e1b4b;
  background:#f3f1ee;
  -webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;
  min-height:100vh
}

/* ---- Design Tokens ---- */
:root{
  --pri:#6366f1;--pri-dark:#4f46e5;--pri-deep:#3730a3;
  --pri-glow:rgba(99,102,241,0.12);--pri-glow-2:rgba(99,102,241,0.25);
  --pri-light:#eef2ff;--pri-bg:rgba(99,102,241,0.06);
  --amber:#f59e0b;--amber-light:#fef3c7;
  --surface:#fff;--bg:#f3f1ee;--card:#faf9f7;
  --text:#1e1b4b;--text-secondary:#52525b;--text-muted:#a1a1aa;
  --border:#e5e2dd;--border-light:#f0eeeb;
  --shadow-xs:0 1px 2px rgba(30,27,75,0.04);
  --shadow-sm:0 2px 4px rgba(30,27,75,0.05);
  --shadow-md:0 4px 14px rgba(30,27,75,0.07);
  --shadow-lg:0 8px 30px rgba(30,27,75,0.09);
  --shadow-xl:0 16px 48px rgba(30,27,75,0.11);
  --radius-sm:6px;--radius:10px;--radius-lg:16px;--radius-xl:22px;
  --header-h:64px;--transition:.2s cubic-bezier(.4,0,.2,1)
}

/* ---- Header ---- */
.site-header{
  position:sticky;top:0;z-index:50;
  height:var(--header-h);
  background:linear-gradient(135deg,#1e1b4b 0%,#3730a3 50%,#4f46e5 100%);
  display:flex;align-items:center;justify-content:space-between;
  padding:0 1.5rem;gap:1rem;
  box-shadow:0 2px 20px rgba(30,27,75,0.2);
}
.header-brand{min-width:0;display:flex;align-items:center;gap:0.85rem}
.header-brand .logo{
  width:32px;height:32px;flex-shrink:0;
  background:linear-gradient(135deg,#f59e0b,#fbbf24);
  border-radius:10px;display:flex;align-items:center;justify-content:center;
  font-size:16px;color:#78350f;font-weight:700;box-shadow:0 2px 8px rgba(245,158,11,0.35)
}
.header-brand h1{font-size:1.05rem;font-weight:700;color:#fff;letter-spacing:-0.02em}
.header-brand p{font-size:.7rem;color:rgba(255,255,255,0.5);line-height:1.3;margin-top:1px}
.btn-new-dialog{
  display:none;align-items:center;gap:.4rem;
  padding:.45rem .9rem;font-size:.75rem;font-weight:500;font-family:inherit;
  color:rgba(255,255,255,0.7);background:rgba(255,255,255,0.1);
  border:1px solid rgba(255,255,255,0.12);border-radius:var(--radius-sm);
  cursor:pointer;white-space:nowrap;backdrop-filter:blur(4px);
  transition:all var(--transition)
}
.btn-new-dialog:hover{color:#fff;background:rgba(255,255,255,0.18);border-color:rgba(255,255,255,0.2)}
.btn-new-dialog:active{transform:translateY(1px)}
.btn-new-dialog svg{width:13px;height:13px;flex-shrink:0}
.app.has-results .btn-new-dialog{display:flex}

/* ---- Layout ---- */
.app{min-height:calc(100vh - var(--header-h));display:flex;flex-direction:column}

/* Intro: centered chat */
.layout-intro{
  flex:1;display:flex;align-items:center;justify-content:center;
  padding:2rem 1rem 3rem;
  background:radial-gradient(ellipse at 50% 0%, rgba(99,102,241,0.04) 0%, transparent 60%);
}
.chat-shell{
  width:min(640px,100%);max-height:min(78vh,720px);min-height:440px;
  background:var(--surface);border-radius:var(--radius-xl);
  border:1px solid var(--border);box-shadow:var(--shadow-xl);
  display:flex;flex-direction:column;overflow:hidden;
}
.app.has-results .layout-intro{display:none}

/* Split layout */
.layout-split{
  display:none;flex:1;
  grid-template-columns:minmax(0,1.1fr) minmax(0,0.9fr);gap:0;
  width:100%;max-width:100%;min-height:calc(100vh - var(--header-h))
}
.app.has-results .layout-split{display:grid}

.results-pane{background:var(--surface);border-right:1px solid var(--border);display:flex;flex-direction:column;min-height:0}
.results-pane-header{
  padding:1rem 1.25rem .7rem;
  font-size:.65rem;font-weight:700;text-transform:uppercase;letter-spacing:.06em;
  color:var(--text-muted);border-bottom:1px solid var(--border-light);flex-shrink:0
}
.results-scroll{flex:1;overflow-y:auto;padding:.75rem 1.25rem 2rem;-webkit-overflow-scrolling:touch}
.results-scroll::-webkit-scrollbar{width:4px}
.results-scroll::-webkit-scrollbar-track{background:transparent}
.results-scroll::-webkit-scrollbar-thumb{background:#d4d4d8;border-radius:10px}

.chat-pane-split .chat-shell{
  max-height:none;min-height:calc(100vh - var(--header-h));
  border:none;border-radius:0;box-shadow:none;width:100%
}

/* ---- Messages Area ---- */
.messages{
  flex:1;overflow-y:auto;padding:1.25rem 1rem;
  display:flex;flex-direction:column;gap:.75rem;
  -webkit-overflow-scrolling:touch;scroll-behavior:smooth;
  background:linear-gradient(180deg,#f8f7f4 0%,var(--surface) 35%)
}
.messages::-webkit-scrollbar{width:4px}
.messages::-webkit-scrollbar-track{background:transparent}
.messages::-webkit-scrollbar-thumb{background:#d4d4d8;border-radius:10px}

/* ---- Bubbles ---- */
.bubble{
  max-width:82%;padding:.7rem 1rem;
  font-size:.9rem;line-height:1.55;
  animation:msgIn .35s cubic-bezier(.34,1.56,.64,1);position:relative
}
@keyframes msgIn{
  from{opacity:0;transform:translateY(12px) scale(.96)}
  to{opacity:1;transform:translateY(0) scale(1)}
}

/* User bubble — rich gradient */
.bubble.user{
  align-self:flex-end;
  background:linear-gradient(135deg,#6366f1 0%,#4f46e5 100%);
  color:#fff;border-radius:18px 18px 4px 18px;
  box-shadow:0 3px 12px rgba(99,102,241,0.25)
}

/* Assistant bubble — elevated card */
.bubble.assistant{
  align-self:flex-start;background:var(--surface);
  border:1px solid var(--border);border-radius:18px 18px 18px 4px;
  box-shadow:var(--shadow-sm)
}

.bubble.assistant .meta-line{
  font-size:.72rem;color:var(--text-muted);
  margin-bottom:.45rem;padding-bottom:.45rem;
  border-bottom:1px solid var(--border-light);
  display:flex;align-items:center;gap:.4rem;flex-wrap:wrap
}
.bubble.assistant .meta-line .dot{width:3px;height:3px;background:#d4d4d8;border-radius:50%;flex-shrink:0}

.bubble.assistant .intent-mini{
  font-size:.72rem;margin-top:.5rem;padding-top:.5rem;
  border-top:1px solid var(--border-light);color:var(--text-muted);line-height:1.5
}
.bubble.assistant .intent-mini strong{color:var(--text);font-weight:600}

.matched-mini{
  margin-top:.55rem;padding:.5rem .65rem;
  background:#ecfdf5;border-radius:var(--radius-sm);
  font-size:.72rem;border:1px solid #a7f3d0
}
.matched-mini .t{font-weight:600;color:#059669;margin-bottom:.15rem}

/* ---- Composer ---- */
.composer{
  padding:.85rem 1rem 1rem;
  background:var(--surface);flex-shrink:0;
  border-top:2px solid var(--border-light)
}
.composer-row{display:flex;gap:.5rem;align-items:center}
.composer textarea{
  flex:1;resize:none;min-height:44px;max-height:120px;
  padding:.65rem .85rem;font-size:.9rem;font-family:inherit;
  border:2px solid var(--border);border-radius:var(--radius);
  line-height:1.4;background:var(--card);
  transition:all var(--transition);color:var(--text)
}
.composer textarea:focus{
  outline:none;border-color:var(--pri);
  box-shadow:0 0 0 4px var(--pri-glow);background:var(--surface)
}
.composer textarea::placeholder{color:#a1a1aa}
.composer button{
  padding:.6rem 1.25rem;font-size:.85rem;font-weight:600;font-family:inherit;
  background:linear-gradient(135deg,#6366f1,#4f46e5);color:#fff;
  border:none;border-radius:var(--radius);cursor:pointer;white-space:nowrap;
  transition:all var(--transition);flex-shrink:0;
  box-shadow:0 3px 10px rgba(99,102,241,0.25);
  align-self:stretch;display:flex;align-items:center
}
.composer button:hover:not(:disabled){
  transform:translateY(-1px);box-shadow:0 5px 16px rgba(99,102,241,0.35)
}
.composer button:active:not(:disabled){transform:translateY(0)}
.composer button:disabled{opacity:.4;cursor:not-allowed;box-shadow:none}

/* ---- Welcome ---- */
.welcome{
  text-align:center;padding:3rem 1rem 1.5rem;color:var(--text-muted);font-size:.85rem;line-height:1.6
}
.welcome-icon{
  display:flex;align-items:center;justify-content:center;
  width:64px;height:64px;margin:0 auto .85rem;
  background:linear-gradient(135deg,#eef2ff,#f0f0ff);
  border-radius:18px;font-size:1.8rem;
  box-shadow:0 4px 14px rgba(99,102,241,0.1)
}

/* ---- Book Cards ---- */
.book{
  display:flex;gap:.85rem;padding:1rem;
  background:var(--card);border-radius:var(--radius);
  margin-bottom:.7rem;border:1px solid var(--border-light);
  transition:all var(--transition);cursor:default
}
.book:hover{border-color:var(--border);box-shadow:var(--shadow-md);transform:translateY(-1px)}
.cover{width:60px;height:90px;object-fit:cover;border-radius:5px;background:#e4e4e7;flex-shrink:0;box-shadow:0 1px 3px rgba(0,0,0,.08)}
.info{flex:1;min-width:0}
.title{font-weight:600;font-size:.85rem;margin:0 0 .1rem;color:var(--text)}
.title a{color:inherit;text-decoration:none}
.title a:hover{text-decoration:underline;color:var(--pri)}
.authors{color:var(--text-secondary);font-size:.72rem;margin:0 0 .3rem}
.annotation{color:var(--text-secondary);font-size:.72rem;line-height:1.45;margin:0 0 .5rem;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;transition:all .25s ease}
.annotation.expanded{-webkit-line-clamp:unset;overflow:visible}
.annotation-toggle{display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;font-size:.75rem;font-weight:500;color:var(--pri);cursor:pointer;padding:0;transition:color var(--transition),background-color .15s ease;background:none;border:none;font-family:inherit;border-radius:50%;flex-shrink:0;margin-left:auto}
.annotation-toggle:hover{color:var(--pri-dark);background:var(--pri-glow)}
.annotation-toggle svg{width:12px;height:12px;transition:transform .2s ease;flex-shrink:0}
.annotation-toggle.expanded svg{transform:rotate(180deg)}
.badges-footer{display:flex;align-items:center;gap:.25rem;flex-wrap:wrap;margin-top:.15rem}
.info{flex:1;min-width:0;display:flex;flex-direction:column}
.badges{display:flex;flex-wrap:wrap;gap:.25rem;align-items:center}
.badges{display:flex;flex-wrap:wrap;gap:.25rem;align-items:center}
.badge{display:inline-flex;padding:.15rem .4rem;border-radius:4px;font-size:.6rem;font-weight:600;line-height:1.35}
.badge-genre{background:#eef2ff;color:#4f46e5;font-size:.72rem;padding:.2rem .5rem}
.badge-llm{background:#f5f3ff;color:#7c3aed}

/* ---- Error / Empty ---- */
.error-state{
  color:#dc2626;padding:.7rem;background:#fef2f2;border-radius:var(--radius-sm);
  font-size:.82rem;border:1px solid #fecaca
}
.empty-state{
  color:var(--text-muted);text-align:center;
  padding:2.5rem 1rem;font-size:.82rem;line-height:1.5
}

/* ---- Typing ---- */
.typing{display:inline-flex;gap:5px;align-items:center;padding:.15rem 0}
.typing span{width:7px;height:7px;background:#a1a1aa;border-radius:50%;animation:bounce 1.3s infinite ease-in-out}
.typing span:nth-child(2){animation-delay:.15s}
.typing span:nth-child(3){animation-delay:.3s}
@keyframes bounce{0%,80%,100%{transform:scale(.55);opacity:.35}40%{transform:scale(1);opacity:1}}

/* ---- Slow indicator ---- */
.slow-indicator{display:block;margin-top:.5rem;font-size:.72rem;color:var(--text-muted);font-style:italic;animation:fadeIn .5s ease}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}

/* ---- Responsive ---- */
@media(max-width:767px){
  .site-header{padding:0 .85rem;height:56px}
  .header-brand p{display:none}
  .header-brand .logo{width:26px;height:26px;font-size:13px;border-radius:8px}
  .header-brand h1{font-size:.9rem}
  .btn-new-dialog{padding:.35rem .6rem;font-size:.68rem}
  .btn-new-dialog svg{width:11px;height:11px}
  .app:not(.has-results) .layout-intro{align-items:stretch;padding:0}
  .app:not(.has-results) .chat-shell{max-height:none;min-height:calc(100vh - 56px);border-radius:0;border-left:none;border-right:none;box-shadow:none}
  .app.has-results .layout-split{grid-template-columns:1fr;grid-template-rows:minmax(40vh,auto) 1fr}
  .results-pane{border-right:none;border-top:1px solid var(--border);order:2;min-height:35vh}
  .chat-pane-split{order:1;min-height:0}
  .chat-pane-split .chat-shell{min-height:min(45vh,400px);max-height:45vh}
  .messages{padding:.85rem .7rem;gap:.6rem}
  .bubble{max-width:90%;padding:.55rem .75rem;font-size:.85rem}
  .composer{padding:.65rem .7rem .85rem}
  .composer textarea{font-size:.85rem;padding:.5rem .65rem;min-height:40px}
  .composer button{padding:.5rem 1rem;font-size:.8rem}
  .results-scroll{padding:.5rem .85rem 1rem}
  .book{padding:.75rem;gap:.65rem}
}
@media(max-width:480px){
  .bubble{max-width:95%}
  .composer{padding:.5rem .6rem .75rem}
  .composer-row{gap:.35rem}
  .composer button{padding:.45rem .85rem}
}
