:root {
  --bg: #153A21;
  --surface: #1b4728;
  --surface-hover: #1f5230;
  --border: #2a5e37;
  --accent: #FEF085;
  --accent-dim: #f5e467;
  --text: #f0f0f0;
  --muted: #7a9e82;
  --danger: #ff7070;
  --font: 'DM Sans', Arial, sans-serif;
  --sidebar-w: 280px;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

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

.brand { display: flex; flex-direction: column; }
.brand-logo {
  width: 80px;
  height: auto;
  margin-bottom: 8px;
}
.brand-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.2;
}
.brand-sub { font-size: 0.72rem; color: var(--muted); }

.btn-new {
  background: var(--accent);
  color: #153A21;
  border: none;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 1.2rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
  transition: opacity 0.15s;
}
.btn-new:hover { opacity: 0.85; }

.sidebar-stats {
  padding: 10px 18px;
  font-size: 0.78rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-sep { color: var(--border); }

.project-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 18px;
  cursor: pointer;
  transition: background 0.12s;
  border-left: 3px solid transparent;
}
.project-item:hover { background: var(--surface-hover); }
.project-item.active {
  background: var(--surface-hover);
  border-left-color: var(--accent);
}

.project-item-left { min-width: 0; }
.project-item-name {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-item-meta {
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  background: var(--accent);
  color: #153A21;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}
.logout-link {
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}
.logout-link:hover { color: var(--text); }

.loading { padding: 16px 18px; color: var(--muted); font-size: 0.85rem; }

/* ── Main ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
  padding: 40px;
}
.empty-icon { font-size: 2.5rem; }
.empty-title { font-size: 1.1rem; font-weight: 500; color: var(--text); }
.empty-sub { font-size: 0.85rem; max-width: 300px; }

/* Thread view */
.thread-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.thread-header {
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.thread-project-name {
  font-size: 1.05rem;
  font-weight: 600;
  flex: 1;
}
.thread-meta { font-size: 0.8rem; color: var(--muted); }

.btn-edit {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 5px 12px;
  font-family: var(--font);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn-edit:hover { border-color: var(--accent); color: var(--accent); }

/* Email thread */
.thread-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.email-bubble {
  max-width: 75%;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 0.875rem;
  line-height: 1.55;
}
.email-bubble.inbound {
  background: rgba(255,255,255,0.07);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.email-bubble.outbound {
  background: rgba(254,240,133,0.12);
  border: 1px solid rgba(254,240,133,0.2);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.bubble-meta {
  font-size: 0.74rem;
  color: var(--muted);
  margin-bottom: 7px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.bubble-from { font-weight: 500; color: var(--text); }
.bubble-subject { font-style: italic; }
.bubble-body { white-space: pre-wrap; word-break: break-word; }

.thread-empty {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 40px;
}

/* Reply box */
.reply-box {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reply-to, .reply-subject {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}
.reply-to:focus, .reply-subject:focus { border-color: var(--accent); }

.reply-textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.5;
}
.reply-textarea:focus { border-color: var(--accent); }

.reply-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}
.reply-sending { font-size: 0.82rem; color: var(--muted); }

.btn-send {
  background: var(--accent);
  color: #153A21;
  border: none;
  border-radius: 8px;
  padding: 9px 20px;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-send:hover { opacity: 0.88; }
.btn-send:disabled { opacity: 0.5; cursor: default; }

/* ── Modals ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.modal label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 4px;
}
.muted-label { color: var(--muted); font-weight: 400; }

.modal input, .modal select, .modal textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
.modal input:focus, .modal select:focus, .modal textarea:focus { border-color: var(--accent); }
.modal select option { background: var(--surface); }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}
.btn-cancel {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 9px 18px;
  font-family: var(--font);
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.btn-cancel:hover { border-color: var(--text); color: var(--text); }

.btn-create {
  background: var(--accent);
  color: #153A21;
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-create:hover { opacity: 0.88; }

.modal-error {
  font-size: 0.82rem;
  color: var(--danger);
  min-height: 16px;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ── */
@media (max-width: 600px) {
  :root { --sidebar-w: 100vw; }
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; min-width: 0; border-right: none; border-bottom: 1px solid var(--border); }
  .project-list { max-height: 40vh; }
  .main { height: 0; flex: 1; }
  .email-bubble { max-width: 90%; }
}
