:root {
  --bg: #1e1f22;
  --panel: #26272b;
  --bubble-user: #31333a;
  --bubble-ai: #2b2d31;
  --text: #d8d8d8;
  --text-dim: #8a8d93;
  --accent: #5c8374;
  --accent-hover: #4a6d61;
  --warn: #c9a45c;
  --border: #35363b;
  --error: #c97b7b;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
}

.hidden { display: none !important; }

.screen { height: 100%; width: 100%; }

.center-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* ---------------- loading ---------------- */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- login card ---------------- */
.login-card, .choice-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.app-title { font-size: 18px; font-weight: 600; color: var(--text); }

.field-label { font-size: 13px; color: var(--text-dim); margin-top: 6px; }

input[type=text], input[type=password], textarea {
  background: var(--bubble-user);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  width: 100%;
}
input:focus, textarea:focus { outline: 1px solid var(--accent); }

.fun-question {
  font-size: 17px;
  font-weight: 800;
  background: linear-gradient(90deg, #ff7ab8, #ffd166, #6ee7b7, #7dd3fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 18px rgba(255, 122, 184, 0.25);
  margin: 10px 0 4px 0;
  line-height: 1.3;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  cursor: pointer;
  margin-top: 8px;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--bubble-user); }

.error-text { color: var(--error); font-size: 13px; }
.muted { color: var(--text-dim); font-size: 13px; margin: 0 0 10px 0; }

/* ---------------- choice screen ---------------- */
.choice-card { align-items: stretch; text-align: center; }
.btn-choice {
  display: flex; align-items: center; gap: 10px;
  background: var(--bubble-user);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 16px;
  font-size: 15px;
  cursor: pointer;
  margin-top: 8px;
}
.btn-choice:hover { border-color: var(--accent); }
.choice-icon { font-size: 20px; }

/* ---------------- topbar (shared) ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.topbar-right { display: flex; align-items: center; gap: 12px; }

.status-cluster { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim); display: inline-block;
}
.status-label { color: var(--text-dim); }

.smart-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); }

/* ---------------- admin panel ---------------- */
.admin-body { padding: 20px; max-width: 560px; margin: 0 auto; }
.admin-user-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; }
.admin-user-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: 14px;
}
.admin-form { display: flex; flex-direction: column; gap: 8px; }
.btn-danger { background: transparent; border: 1px solid var(--error); color: var(--error);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; }

/* ---------------- chat shell ---------------- */
.app-shell { display: flex; height: 100%; }

.sidebar {
  width: 240px; min-width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}
.sidebar-new-btn { width: 100%; }
.conversation-list { flex: 1; overflow-y: auto; margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.conversation-item {
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  font-size: 13px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conversation-item:hover { background: var(--bubble-user); }
.conversation-item.active { background: var(--bubble-user); color: var(--text); }
.sidebar-footer { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }

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

.chat-log {
  flex: 1; overflow-y: auto; padding: 16px; position: relative;
  white-space: pre-wrap; line-height: 1.5; font-size: 15px;
}
.msg-user { color: var(--accent); font-weight: 600; }
.msg-ai { color: var(--text-dim); font-weight: 600; }
.msg-error { color: var(--error); }

.ai-status-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 16px;
}

.jump-btn {
  position: absolute;
  align-self: flex-end;
  margin: 0 16px 8px 0;
  background: var(--accent);
  color: #fff; border: none; border-radius: 20px;
  padding: 6px 14px; font-size: 13px; cursor: pointer;
}

.input-row {
  display: flex; gap: 8px; padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--panel);
  border-top: 1px solid var(--border);
}
#message-input { resize: none; max-height: 140px; }
#send-btn { align-self: flex-end; }

/* ---------------- mobile ---------------- */
@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; min-width: 0; max-height: 40vh;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .login-card, .choice-card { padding: 20px; }
}
