:root {
  --bg1: #eaf4ef;
  --bg2: #f5effc;
  --green: #3f7f6c;
  --green-dark: #2c5a4c;
  --green-deep: #24463c;
  --ink: #233230;
  --muted: #6b7f7a;
  --line: #dde9e3;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
}

.hidden { display: none !important; }
.view { height: 100%; }

button { font-family: inherit; }

/* ===================== Экран входа ===================== */

#auth-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 100dvh;
}

.auth-card {
  background: #fff;
  border-radius: 22px;
  padding: 36px 34px 30px;
  width: min(410px, 94vw);
  box-shadow: 0 18px 50px rgba(35, 70, 60, 0.14);
}

.auth-logo { font-size: 40px; text-align: center; }
.auth-card h1 {
  margin: 8px 0 4px;
  font-size: 23px;
  text-align: center;
  color: var(--green-deep);
}
.auth-sub {
  margin: 0 0 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.tabs {
  display: flex;
  background: #eef4f1;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 0;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14.5px;
  color: #55706a;
}
.tab.active {
  background: #fff;
  color: var(--green-dark);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(35, 70, 60, 0.12);
}

.field { display: block; margin-bottom: 14px; }
.field span {
  display: block;
  font-size: 13px;
  color: #5c716c;
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.field input:focus { border-color: var(--green); }

.auth-error {
  background: #fdecec;
  color: #a33a3a;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  margin-bottom: 14px;
  line-height: 1.4;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { opacity: .6; cursor: default; }

/* ===================== Чат ===================== */

#chat-view { display: flex; height: 100dvh; overflow: hidden; }

/* --- боковая панель --- */
#sidebar {
  width: 292px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #275044, #1d3d34);
  color: #dcece6;
  display: flex;
  flex-direction: column;
  padding: 18px 14px 14px;
}
.side-title { font-weight: 600; font-size: 16.5px; }
.side-head { padding: 0 8px 14px; }

.btn-new {
  width: 100%;
  padding: 11px;
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .08);
  color: #fff;
  border-radius: 12px;
  font-size: 14.5px;
  cursor: pointer;
  transition: background .15s;
}
.btn-new:hover { background: rgba(255, 255, 255, .16); }

.conv-list {
  flex: 1;
  overflow-y: auto;
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.conv-list:empty::after {
  content: 'Здесь появятся твои разговоры';
  display: block;
  color: rgba(220, 236, 230, .45);
  font-size: 12.5px;
  text-align: center;
  padding: 18px 10px;
  line-height: 1.5;
}
.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s;
}
.conv-item:hover { background: rgba(255, 255, 255, .08); }
.conv-item.active { background: rgba(255, 255, 255, .16); }
.conv-title {
  flex: 1;
  font-size: 13.5px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-del {
  border: none;
  background: transparent;
  color: rgba(220, 236, 230, .5);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 6px;
  visibility: hidden;
}
.conv-item:hover .conv-del { visibility: visible; }
.conv-del:hover { color: #fff; background: rgba(255, 255, 255, .14); }

.side-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, .12);
  font-size: 13.5px;
}
#user-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#logout {
  border: none;
  background: transparent;
  color: rgba(220, 236, 230, .75);
  cursor: pointer;
  font-size: 13.5px;
  padding: 4px 6px;
  border-radius: 8px;
}
#logout:hover { color: #fff; background: rgba(255, 255, 255, .1); }

#backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 34, .45);
  z-index: 25;
}

