@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #F5F3EE;
  --bg2: #EDEADE;
  --card: #FFFFFF;
  --hover: #EAE7DF;
  --text: #1A1A1A;
  --text2: #6B6B6B;
  --text3: #9B9B9B;
  --accent: #1A7F64;
  --accent-bg: #E8F5F0;
  --border: #E0DDD5;
  --border2: #EDEADE;
  --red: #D32F2F;
  --shadow: 0 1px 3px rgba(0,0,0,0.04);
  --shadow2: 0 4px 16px rgba(0,0,0,0.06);
  --r: 12px;
  --r2: 16px;
  --r3: 24px;
  --t: 0.2s cubic-bezier(0.4,0,0.2,1);
  --sidebar-w: 260px;
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── AUTH PAGES ── */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: 420px;
  max-width: 100%;
  background: var(--card);
  border-radius: var(--r2);
  padding: 40px;
  box-shadow: var(--shadow2);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.auth-logo svg { width: 32px; height: 32px; }
.auth-logo span { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }

.auth-card h2 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.auth-card .subtitle { color: var(--text2); font-size: 14px; margin-bottom: 28px; line-height: 1.5; }

.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  outline: none;
  transition: border-color var(--t);
}

.form-input:focus { border-color: var(--accent); }
.form-input.error { border-color: var(--red); }

.form-error { font-size: 12px; color: var(--red); margin-top: 4px; display: none; }
.form-error.show { display: block; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all var(--t);
}

.btn-full { width: 100%; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-outline { background: transparent; color: var(--text); border: 1.5px solid var(--border); }
.btn-outline:hover { background: var(--hover); }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 8px; }

.auth-footer { text-align: center; margin-top: 24px; font-size: 14px; color: var(--text2); }

.alert {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 20px;
  line-height: 1.4;
}

.alert-error { background: #FDE8E8; color: var(--red); }
.alert-success { background: var(--accent-bg); color: var(--accent); }

/* ── SIDEBAR ── */
.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  z-index: 100;
  transition: transform var(--t);
}

.sb-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

.sb-logo svg { width: 28px; height: 28px; }
.sb-logo span { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }

.sb-nav { display: flex; flex-direction: column; gap: 2px; }

.sb-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  color: var(--text2);
  transition: all var(--t);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.sb-item:hover { background: var(--hover); color: var(--text); }
.sb-item.active { background: var(--hover); color: var(--text); font-weight: 600; }
.sb-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.sb-div { height: 1px; background: var(--border); margin: 8px 12px; }

.sb-threads {
  flex: 1;
  overflow-y: auto;
  margin-top: 8px;
}

.sb-threads-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 4px 12px 8px;
}

.sb-thread {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all var(--t);
}

.sb-thread:hover { background: var(--hover); color: var(--text); }

.sb-user {
  padding: 10px 12px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all var(--t);
}

.sb-user:hover { background: var(--hover); }

.sb-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.sb-user-info { flex: 1; min-width: 0; }
.sb-user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-plan {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sb-dropdown {
  display: none;
  position: absolute;
  bottom: 70px;
  left: 12px;
  right: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow2);
  padding: 6px;
  z-index: 200;
}

.sb-dropdown.show { display: block; }

.sb-drop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: all var(--t);
}

.sb-drop-item:hover { background: var(--hover); color: var(--text); }
.sb-drop-item.danger { color: var(--red); }
.sb-drop-item svg { width: 16px; height: 16px; }

/* ── MAIN AREA ── */
.main {
  margin-left: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
  position: relative;
}

.page { display: none; }
.page.active { display: flex; flex-direction: column; }

/* ── SEARCH HOME ── */
.search-home {
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 24px;
}

.sh-title {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: 32px;
  text-align: center;
  background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.search-wrap {
  width: 100%;
  max-width: 680px;
  position: relative;
}

.search-input {
  width: 100%;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--r3);
  padding: 18px 60px 18px 24px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: all var(--t);
  box-shadow: var(--shadow);
}

.search-input:focus { border-color: var(--accent); box-shadow: var(--shadow2), 0 0 0 3px var(--accent-bg); }
.search-input::placeholder { color: var(--text3); }

.search-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t);
  opacity: 0.4;
}

.search-btn.ready { opacity: 1; }
.search-btn svg { width: 18px; height: 18px; stroke: white; }

.quick-chips {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.chip {
  padding: 8px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  transition: all var(--t);
  font-family: inherit;
}

.chip:hover { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

.usage-bar {
  margin-top: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text3);
}

.usage-bar strong { color: var(--text2); }

/* ── THREAD VIEW ── */
.thread-view { height: 100vh; }

.tv-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border2);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.tv-header-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tv-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.msg {
  max-width: 780px;
  margin: 0 auto 28px;
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-query {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 20px;
  letter-spacing: -0.3px;
}

.msg-answer {
  background: var(--card);
  border: 1px solid var(--border2);
  border-radius: var(--r2);
  padding: 24px;
  box-shadow: var(--shadow);
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.msg-header svg { width: 18px; height: 18px; }

.msg-body {
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
}

.msg-body p { margin-bottom: 12px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body strong { font-weight: 600; }
.msg-body ul, .msg-body ol { margin: 8px 0 12px 20px; }
.msg-body li { margin-bottom: 6px; }
.msg-body code { background: var(--bg2); padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.msg-body pre { background: #1a1a1a; color: #e0e0e0; padding: 16px; border-radius: 10px; overflow-x: auto; margin: 12px 0; font-size: 13px; line-height: 1.6; }

.tv-input-bar {
  padding: 16px 24px;
  background: var(--bg);
  border-top: 1px solid var(--border2);
}

.tv-input-wrap {
  max-width: 780px;
  margin: 0 auto;
  position: relative;
}

.tv-input {
  width: 100%;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--r3);
  padding: 14px 52px 14px 20px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: all var(--t);
}

.tv-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

.tv-send {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tv-send svg { width: 16px; height: 16px; stroke: white; }

/* ── DISCOVER ── */
.discover-page { display: none; overflow-y: auto; height: 100vh; padding: 32px 24px; }
.discover-page.active { display: block; }

.disc-header { max-width: 900px; margin: 0 auto 28px; }
.disc-header h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 4px; }
.disc-header p { color: var(--text2); font-size: 15px; }

.news-grid {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}

.news-card {
  background: var(--card);
  border: 1px solid var(--border2);
  border-radius: var(--r2);
  padding: 20px;
  cursor: pointer;
  transition: all var(--t);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.news-card:hover { box-shadow: var(--shadow2); transform: translateY(-2px); }

.news-cat {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 4px 10px;
  border-radius: 6px;
  align-self: flex-start;
}

.news-title { font-size: 16px; font-weight: 600; line-height: 1.4; }
.news-snippet { font-size: 13px; color: var(--text2); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.news-meta { font-size: 12px; color: var(--text3); margin-top: auto; }
.news-loading { text-align: center; padding: 60px 20px; color: var(--text3); }

/* ── LOADING ── */
.dots { display: flex; gap: 6px; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: bounce 1.4s ease-in-out infinite; }
.dots span:nth-child(2) { animation-delay: 0.16s; }
.dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes bounce { 0%,80%,100%{transform:scale(0.6);opacity:0.4}40%{transform:scale(1);opacity:1} }

.cursor::after { content:'▊'; animation: blink 0.8s step-end infinite; color: var(--accent); }
@keyframes blink { 50%{opacity:0} }

/* ── MOBILE ── */
.mob-header { display: none; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .mob-header {
    display: flex !important;
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border2);
    align-items: center;
    gap: 12px;
  }
  .sh-title { font-size: 28px; }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
