/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-body: #0f0f0f;
  --bg-sidebar: #1a1a1a;
  --bg-chat: #141414;
  --bg-card: #1e1e1e;
  --bg-input: #222;
  --bg-hover: #252525;

  --text-primary: #e0e0e0;
  --text-secondary: #888;
  --text-muted: #555;

  --accent-claude: #8B5CF6;
  --accent-codex: #10B981;
  --accent-user: #6B7280;
  --accent-danger: #EF4444;

  --border: #2a2a2a;
  --border-light: #333;

  --radius: 8px;
  --radius-lg: 12px;

  --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', monospace;

  --sidebar-width: 280px;
  --header-height: 60px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-main);
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
}

/* === Screens === */
.screen {
  height: 100vh;
  width: 100vw;
}

.hidden {
  display: none !important;
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #444;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #333 transparent;
}

/* === Login Screen === */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(139, 92, 246, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, rgba(16, 185, 129, 0.06) 0%, transparent 60%);
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-box h1 {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
  background: linear-gradient(135deg, var(--accent-claude), var(--accent-codex));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-box p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

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

#login-form input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

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

#login-form button {
  background: var(--accent-claude);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-top: 4px;
}

#login-form button:hover {
  background: #7C4DDB;
}

#login-form button:active {
  transform: scale(0.98);
}

.error {
  color: var(--accent-danger);
  font-size: 0.85rem;
  min-height: 1.2em;
}

/* === Chat Layout === */
.layout {
  display: flex;
  height: 100vh;
}

/* === Sidebar === */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#new-convo-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-primary);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

#new-convo-btn:hover {
  background: var(--accent-claude);
  border-color: var(--accent-claude);
}

#convo-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#convo-list li {
  padding: 12px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#convo-list li:hover {
  background: var(--bg-hover);
}

#convo-list li.active {
  background: #1f1f2e;
  border-left: 3px solid var(--accent-claude);
}

#convo-list li .convo-name {
  flex: 1;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#convo-list li .convo-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#user-display {
  font-size: 0.85rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
}

#logout-btn {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

#logout-btn:hover {
  color: var(--accent-danger);
  border-color: var(--accent-danger);
}

/* === Chat Area === */
#chat-area {
  flex: 1;
  background: var(--bg-chat);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.center-message {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.center-message p {
  color: var(--text-muted);
  font-size: 1.1rem;
}

#active-convo {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* === Chat Header === */
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  min-height: var(--header-height);
  background: var(--bg-sidebar);
}

#chat-header > div:first-child {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

#convo-title {
  font-size: 1.05rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#turn-count {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* === Badges === */
.badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-pending {
  background: rgba(139, 92, 246, 0.15);
  color: #A78BFA;
}

.badge-active {
  background: rgba(16, 185, 129, 0.15);
  color: #34D399;
}

.badge-paused {
  background: rgba(234, 179, 8, 0.15);
  color: #FBBF24;
}

.badge-agreed {
  background: rgba(59, 130, 246, 0.15);
  color: #60A5FA;
}

.badge-closed {
  background: rgba(107, 114, 128, 0.15);
  color: #9CA3AF;
}

/* === Controls === */
.controls {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.controls button {
  padding: 8px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

#start-btn {
  background: var(--accent-claude);
  color: white;
}

#start-btn:hover {
  background: #7C4DDB;
}

#pause-btn {
  background: rgba(234, 179, 8, 0.15);
  color: #FBBF24;
  border: 1px solid rgba(234, 179, 8, 0.3);
}

#pause-btn:hover {
  background: rgba(234, 179, 8, 0.25);
}

#resume-btn {
  background: rgba(16, 185, 129, 0.15);
  color: #34D399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

#resume-btn:hover {
  background: rgba(16, 185, 129, 0.25);
}

/* === Messages === */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border-left: 3px solid transparent;
  max-width: 85%;
  animation: fadeIn 0.2s ease;
}

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

.message-claude {
  border-left-color: var(--accent-claude);
  background: rgba(139, 92, 246, 0.06);
}

.message-codex {
  border-left-color: var(--accent-codex);
  background: rgba(16, 185, 129, 0.06);
}

.message-user {
  border-left-color: var(--accent-user);
  background: #1c1c1c;
  align-self: flex-end;
}

.message-system {
  border-left: none;
  background: rgba(59, 130, 246, 0.08);
  text-align: center;
  align-self: center;
  max-width: 70%;
  font-size: 0.9rem;
  color: var(--text-secondary);
  border: 1px solid rgba(59, 130, 246, 0.15);
}

.message-sender {
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.message-claude .message-sender {
  color: var(--accent-claude);
}

.message-codex .message-sender {
  color: var(--accent-codex);
}

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

.message-content {
  font-size: 0.95rem;
  line-height: 1.6;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* === Typing Indicator === */
#typing-indicator {
  padding: 8px 24px 4px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 2px;
}

#typing-name {
  font-weight: 600;
}

.typing-claude #typing-name {
  color: var(--accent-claude);
}

.typing-codex #typing-name {
  color: var(--accent-codex);
}

.dots span {
  animation: blink 1.4s infinite both;
  font-weight: bold;
}

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

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

@keyframes blink {
  0%, 60%, 100% { opacity: 0.2; }
  30% { opacity: 1; }
}

/* === Message Form === */
#message-form {
  display: flex;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-sidebar);
}

#message-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

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

#message-form button {
  background: var(--accent-claude);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 12px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#message-form button:hover {
  background: #7C4DDB;
}

#message-form button:active {
  transform: scale(0.97);
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-content h3 {
  font-size: 1.1rem;
  margin-bottom: 20px;
  color: var(--text-primary);
}

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

#new-convo-form input,
#new-convo-form textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font-main);
  outline: none;
  resize: vertical;
  transition: border-color 0.2s;
}

#new-convo-form input:focus,
#new-convo-form textarea:focus {
  border-color: var(--accent-claude);
}

#new-convo-form label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 10px;
}

#new-convo-form label input {
  width: 80px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.modal-actions button {
  padding: 10px 22px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

#cancel-modal {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
}

#cancel-modal:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.modal-actions button[type="submit"] {
  background: var(--accent-claude);
  color: white;
  border: none;
}

.modal-actions button[type="submit"]:hover {
  background: #7C4DDB;
}

/* === Streaming cursor blink === */
.streaming-cursor::after {
  content: '\25AE';
  animation: cursorBlink 0.8s step-end infinite;
  color: var(--text-muted);
  margin-left: 2px;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
