* { box-sizing: border-box; }

.icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
  display: inline-block;
  vertical-align: middle;
  flex: none;
}

.icon-lg {
  width: 28px;
  height: 28px;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1b1d22;
  color: #f2f2f2;
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* --- Setup screen --- */
#setup-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.setup-card {
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.setup-card h1 {
  font-size: 1.6rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #ff8c1a;
}
.setup-card p { color: #b7b9c2; margin: 4px 0; }
.setup-card .hint { font-size: 0.85rem; }

#api-key-input {
  width: 100%;
  padding: 12px 14px;
  margin-top: 16px;
  border-radius: 10px;
  border: 1px solid #3a3d46;
  background: #24262c;
  color: #f2f2f2;
  font-size: 1rem;
}

#save-key-btn {
  width: 100%;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: none;
  background: #ff8c1a;
  color: #1b1d22;
  font-weight: 600;
  font-size: 1rem;
}

.hint-link {
  display: block;
  margin-top: 16px;
  color: #ff8c1a;
  font-size: 0.85rem;
  text-decoration: none;
}

/* --- Chat screen --- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 12px) 16px 12px;
  border-bottom: 1px solid #2a2c33;
}

header h1 {
  font-size: 1.1rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ff8c1a;
}

.header-actions {
  display: flex;
  gap: 2px;
}

.header-actions button {
  background: none;
  border: none;
  color: #b7b9c2;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.header-actions button:active {
  background: #2a2c33;
}

/* --- History overlay --- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}

.overlay-card {
  width: 100%;
  max-height: 70vh;
  background: #24262c;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 12px);
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #33353d;
}

.overlay-header h2 { font-size: 1rem; margin: 0; }

#close-history-btn {
  background: none;
  border: none;
  color: #b7b9c2;
  padding: 6px;
  display: flex;
  align-items: center;
}

#history-list {
  overflow-y: auto;
  padding: 8px 0;
}

.history-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid #2a2c33;
  color: #f2f2f2;
}

.history-item .h-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .h-meta {
  font-size: 0.78rem;
  color: #8b8d97;
  margin-top: 2px;
}

.history-empty {
  padding: 20px 16px;
  color: #8b8d97;
  font-size: 0.9rem;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.assistant p {
  margin: 0 0 8px;
}

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

.msg.assistant ul {
  margin: 4px 0 8px;
  padding-left: 20px;
}

.msg.assistant li {
  margin-bottom: 4px;
}

.msg.assistant strong {
  font-weight: 700;
}

.msg.user {
  align-self: flex-end;
  background: #ff8c1a;
  color: #1b1d22;
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: #2a2c33;
  border-bottom-left-radius: 4px;
}

.msg.pending { opacity: 0.6; }

#chips {
  display: flex;
  gap: 8px;
  padding: 0 12px 8px;
  overflow-x: auto;
}

.chip {
  flex: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: #2a2c33;
  border: 1px solid #3a3d46;
  color: #f2f2f2;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Blank/new chat: stack suggestions as a full-width vertical list instead of a scroll row */
#chips.empty-state {
  flex-direction: column;
  overflow-x: visible;
  overflow-y: auto;
  max-height: 44vh;
  padding: 8px 16px 12px;
  gap: 8px;
}

#chips.empty-state .chip {
  width: 100%;
  text-align: left;
  border-radius: 12px;
  padding: 12px 14px;
  white-space: normal;
}

#chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom, 10px) + 10px);
  border-top: 1px solid #2a2c33;
}

#chat-input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 20px;
  border: 1px solid #3a3d46;
  background: #24262c;
  color: #f2f2f2;
  font-size: 1rem;
}

#chat-form button {
  padding: 0 18px;
  border-radius: 20px;
  border: none;
  background: #ff8c1a;
  color: #1b1d22;
  font-weight: 600;
}
