/* ===== CSS Custom Properties ===== */
:root {
  --bg-primary: #0a0a0f;
  --bg-card: #1a1a2e;
  --bg-input: #12121f;
  --bg-code: #0d1117;
  --border-subtle: #2a2a3e;
  --accent-gradient: linear-gradient(135deg, #7c3aed, #06b6d4);
  --accent-purple: #7c3aed;
  --accent-cyan: #06b6d4;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --radius-card: 12px;
  --radius-btn: 8px;
  --transition: 0.2s ease;
  --font-main: system-ui, -apple-system, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-cyan);
  text-decoration: none;
  transition: opacity var(--transition);
}

a:hover {
  opacity: 0.8;
}

img {
  max-width: 100%;
  display: block;
}

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

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

::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 3px;
}

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

/* ===== Layout ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.grid {
  display: grid;
  gap: 20px;
}

/* ===== Typography ===== */
h1, h2, h3 {
  line-height: 1.3;
  font-weight: 600;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }

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

.text-muted {
  color: var(--text-muted);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-btn);
  font-family: var(--font-main);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  border-color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 24px;
  transition: all var(--transition);
}

.card:hover {
  border-color: var(--text-muted);
}

/* ===== Forms ===== */
input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-btn);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.9375rem;
  transition: border-color var(--transition);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent-purple);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.form-group {
  margin-bottom: 16px;
}

/* Radio buttons */
.radio-group {
  display: flex;
  gap: 16px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.radio-label input[type="radio"] {
  width: auto;
  accent-color: var(--accent-purple);
}

/* ===== Header ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card);
}

.page-header .back-link {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.page-header .back-link:hover {
  color: var(--text-primary);
}

/* ===== Doer Card Grid (Index) ===== */
.doer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  padding: 40px 0;
}

.doer-card {
  position: relative;
  text-align: center;
  padding: 32px 24px;
  cursor: pointer;
}

.doer-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-purple);
}

.doer-card.coming-soon {
  opacity: 0.5;
  cursor: default;
}

.doer-card.coming-soon:hover {
  transform: none;
  border-color: var(--border-subtle);
}

.doer-card .icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
}

.doer-card h3 {
  margin-bottom: 8px;
}

.doer-card p {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 12px;
}

.badge-soon {
  background: rgba(124, 58, 237, 0.15);
  color: var(--accent-purple);
  border: 1px solid rgba(124, 58, 237, 0.3);
}

.badge-active {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

/* ===== Landing Header ===== */
.landing-header {
  text-align: center;
  padding: 60px 20px 20px;
}

.landing-header h1 {
  font-size: 2rem;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.landing-header .subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 8px;
}

/* ===== Footer ===== */
.page-footer {
  text-align: center;
  padding: 32px 20px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  border-top: 1px solid var(--border-subtle);
}

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

.chat-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card);
  flex-shrink: 0;
}

.chat-header .doer-info {
  flex: 1;
}

.chat-header .doer-name {
  font-weight: 600;
  font-size: 1rem;
}

.chat-header .doer-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-header .doer-status.active {
  color: #22c55e;
}

/* ===== Timer ===== */
.timer-display {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  color: var(--text-secondary);
  padding: 6px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-btn);
  border: 1px solid var(--border-subtle);
}

.timer-display.warning {
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.3);
}

.timer-display.expired {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

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

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-muted);
  text-align: center;
  gap: 24px;
}

.chat-empty h2 {
  color: var(--text-secondary);
  font-weight: 500;
}

.example-prompts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 420px;
  width: 100%;
}

.example-prompt {
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-btn);
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
}

.example-prompt:hover {
  border-color: var(--accent-purple);
  color: var(--text-primary);
}

.message {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: var(--radius-card);
  font-size: 0.9375rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.message-user {
  align-self: flex-end;
  background: var(--accent-gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-bot {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 4px;
}

/* Assistant messages (triage phase) — visually lighter than doer */
.message-assistant {
  align-self: flex-start;
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-bottom-left-radius: 4px;
  color: var(--text-secondary);
  max-width: 75%;
  padding: 12px 16px;
  border-radius: var(--radius-card);
  font-size: 0.9375rem;
  line-height: 1.6;
  word-wrap: break-word;
}

/* ===== Phase Badge ===== */
.phase-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.phase-triage {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-secondary);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.phase-working {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
  animation: phase-pulse 2s ease-in-out infinite;
}

.phase-delivered {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

@keyframes phase-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ===== Handoff Banner ===== */
.handoff-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.2);
  border-radius: var(--radius-btn);
  margin: 8px 0;
}

.handoff-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(6, 182, 212, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-cyan);
  flex-shrink: 0;
}

.handoff-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.handoff-text strong {
  font-size: 0.8125rem;
  color: var(--text-primary);
}

.handoff-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== Code Blocks ===== */
.message-bot pre {
  background: var(--bg-code);
  border-left: 3px solid var(--accent-purple);
  border-radius: 6px;
  padding: 14px 16px;
  margin: 10px 0;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.5;
}

.message-bot code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.message-bot p code {
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: 4px;
}

.code-block-wrapper {
  position: relative;
}

.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  font-family: var(--font-main);
  transition: all var(--transition);
}

.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}

/* ===== Tool Use Indicator ===== */
.tool-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.2);
  border-radius: 20px;
  font-size: 0.8125rem;
  color: var(--accent-cyan);
  margin: 4px 0;
}

.tool-indicator .pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-cyan);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* ===== Typing Indicator ===== */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.typing-indicator .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.4s ease-in-out infinite;
}

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

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ===== Chat Input ===== */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-card);
  flex-shrink: 0;
}

.chat-input-bar textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 14px;
  line-height: 1.5;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-btn);
  background: var(--accent-gradient);
  border: none;
  color: #fff;
  font-size: 1.125rem;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.send-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

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

/* ===== Vault Page ===== */
.vault-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 20px;
}

.vault-section {
  margin-bottom: 40px;
}

.vault-section h2 {
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.credentials-table {
  width: 100%;
  border-collapse: collapse;
}

.credentials-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  border-bottom: 1px solid var(--border-subtle);
}

.credentials-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(42, 42, 62, 0.5);
  font-size: 0.875rem;
}

.credentials-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.credentials-empty {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Toggle Switch */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-subtle);
  border-radius: 11px;
  transition: var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  bottom: 3px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: var(--transition);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent-purple);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: #fff;
}

.btn-danger {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-btn);
  color: #ef4444;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: var(--font-main);
  transition: all var(--transition);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* ===== Session Expired Overlay ===== */
.expired-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.expired-modal {
  text-align: center;
  padding: 48px;
  max-width: 420px;
}

.expired-modal h2 {
  margin-bottom: 12px;
}

.expired-modal p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .doer-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 24px 0;
  }

  .doer-card {
    padding: 20px 16px;
  }

  .doer-card .icon {
    font-size: 2rem;
  }

  .landing-header {
    padding: 40px 20px 16px;
  }

  .landing-header h1 {
    font-size: 1.5rem;
  }

  .message {
    max-width: 88%;
  }

  .chat-header {
    gap: 10px;
    padding: 10px 14px;
  }

  .chat-input-bar {
    padding: 12px 14px;
  }
}

@media (max-width: 480px) {
  .doer-grid {
    grid-template-columns: 1fr;
  }

  .chat-header .btn-secondary {
    padding: 8px 12px;
    font-size: 0.75rem;
  }
}