/* --- основная область --- */
#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, .75);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.chat-header-title { font-weight: 600; font-size: 15.5px; color: var(--green-deep); }
#menu-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  color: var(--green-deep);
  padding: 2px 8px;
  border-radius: 8px;
}
#menu-btn:hover { background: rgba(36, 70, 60, .08); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 26px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  padding: 5px 0;
}
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15.5px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.assistant .bubble {
  background: #fff;
  border: 1px solid #e4ece7;
  box-shadow: 0 1px 3px rgba(35, 70, 60, .06);
  border-radius: 18px 18px 18px 4px;
}
.user .bubble {
  background: linear-gradient(135deg, #43907a, #38806c);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}
.bubble.error {
  background: #fdf3f3;
  border: 1px solid #eccaca;
  color: #9c4444;
  font-size: 14.5px;
}
.bubble b { font-weight: 600; }
.msg-list { margin: 4px 0 2px; padding-left: 20px; }
.msg-gap { height: 7px; }

.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a9c4ba;
  animation: pulse 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes pulse {
  0%, 60%, 100% { transform: scale(.8); opacity: .5; }
  30% { transform: scale(1.15); opacity: 1; }
}

/* --- приветствие --- */
.welcome {
  margin: auto;
  text-align: center;
  max-width: 540px;
  padding: 24px 12px;
}
.welcome-emoji { font-size: 46px; margin-bottom: 6px; }
.welcome h2 { margin: 0 0 10px; font-size: 22px; color: var(--green-deep); }
.welcome p { margin: 0 0 22px; color: var(--muted); font-size: 15.5px; line-height: 1.6; }
.chips { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; }
.chip {
  border: 1px solid #c8ddd4;
  background: rgba(255, 255, 255, .8);
  color: var(--green-dark);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { background: #fff; border-color: var(--green); }

/* --- поле ввода --- */
.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 20px 4px;
}
#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 13px 18px;
  font-size: 15.5px;
  font-family: inherit;
  line-height: 1.45;
  outline: none;
  max-height: 180px;
  background: #fff;
  transition: border-color .15s;
}
#input:focus { border-color: var(--green); }
#send {
  width: 47px;
  height: 47px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
#send:hover { background: var(--green-dark); }
#send:disabled { opacity: .45; cursor: default; }

.privacy-note {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 12px 12px;
}

/* ===================== Админ-панель ===================== */

.btn-admin {
  width: 100%;
  margin-top: 10px;
  padding: 9px;
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .08);
  color: #dcece6;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.btn-admin:hover { background: rgba(255, 255, 255, .16); }

#admin-view {
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  overflow-y: auto;
}
.admin-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 26px 18px 40px;
}
.admin-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.admin-back {
  border: none;
  background: #fff;
  color: var(--green-dark);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(35, 70, 60, .12);
}
.admin-back:hover { background: #f2f8f5; }
.admin-title { font-size: 19px; font-weight: 600; color: var(--green-deep); }

.admin-tabs {
  display: flex;
  gap: 4px;
  background: #e3eee8;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 18px;
}
.admin-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 0;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  color: #55706a;
}
.admin-tab.active {
  background: #fff;
  color: var(--green-dark);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(35, 70, 60, .12);
}

.admin-stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.stat-card {
  flex: 1;
  min-width: 150px;
  background: #fff;
  border-radius: 14px;
  padding: 14px 18px;
  box-shadow: 0 1px 4px rgba(35, 70, 60, .08);
}
.stat-num { font-size: 24px; font-weight: 700; color: var(--green-dark); }
.stat-label { font-size: 12.5px; color: var(--muted); }

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(35, 70, 60, .08);
}
.user-ava {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #43907a, #38806c);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
}
.user-info { flex: 1; min-width: 0; }
.user-name-l { font-weight: 600; font-size: 14.5px; }
.user-badge {
  font-size: 11px;
  background: #e7f3ee;
  color: var(--green-dark);
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: 6px;
}
.user-email {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.user-actions { display: flex; gap: 6px; flex-shrink: 0; }
.user-actions button {
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
  background: #eef4f1;
  color: #55706a;
  font-family: inherit;
}
.user-actions button:hover { background: #e0ebe5; }
.user-actions button.danger { background: #fdecec; color: #a33a3a; }
.user-actions button.danger:hover { background: #f9dcdc; }

.afield { display: block; margin-bottom: 14px; }
.afield span { display: block; font-size: 13px; color: #5c716c; margin-bottom: 6px; }
.afield input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  background: #fff;
}
.afield input:focus { border-color: var(--green); }
.arow { display: flex; gap: 12px; }
.afield.half { flex: 1; }
.ahint {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin: 4px 0 10px;
  line-height: 1.5;
}
.acheck {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13.5px;
  color: #5c716c;
  margin-bottom: 14px;
  cursor: pointer;
}

.aprompt {
  width: 100%;
  min-height: 340px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  font-family: inherit;
  outline: none;
  background: #fff;
}
.aprompt:focus { border-color: var(--green); }

.admin-pane .btn-primary { margin-top: 6px; }

/* ===================== Мобильная версия ===================== */

@media (max-width: 760px) {
  .chat-header { display: flex; }
  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform .22s ease;
    width: 300px;
    max-width: 86vw;
  }
  #sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  #backdrop.show { display: block; }
  .bubble { max-width: 88%; }
  .messages { padding: 18px 14px 10px; }
  .chat-form { padding: 10px 12px 2px; }
}
