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

:root {
  --maroon: #800000;
  --maroon-dark: #5c0000;
  --maroon-light: #a83232;
  --bg: #f7f4f2;
  --sidebar-bg: #1a0a0a;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --border: #e8e0dc;
  --user-bubble: #f0ebe8;
  --shadow: 0 2px 12px rgba(128, 0, 0, 0.08);
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

body.locked .app {
  display: none;
}

.gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--sidebar-bg);
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

body.locked .gate {
  display: flex;
}

.gate-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.gate-icon {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  object-fit: cover;
  margin-bottom: 1rem;
}

.gate-card h2 {
  font-size: 1.25rem;
  margin-bottom: 0.35rem;
}

.gate-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.gate-form input {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
}

.gate-form input:focus {
  border-color: var(--maroon-light);
}

.gate-form button {
  padding: 0.75rem 1rem;
  background: var(--maroon);
  color: white;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.gate-form button:hover {
  background: var(--maroon-dark);
}

.gate-error {
  margin-top: 0.85rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0;
}

.gate-error.show {
  animation: gateErrorFadeIn 0.5s ease forwards;
}

@keyframes gateErrorFadeIn {
  from {
    opacity: 0;
    transform: translateY(-2px);
  }
  to {
    opacity: 0.7;
    transform: translateY(0);
  }
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: #e8d5d5;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.25rem;
}

.logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.logo-text {
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  background: rgba(128, 0, 0, 0.25);
  border: 1px solid rgba(168, 50, 50, 0.4);
  border-radius: 8px;
  color: #f0d0d0;
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.new-chat-btn:hover {
  background: rgba(128, 0, 0, 0.4);
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 0.25rem;
}

.sidebar-footer p {
  font-size: 0.75rem;
  color: #8a6060;
  font-style: italic;
}

/* Main chat */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  position: relative;
  isolation: isolate;
}

.chat::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('fauxnixtransparent.png');
  background-repeat: repeat;
  background-size: 72px;
  opacity: 0.045;
  pointer-events: none;
  z-index: 0;
}

.chat > * {
  position: relative;
  z-index: 1;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

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

.badge {
  font-size: 0.75rem;
  color: var(--maroon);
  font-weight: 500;
  font-style: italic;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.message {
  display: flex;
  gap: 0.85rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

.message.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  flex-shrink: 0;
}

.message.assistant .avatar {
  background: #fff;
  color: white;
  overflow: hidden;
  padding: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.message.user .avatar {
  background: #d4c4be;
  color: var(--text);
  font-size: 0.75rem;
}

.bubble {
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  font-size: 0.95rem;
}

.message.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.message.user .bubble {
  background: var(--user-bubble);
  border: 1px solid var(--border);
}

.bubble p + p {
  margin-top: 0.5rem;
}

/* Typing indicator */
.typing .bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 1rem 1.25rem;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--maroon-light);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

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

/* Input */
.input-area {
  padding: 1rem 1.5rem 1.25rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.input-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.6rem 0.6rem 0.6rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

.input-form:focus-within {
  border-color: var(--maroon-light);
}

#userInput {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  outline: none;
  max-height: 150px;
  line-height: 1.4;
  padding: 0;
  margin: 0;
  min-height: 1.4em;
}

.send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--maroon);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

.send-btn:hover:not(:disabled) {
  background: var(--maroon-dark);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .messages,
  .input-area {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
