/* 7Дачный советник — styled after the 7dach.ru "banana" skin.
   Tokens pulled from templates/skin/banana/css/{base,buttons,common}.css:
   body 'PT Serif' 16px/22px #444, links #3A873F bold, titles #504b47 'PT Sans',
   primary button #439d48 → #5eb763, yellow #ffda52, khaki #e8e8c0 / #fefef1. */

:root {
  --green: #439d48;
  --green-hover: #5eb763;
  --link: #3a873f;
  --text: #444;
  --title: #504b47;
  --yellow: #ffda52;
  --yellow-hover: #f7ec76;
  --border: #d1d0be;
  --khaki: #e8e8c0;
  --bg: #fbfbf3;
  --sidebar-bg: #f5f5e6;
  --muted: #858481;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: 'PT Serif', serif;
  font-size: 16px;
  line-height: 22px;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--link);
  font-weight: bold;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.layout {
  display: flex;
  /* Mobile browsers compute 100vh with the address bar hidden, so the
     layout used to be taller than the visible viewport and the composer
     fell below the fold; dvh tracks the actually visible height. */
  height: 100vh;
  height: 100dvh;
}

/* ---------- sidebar ---------- */

.sidebar {
  width: 270px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--khaki);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  font-family: 'PT Sans', sans-serif;
}

.sidebar-top {
  display: flex;
  gap: 8px;
}

/* Mobile-only ✕ control: the open fixed sidebar covers the topbar's
   hamburger button, so the menu needs its own way to close. */
.sidebar-close {
  display: none;
  flex-shrink: 0;
  width: 40px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

/* Dimmed backdrop behind the open mobile sidebar; tap-to-close. */
.backdrop {
  display: none;
}

/* site .button_quaternary */
.new-chat {
  width: 100%;
  height: 34px;
  line-height: 30px;
  border: 2px solid var(--green);
  border-radius: 3px;
  background: #fff;
  color: #111;
  font-family: 'PT Sans', sans-serif;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
}

.new-chat:hover {
  background: var(--green);
  color: #fff;
}

.anon-hint {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  background: #fefef1;
  border: 1px solid var(--khaki);
  border-radius: 3px;
  padding: 8px 10px;
}

.conversations {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-item {
  text-align: left;
  padding: 7px 10px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text);
  font-family: 'PT Sans', sans-serif;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item:hover {
  background: #ececd8;
}

.conv-item.active {
  background: var(--khaki);
  font-weight: bold;
}

/* ---------- main ---------- */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--khaki);
  background: #fff;
}

/* site .mtitle */
.topbar h1 {
  font-family: 'PT Sans', sans-serif;
  font-size: 22px;
  font-weight: bold;
  color: var(--title);
  margin: 0;
}

.menu-toggle {
  display: none;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 3px;
  font-size: 18px;
  padding: 2px 10px;
  cursor: pointer;
}

.quota {
  margin-left: auto;
  font-family: 'PT Sans', sans-serif;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- messages ---------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.welcome {
  margin: auto;
  max-width: 560px;
  text-align: center;
  color: var(--text);
  font-size: 17px;
  line-height: 1.5;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: min(760px, 88%);
}

.msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble {
  padding: 10px 14px;
  border-radius: 8px;
  line-height: 1.55;
  font-size: 16px;
  overflow-wrap: break-word;
}

.msg-user .bubble {
  background: var(--green);
  color: #fff;
  border-bottom-right-radius: 3px;
  white-space: pre-wrap;
}

.msg-assistant .bubble {
  background: #fff;
  border: 1px solid var(--khaki);
  border-bottom-left-radius: 3px;
}

.bubble.thinking {
  color: var(--muted);
  font-style: italic;
}

.bubble p {
  margin: 0 0 0.6em;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble img {
  max-width: 100%;
  border-radius: 3px;
  border: 1px solid var(--khaki);
  display: block;
  margin: 8px 0;
  cursor: zoom-in;
}

.bubble pre {
  background: #f5f5e6;
  border: 1px solid var(--khaki);
  padding: 10px;
  border-radius: 3px;
  overflow-x: auto;
}

/* Suggested follow-up questions under an answer — site infobox look:
   #fefef1 with khaki border. */
.follow-ups {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.follow-up {
  text-align: left;
  padding: 8px 14px;
  border: 1px solid var(--khaki);
  border-radius: 3px;
  background: #fefef1;
  color: var(--link);
  font-family: 'PT Sans', sans-serif;
  font-size: 16px;
  cursor: pointer;
}

.follow-up:hover {
  border-color: var(--green);
  background: #fff;
}

/* Fallback illustration attached by ensureImage() when the answer text
   itself has no image. */
.auto-image {
  margin-top: 6px;
}

.auto-image img {
  max-width: 260px;
  border-radius: 3px;
  border: 1px solid var(--khaki);
  display: block;
}

/* Inline [n] citation links inside answers. */
.cite {
  color: #3a873f;
  font-weight: 600;
  font-size: 0.85em;
  vertical-align: super;
  line-height: 0;
  text-decoration: none;
}

.cite:hover {
  text-decoration: underline;
}

/* ---------- composer ---------- */

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--khaki);
  background: #fff;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 9px 12px;
  font-family: 'PT Sans', sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  max-height: 160px;
}

.composer textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(67, 157, 72, 0.25);
}

/* site .button_primary */
.composer button {
  border: none;
  border-radius: 3px;
  background: var(--green);
  color: #fff;
  font-family: 'PT Sans', sans-serif;
  font-size: 14px;
  font-weight: bold;
  padding: 0 20px;
  cursor: pointer;
}

.composer button:hover {
  background: var(--green-hover);
}

.composer button:disabled {
  background: #a9bf97;
  cursor: default;
}

/* ---------- banner ---------- */

/* site notice yellow */
.banner {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--yellow);
  border: 1px solid #e5c34a;
  color: #111;
  font-family: 'PT Sans', sans-serif;
  padding: 10px 18px;
  border-radius: 3px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 100;
  max-width: min(90vw, 560px);
}

/* PWA install offer: floating card above the composer. The sidebar (where
   such a button would normally live) is hidden behind ☰ on mobile, so the
   offer must live in the main viewport to be seen. */
.install-bar {
  position: fixed;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(92vw, 480px);
  padding: 8px 8px 8px 14px;
  background: #fff;
  border: 1px solid var(--khaki);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  font-family: 'PT Sans', sans-serif;
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
}

/* display:flex above would otherwise beat the hidden attribute's display:none
   (the bar stayed visible forever and ✕ appeared broken). */
.install-bar[hidden] {
  display: none;
}

.install-accept {
  flex-shrink: 0;
  border: none;
  border-radius: 3px;
  background: var(--green);
  color: #fff;
  font-family: 'PT Sans', sans-serif;
  font-size: 14px;
  font-weight: bold;
  padding: 7px 14px;
  cursor: pointer;
}

.install-accept:hover {
  background: var(--green-hover);
}

.install-dismiss {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  padding: 6px;
  cursor: pointer;
}

/* ---------- mobile ---------- */

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    z-index: 50;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  }

  .menu-toggle {
    display: block;
  }

  .sidebar-close {
    display: block;
  }

  .backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.35);
  }

  .msg {
    max-width: 96%;
  }
}
