:root {
  --bg: #ffffff;
  --sidebar: #f7f7f8;
  --text: #0a0a0a;
  --muted: #1a1a1a;
  --line: #e8e8ea;
  --green: #10a37f;
  --green-dark: #0b7a5f;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  font-family: Inter, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, textarea, select, input { font: inherit; }

.auth-gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f4f7f6;
}

.auth-gate[hidden],
.app[hidden] {
  display: none !important;
}

.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-card h1 { margin: 12px 0 8px; font-size: 1.35rem; color: #0a0a0a; }
.auth-card p { margin: 0 0 16px; color: #1a1a1a; }
.auth-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.password-wrap {
  position: relative;
  margin-bottom: 12px;
}
.password-wrap input {
  margin-bottom: 0;
  padding-right: 46px;
}
.auth-card button, .btn, .send-btn {
  border: 0;
  cursor: pointer;
}
.auth-card button[type="submit"] {
  width: 100%;
  background: var(--green);
  color: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 600;
}
.auth-eye {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  background: transparent;
  color: #333;
  display: grid;
  place-items: center;
}
.auth-eye:hover,
.auth-eye:focus-visible {
  background: #f1f3f2;
  outline: none;
}
.auth-error { color: #b42318 !important; margin-top: 12px !important; }

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 300px 1fr;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 18px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-brand, .topbar h1 {
  color: #0a0a0a;
  font-weight: 700;
}
.sidebar-brand { font-size: 1.05rem; }

.btn {
  width: 100%;
  border-radius: 14px;
  padding: 11px 12px;
  background: #ececee;
  color: #0a0a0a;
  text-align: left;
}
.btn-primary { background: var(--green); color: #fff; text-align: center; font-weight: 600; }

.field, .check { display: flex; flex-direction: column; gap: 6px; color: #111; }
.field select, .composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: #0a0a0a;
}
.field select { padding: 10px 12px; }
.check { flex-direction: row; align-items: flex-start; gap: 8px; }
.check input { margin-top: 3px; }

.history-title { margin-top: 8px; font-weight: 600; color: #111; }
.chat-list { display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.chat-item {
  border: 0;
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  color: #111;
  cursor: pointer;
}
.chat-item.active { background: #dcefe8; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 18px 20px 8px;
}
.topbar h1 { margin: 0 0 4px; font-size: 1.45rem; }
.topbar p { margin: 0; color: #111; font-weight: 500; }
.icon-btn {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  width: 42px;
  height: 42px;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 8px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.empty {
  margin: auto;
  text-align: center;
  color: #111;
  padding: 48px 16px;
}
.empty h2 { margin: 0 0 8px; color: #0a0a0a; }

.msg { display: flex; gap: 10px; max-width: 820px; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.bubble {
  background: #f4f4f5;
  border-radius: 18px;
  padding: 12px 14px;
  white-space: pre-wrap;
  line-height: 1.5;
  color: #111;
}
.msg.user .bubble { background: #e7f6f1; }
.bubble img { max-width: min(280px, 70vw); border-radius: 12px; display: block; margin-top: 8px; }
.bubble a { color: var(--green-dark); }

.composer {
  position: sticky;
  bottom: 0;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(255,255,255,0), #fff 28%);
}
.preview-row { display: flex; gap: 8px; overflow: auto; margin-bottom: 8px; }
.preview-row img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.composer-row {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  align-items: end;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 8px;
  box-shadow: var(--shadow);
}
.attach-btn, .send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #f4f4f5;
}
.send-btn { background: var(--green); color: #fff; }
.composer textarea {
  border: 0;
  resize: none;
  min-height: 44px;
  max-height: 140px;
  padding: 10px 4px;
  outline: none;
}

.backdrop {
  display: none;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .icon-btn { display: grid; place-items: center; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    z-index: 20;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.28);
    z-index: 15;
  }
  .topbar, .messages, .composer { padding-left: 14px; padding-right: 14px; }
}
