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

:root {
  --bg: #0a0a0a;
  --surface: #1a1a1a;
  --surface-hover: #252525;
  --text: #e0e0e0;
  --text-muted: #777;
  --accent: #4a9eff;
  --user-bubble: #1a3a5c;
  --coach-bubble: #1e1e1e;
  --danger: #ff4444;
  --warning: #ffaa00;
  --success: #44cc44;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

/* Login Screen */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
}

#login-screen.hidden {
  display: none;
}

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

.login-icon {
  margin-bottom: 16px;
}

.login-card h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

#google-signin-btn {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #333;
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

#auth-form input {
  background: var(--surface);
  border: 1px solid #333;
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}

#auth-form input:focus {
  border-color: var(--accent);
}

#auth-form input::placeholder {
  color: #555;
}

#auth-submit-btn {
  background: var(--accent);
  border: none;
  color: white;
  padding: 12px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.2s;
}

#auth-submit-btn:hover {
  background: #3a8aee;
}

#auth-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  padding: 4px;
}

#auth-error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

#auth-error.hidden {
  display: none;
}

/* Header right */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  transition: all 0.2s;
}

#logout-btn:hover {
  background: var(--surface);
  color: var(--danger);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 700px;
  margin: 0 auto;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  padding-top: calc(14px + var(--safe-top));
  border-bottom: 1px solid #222;
  flex-shrink: 0;
  gap: 12px;
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
  flex: 1;
  text-align: center;
}

#menu-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
}

#menu-btn:hover {
  background: var(--surface);
  color: var(--text);
}

#budget-toggle {
  background: var(--surface);
  border: 1px solid #333;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  white-space: nowrap;
}

#budget-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* Budget Panel */
#budget-panel {
  padding: 14px 20px;
  border-bottom: 1px solid #222;
  flex-shrink: 0;
}

#budget-panel.hidden {
  display: none;
}

.budget-bar {
  height: 6px;
  background: #222;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
}

.budget-fill {
  height: 100%;
  background: var(--success);
  border-radius: 3px;
  transition: width 0.3s, background-color 0.3s;
  width: 0%;
}

.budget-fill.warning {
  background: var(--warning);
}

.budget-fill.danger {
  background: var(--danger);
}

.budget-details {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
}

/* Budget Warning Banner */
#budget-warning {
  background: #3a1111;
  color: var(--danger);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  flex-shrink: 0;
}

#budget-warning.hidden {
  display: none;
}

/* Sidebar Overlay */
#sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 90;
  transition: opacity 0.2s;
}

#sidebar-overlay.hidden {
  display: none;
}

/* Sidebar */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: #111;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.25s ease;
  padding-top: var(--safe-top);
}

#sidebar.hidden {
  transform: translateX(-100%);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #222;
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 600;
}

#new-chat-btn {
  background: var(--accent);
  border: none;
  color: white;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

#new-chat-btn:hover {
  background: #3a8aee;
}

/* Conversation List */
#conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}

.conv-item:hover {
  background: var(--surface);
}

.conv-item.active {
  background: var(--surface);
  border: 1px solid #333;
}

.conv-item-content {
  flex: 1;
  min-width: 0;
}

.conv-item-title {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.conv-item-delete {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  opacity: 0;
  transition: all 0.15s;
}

.conv-item:hover .conv-item-delete {
  opacity: 1;
}

.conv-item-delete:hover {
  color: var(--danger);
  background: rgba(255, 68, 68, 0.1);
}

.conv-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 14px;
}

/* Chat Messages */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message.user {
  align-self: flex-end;
}

.message.coach {
  align-self: flex-start;
}

.message-label {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.message.user .message-label {
  text-align: right;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.5;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.message.coach .message-bubble {
  background: var(--coach-bubble);
  border: 1px solid #2a2a2a;
  border-bottom-left-radius: 4px;
}

/* Typing indicator */
.typing {
  display: flex;
  gap: 5px;
  padding: 12px 16px;
  align-items: center;
}

.typing span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* Input Area */
#chat-form {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  padding-bottom: calc(16px + var(--safe-bottom));
  border-top: 1px solid #222;
  flex-shrink: 0;
  align-items: flex-end;
}

#chat-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid #333;
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15px;
  font-family: var(--font);
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.2s;
}

#chat-input:focus {
  border-color: var(--accent);
}

#chat-input::placeholder {
  color: #555;
}

#chat-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#send-btn {
  background: var(--accent);
  border: none;
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, opacity 0.2s;
}

#send-btn:hover {
  background: #3a8aee;
}

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

/* Scrollbar */
#chat-messages::-webkit-scrollbar,
#conversation-list::-webkit-scrollbar {
  width: 6px;
}

#chat-messages::-webkit-scrollbar-track,
#conversation-list::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb,
#conversation-list::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover,
#conversation-list::-webkit-scrollbar-thumb:hover {
  background: #444;
}

/* Mobile */
@media (max-width: 600px) {
  #app {
    max-width: 100%;
  }

  header {
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-top));
  }

  #chat-messages {
    padding: 16px;
  }

  #chat-form {
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-bottom));
  }

  .message {
    max-width: 90%;
  }

  #sidebar {
    width: 85%;
  }
}
