:root {
  --bg: #ffffff;
  --bg-subtle: #f4f5f7;
  --bg-hover: #eef0f3;
  --border: #e3e5e9;
  --text: #14171a;
  --text-muted: #6b7280;
  --accent: #2f5d50;       /* deep pine -- primary actions, unread mark */
  --accent-soft: #e4efec;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;

  --font-ui: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-weight: 400; }

/* ---------- Login ---------- */

.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-subtle);
}

.login-card {
  width: 320px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-mark {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin: 0 auto 4px;
}

.login-card h1 {
  margin: 0;
  font-size: 20px;
}

.login-sub {
  margin: 0 0 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login-card button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
}

.login-error {
  color: var(--danger);
  font-size: 12px;
  margin: 0;
}

/* ---------- App layout ---------- */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 220px 340px 1fr;
}

.sidebar {
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.brand {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark { color: var(--accent); }

.compose-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 9px 12px;
  font-weight: 600;
  cursor: pointer;
}
.compose-btn:hover { opacity: 0.92; }

.nav-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  gap: 8px;
}

.nav-item:hover { background: var(--bg-hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.nav-label { display: flex; align-items: center; gap: 8px; }

.nav-tag-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.nav-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 1px 6px;
  border-radius: 10px;
}

.nav-item.active .nav-count {
  background: rgba(47, 93, 80, 0.15);
  color: var(--accent);
}

.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 12px 10px 4px;
}

.nav-manage {
  color: var(--text-muted);
  font-size: 12px;
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 4px;
}

.sidebar-bottom {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.export-row {
  display: flex;
  gap: 6px;
}

.ghost-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}
.ghost-btn:hover { background: var(--bg-hover); }
.ghost-btn.danger { color: var(--danger); border-color: var(--danger-soft); }
.ghost-btn.danger:hover { background: var(--danger-soft); }

.logout-btn { align-self: flex-start; }

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:hover { opacity: 0.92; }

/* ---------- List pane ---------- */

.list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.list-toolbar {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.list-toolbar h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.toolbar-controls {
  display: flex;
  gap: 8px;
}

.toolbar-controls input,
.toolbar-controls select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
}

#search-input { flex: 1; min-width: 0; }

.message-list {
  flex: 1;
  overflow-y: auto;
}

.message-row {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  border-left: 3px solid transparent;
}

.message-row:hover { background: var(--bg-hover); }
.message-row.selected { background: var(--accent-soft); }

.message-row.unread .message-from,
.message-row.unread .message-subject {
  font-weight: 700;
}

.message-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 6px;
  flex-shrink: 0;
}
.message-row:not(.unread) .message-unread-dot { background: transparent; }

.message-main { flex: 1; min-width: 0; }

.message-top-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.message-from {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.message-subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.message-tags {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.tag-chip {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.list-empty, .reading-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}

/* ---------- Reading pane ---------- */

.reading-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.reading-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.reading-header {
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--border);
}

.reading-header h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.reading-meta {
  font-size: 13px;
  line-height: 1.6;
}

.reading-tags {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.reading-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
  position: relative;
}

.apply-filter-menu { position: relative; }

.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  min-width: 180px;
  z-index: 10;
  overflow: hidden;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}
.dropdown-item:hover { background: var(--bg-hover); }

.reading-attachments {
  padding: 10px 24px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.attachment-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 9px;
  text-decoration: none;
  color: var(--text);
}
.attachment-chip:hover { background: var(--bg-hover); }

.reading-body {
  flex: 1;
  border: none;
  width: 100%;
}

/* ---------- Modals ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 23, 26, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--bg);
  border-radius: var(--radius);
  width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { margin: 0; }

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
}

.compose-modal label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.compose-modal input,
.compose-modal textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-weight: 400;
  color: var(--text);
  resize: vertical;
}

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

.filters-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}

.filter-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.filter-row-name { flex: 1; font-weight: 600; }
.filter-row-rules { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

.new-filter-row {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.new-filter-row h4 { margin: 0; font-size: 13px; }

.new-filter-row input,
.new-filter-row select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
}

.rule-builder {
  display: flex;
  gap: 6px;
}
.rule-builder select { flex: 1; }
.rule-builder input { flex: 1; }

.hint {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 180px 1fr; }
  .reading-pane { display: none; }
}
