/* ─── Kinsen AI — Styles ─── */

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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --user-bg: #1f6feb33;
  --assistant-bg: #161b22;
  --error: #f85149;
  --radius: 12px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── PIN Gate ── */
#pin-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}

.pin-box {
  text-align: center;
  background: var(--surface);
  padding: 2.5rem 2rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 320px;
}

.pin-box h1 {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
}

.pin-box p {
  color: var(--text-muted);
  margin-bottom: 1.2rem;
  font-size: 0.9rem;
}

.pin-box input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 0.8rem;
  text-align: center;
  letter-spacing: 0.15em;
}

.pin-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.pin-box button {
  width: 100%;
  padding: 0.7rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}

.pin-box button:hover {
  background: var(--accent-hover);
}

.error {
  color: var(--error);
  margin-top: 0.8rem;
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

/* ── App Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.header-actions button {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.35rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}

.header-actions button:hover {
  background: var(--border);
}

/* ── Chat Area ── */
main#chat-area {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ── Messages ── */
.message {
  max-width: 80%;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  line-height: 1.5;
  word-wrap: break-word;
}

.message .label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
  color: var(--text-muted);
}

.message .text {
  white-space: pre-wrap;
  font-size: 0.95rem;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bg);
  border: 1px solid #1f6feb55;
}

.message.user .label {
  color: var(--accent);
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
}

.message.loading .text {
  color: var(--text-muted);
  font-style: italic;
}

.message.error-msg {
  border-color: var(--error);
}

.message.error-msg .text {
  color: var(--error);
}

/* ── Footer / Input ── */
footer {
  padding: 0.6rem 1rem 0.8rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

#user-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 0.65rem 0.9rem;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
}

#user-input:focus {
  outline: none;
  border-color: var(--accent);
}

#send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#send-btn:hover {
  background: var(--accent-hover);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hint {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* ── Scrollbar ── */
#messages::-webkit-scrollbar {
  width: 6px;
}

#messages::-webkit-scrollbar-track {
  background: transparent;
}

#messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .message {
    max-width: 92%;
  }

  header h1 {
    font-size: 1rem;
  }

  .pin-box {
    width: 90%;
  }
}
