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

:root {
  color-scheme: light dark;
  --bg-primary: #fff;
  --bg-secondary: #f5f5f5;
  --text-primary: #111;
  --text-secondary: #666;
  --border: #ddd;
  --msg-user: #e5e5e5;
  --msg-other: #f5f5f5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #111;
    --bg-secondary: #1a1a1a;
    --text-primary: #eee;
    --text-secondary: #888;
    --border: #333;
    --msg-user: #2a2a2a;
    --msg-other: #1a1a1a;
  }
}

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

/* Auth Overlay */
#auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.auth-container {
  text-align: center;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
}

.auth-container h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.auth-subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.auth-button {
  display: inline-block;
  padding: 1rem 2rem;
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--text-primary);
  color: var(--bg-primary);
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: opacity 0.2s;
}

.auth-button:hover {
  opacity: 0.9;
}

.auth-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-error {
  color: #e53e3e;
  margin-top: 1rem;
  min-height: 1.5rem;
}

.auth-info {
  color: var(--text-secondary);
  margin-top: 0.5rem;
  min-height: 1.5rem;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 250px;
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 100;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  padding: 1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.sidebar-link {
  display: block;
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  text-decoration: none;
  transition: background 0.15s;
}

.sidebar-link:hover {
  background: var(--bg-primary);
}

.sidebar-link.active {
  background: var(--bg-primary);
  font-weight: 500;
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 99;
}

.sidebar-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* Hamburger */
.hamburger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  padding: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  margin-right: 0.75rem;
}

.hamburger span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
}

/* App - hidden until authenticated */
#app {
  display: none;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
}

#app.authenticated {
  display: flex;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
}

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

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status {
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status.connected {
  background: var(--text-primary);
  color: var(--bg-primary);
}

.status.disconnected {
  background: var(--text-secondary);
  color: var(--bg-primary);
}

.status.connecting {
  background: var(--border);
  color: var(--text-primary);
}

.logout-button {
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 0.25rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.logout-button:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

/* Page container */
#page-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Chat page */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  word-wrap: break-word;
}

.message.user {
  background: var(--msg-user);
  align-self: flex-end;
  border-bottom-right-radius: 0.25rem;
}

.message.system {
  background: var(--bg-secondary);
  align-self: center;
  font-style: italic;
  max-width: 90%;
  text-align: center;
}

.message.chronicler,
.message.treasurer,
.message.guard,
.message.architect {
  background: var(--msg-other);
  align-self: flex-start;
  border-bottom-left-radius: 0.25rem;
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.message-role {
  font-weight: 600;
  text-transform: capitalize;
}

.message-time {
  opacity: 0.7;
}

.message-content {
  line-height: 1.4;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
}

.chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
}

.chat-input:focus {
  outline: none;
  border-color: var(--text-secondary);
}

.chat-input::placeholder {
  color: var(--text-secondary);
}

.chat-form button {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  background: var(--text-primary);
  color: var(--bg-primary);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chat-form button:hover {
  opacity: 0.9;
}

.chat-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 600px) {
  header h1 {
    font-size: 1rem;
  }

  .message {
    max-width: 90%;
  }

  .chat-form {
    padding: 0.75rem;
  }

  .chat-input {
    padding: 0.5rem 0.75rem;
  }

  .chat-form button {
    padding: 0.5rem 1rem;
  }

  .auth-container {
    padding: 1rem;
  }

  .auth-container h2 {
    font-size: 1.5rem;
  }
}
