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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --error: #f85149;
  --tool-bg: #1c2128;
  --tool-border: #2d333b;
  --green: #3fb950;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.error { color: var(--error); }

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

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 340px;
  text-align: center;
}

.login-box h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--accent);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-password {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

#login-password:focus {
  border-color: var(--accent);
}

#login-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

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

#login-error {
  margin-top: 12px;
  font-size: 13px;
}

.build-info {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text);
  opacity: 0.5;
}

/* Main UI */
#main-ui {
  display: flex;
  flex-direction: column;
  height: 100%;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.title {
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.cwd {
  color: var(--text-dim);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 16px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { border-color: var(--accent); }
.icon-btn.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }

.voice-controls {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}

.voice-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  padding: 4px 6px;
  max-width: 140px;
  outline: none;
}

.voice-select:focus {
  border-color: var(--accent);
}

@media (max-width: 600px) {
  .voice-select {
    max-width: 100px;
    font-size: 11px;
  }
}

/* Output area */
main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
}

.msg {
  margin-bottom: 16px;
  max-width: 100%;
}

.msg-user {
  color: var(--green);
}

.msg-user::before {
  content: '> ';
  opacity: 0.6;
}

.msg-assistant {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg-assistant code {
  background: var(--tool-bg);
  border: 1px solid var(--tool-border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 13px;
}

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

.msg-tool {
  background: var(--tool-bg);
  border: 1px solid var(--tool-border);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 13px;
}

.msg-tool .tool-name {
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 4px;
}

.msg-tool .tool-input {
  color: var(--text-dim);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg-result {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.msg-error {
  color: var(--error);
  padding: 8px 12px;
  background: rgba(248, 81, 73, 0.1);
  border-radius: 6px;
  margin: 8px 0;
}

/* Footer / Input */
footer {
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#prompt-form {
  display: flex;
  gap: 8px;
}

#prompt-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 200px;
}

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

#send-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  align-self: flex-end;
}

#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Stop Audio Button */
.stop-audio-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 18px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.stop-audio-btn:hover { border-color: var(--error); color: var(--error); }
.stop-audio-btn:active { background: rgba(248, 81, 73, 0.15); }

/* TTS Play Button */
.tts-play-btn {
  display: inline-block;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  margin: 8px 0;
}

.tts-play-btn:hover { background: var(--accent-hover); }
.tts-play-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Scrollbar */
main::-webkit-scrollbar {
  width: 8px;
}

main::-webkit-scrollbar-track {
  background: var(--bg);
}

main::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

main::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* Attach button */
.attach-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 18px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.attach-btn:hover { border-color: var(--accent); color: var(--accent); }
.attach-btn:active { background: rgba(88, 166, 255, 0.1); }

/* Preview strip */
.preview-strip {
  display: flex;
  gap: 8px;
  padding: 8px 16px 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.preview-thumb {
  position: relative;
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 14px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}

/* Chat images in messages */
.msg-images {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.chat-image {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: contain;
}

/* Mobile */
@media (max-width: 600px) {
  html { font-size: 15px; }

  header { padding: 8px 12px; gap: 8px; }
  main { padding: 12px; }
  footer { padding: 10px 12px; }

  .login-box {
    width: 90%;
    padding: 30px 24px;
  }

  #prompt-input {
    font-size: 16px; /* prevents iOS zoom */
  }
  .preview-strip { padding: 8px 12px 4px; }
  .chat-image { max-width: 150px; max-height: 150px; }
}
