:root {
  --bg: #fafaf9;
  --bg-card: #ffffff;
  --text: #1c1917;
  --text-muted: #78716c;
  --text-light: #a8a29e;
  --border: #e7e5e4;
  --accent: #4f7942;
  --accent-hover: #3d6033;
  --accent-light: #e8f0e6;
  --danger: #b45454;
  --danger-hover: #943e3e;
  --urgent: #d97706;
  --low: #6b7280;
  --quick-win: #059669;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
  --max-width: 640px;
  --transition: 150ms ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917;
    --bg-card: #292524;
    --text: #e7e5e4;
    --text-muted: #a8a29e;
    --text-light: #78716c;
    --border: #44403c;
    --accent: #6b9e5e;
    --accent-hover: #7db86e;
    --accent-light: #2d3a29;
    --shadow: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.3);
  }
}

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

html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
}

/* --- Screens --- */

.screen {
  min-height: 100vh;
  padding-bottom: 48px;
}

.screen[hidden] {
  display: none;
}

/* --- Setup --- */

.setup-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 8px;
}

.logo {
  font-size: 3rem;
  font-weight: 300;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.logo-small {
  font-size: 1.2rem;
  font-weight: 300;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.setup-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 32px;
}

.setup-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
}

/* --- Top Bar --- */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.top-actions {
  display: flex;
  gap: 4px;
}

/* --- Buttons --- */

.btn {
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--accent-light);
  color: var(--accent);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--border);
  color: var(--text);
}

.btn-danger {
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-large {
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 500;
}

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

/* --- Form elements --- */

label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 8px;
}

input[type="text"],
input[type="url"],
input[type="password"],
input[type="time"],
textarea,
select {
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  width: 100%;
  transition: border-color var(--transition);
}

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

textarea {
  resize: vertical;
  font-family: var(--font);
}

select {
  cursor: pointer;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  margin-top: 12px;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
}

/* --- Section Cards --- */

.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 4px;
}

.section-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* --- Greeting --- */

.greeting {
  font-size: 1.1rem;
  margin-bottom: 20px;
  color: var(--text);
}

/* --- Suggestion Cards --- */

.suggestion-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg);
}

.suggestion-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.suggestion-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.suggestion-preview {
  font-size: 0.9rem;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}

.suggestion-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* --- Badges --- */

.badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text-muted);
}

.badge-urgent {
  background: #fef3c7;
  color: var(--urgent);
}

.badge-low {
  background: #f3f4f6;
  color: var(--low);
}

.badge-quick-win {
  background: #d1fae5;
  color: var(--quick-win);
}

.badge-in-progress {
  background: var(--accent-light);
  color: var(--accent);
}

.badge-email {
  background: #dbeafe;
  color: #2563eb;
}

.badge-new-message {
  background: #ede9fe;
  color: #7c3aed;
}

@media (prefers-color-scheme: dark) {
  .badge-urgent {
    background: #422006;
    color: #fbbf24;
  }
  .badge-quick-win {
    background: #064e3b;
    color: #34d399;
  }
  .badge-in-progress {
    background: var(--accent-light);
    color: var(--accent);
  }
  .badge-email {
    background: #1e3a5f;
    color: #60a5fa;
  }
  .badge-new-message {
    background: #2e1065;
    color: #a78bfa;
  }
  .badge-low {
    background: #374151;
    color: #9ca3af;
  }
}

/* --- Suggestions Footer --- */

.suggestions-footer {
  margin-top: 20px;
  text-align: center;
}

/* --- Done Card --- */

.done-card {
  text-align: center;
  padding: 48px 24px;
}

.done-emoji {
  font-size: 2.5rem;
  margin-bottom: 12px;
  color: var(--accent);
  font-weight: 300;
}

.done-text {
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.done-subtext {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* --- Drafting Screen --- */

.drafting-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.draft-meta {
  display: flex;
  gap: 6px;
}

.original-message h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 8px;
}

.message-body {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 0.9rem;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}

.draft-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.draft-images img {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: opacity var(--transition);
}

.draft-images img:hover {
  opacity: 0.85;
}

.reply-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reply-actions {
  display: flex;
  gap: 8px;
}

#reply-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reply-footer {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

.draft-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.draft-controls select {
  width: auto;
  padding: 6px 10px;
  font-size: 0.85rem;
}

/* --- Revise Section --- */

.revise-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.revise-row {
  display: flex;
  gap: 8px;
}

.revise-row input {
  flex: 1;
}

.revise-row .btn {
  flex-shrink: 0;
}

/* --- Versions --- */

#versions-section {
  margin-top: 12px;
}

.version-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 6px;
  background: var(--bg);
  font-size: 0.85rem;
}

.version-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.version-instruction {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.version-preview {
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}

/* --- Add Screen --- */

.add-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-type-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.add-type-toggle .btn {
  flex: 1;
  justify-content: center;
}

.toggle-active {
  background: var(--accent);
  color: white;
}

.toggle-active:hover {
  background: var(--accent-hover);
}

/* --- All Drafts --- */

.drafts-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.drafts-filters select {
  flex: 1;
  font-size: 0.85rem;
  padding: 6px 10px;
}

.draft-list-item {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-card);
}

.draft-list-item:hover {
  border-color: var(--accent);
}

.draft-list-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.draft-list-preview {
  font-size: 0.85rem;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.draft-list-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.draft-list-time {
  font-size: 0.75rem;
  color: var(--text-light);
}

/* --- Screening --- */

.screening-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.screening-item:last-child {
  border-bottom: none;
}

.screening-info {
  flex: 1;
  min-width: 0;
}

.screening-email {
  font-size: 0.9rem;
  font-weight: 500;
}

.screening-name {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.screening-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.screening-actions .btn {
  padding: 6px 12px;
  font-size: 0.8rem;
}

/* --- Settings --- */

.settings-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-info {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.sender-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* --- Streaming indicator --- */

.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  animation: blink 1s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* --- Toast / Feedback --- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  opacity: 0;
  transition: opacity 300ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

/* --- Snooze Dialog --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 320px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  margin-bottom: 12px;
}

.modal-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-options .btn {
  justify-content: center;
}
