:root {
  --green-deep: #123528;
  --green: #0e7a3d;
  --green-soft: #e8f1ea;
  --ink: #142414;
  --muted: #5f6f5f;
  --line: #d7e0d8;
  --paper: #f7f8f3;
  --white: #ffffff;
  --amber: #c47a1a;
  --danger: #9b2c2c;
  --shadow: 0 10px 30px rgba(18, 53, 40, 0.08);
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(14, 122, 61, 0.08), transparent 40%),
    linear-gradient(160deg, #eef3ee 0%, var(--paper) 45%, #f3efe6 100%);
}

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

.btn {
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.65rem 1rem;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { border-color: var(--green); }
.btn.primary {
  background: var(--green-deep);
  border-color: var(--green-deep);
  color: var(--white);
}
.btn.primary:hover { background: var(--green); border-color: var(--green); }
.btn.ghost {
  background: transparent;
  border-color: transparent;
}
.btn.ghost:hover { background: rgba(18, 53, 40, 0.06); }

.error {
  color: var(--danger);
  margin: 0.5rem 0 0;
  font-size: 0.92rem;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%);
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 2rem;
}
.eyebrow {
  margin: 0 0 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: var(--amber);
  font-weight: 700;
}
.login-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.4rem;
  line-height: 1.1;
}
.login-copy {
  color: var(--muted);
  margin: 0.75rem 0 1.4rem;
}
.login-card label,
.sidebar label,
#compose-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.9rem;
}
.login-card input,
.sidebar select,
#compose-form input,
#compose-form select,
#compose-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  background: var(--white);
}
#compose-form textarea { resize: vertical; }
.login-card .btn { width: 100%; margin-top: 0.25rem; }

.inbox-view { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  background: var(--green-deep);
  color: var(--white);
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--white);
  color: var(--green-deep);
  font-weight: 700;
}
.brand strong { display: block; font-size: 1rem; }
.brand small { color: rgba(255,255,255,0.72); }
.top-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.top-actions .btn { background: rgba(255,255,255,0.08); color: var(--white); border-color: rgba(255,255,255,0.18); }
.top-actions .btn:hover { background: rgba(255,255,255,0.16); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(255,255,255,0.72);
  padding: 0.9rem;
  overflow: auto;
}
.filter-label { margin-bottom: 0.75rem; }
.message-list { display: grid; gap: 0.45rem; }
.message-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 0.8rem 0.75rem;
  cursor: pointer;
}
.message-item:hover,
.message-item.active {
  background: var(--white);
  border-color: var(--line);
}
.message-item.unread { background: var(--green-soft); }
.message-item .from {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.92rem;
}
.message-item .subject {
  margin-top: 0.2rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.message-item .preview,
.message-item .meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.2rem;
}
.message-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  margin-left: 0.35rem;
}

.detail {
  padding: 1.25rem;
  overflow: auto;
}
.empty-detail {
  max-width: 420px;
  margin: 12vh auto 0;
  text-align: center;
  color: var(--muted);
}
.empty-detail h2 {
  font-family: var(--font-display);
  color: var(--ink);
  font-size: 2rem;
  margin: 0 0 0.5rem;
}

#message-detail {
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 14px;
  padding: 1.25rem 1.35rem 1.5rem;
  max-width: 860px;
}
.detail-header h2 {
  margin: 0.2rem 0 0.6rem;
  font-family: var(--font-display);
  font-size: 1.9rem;
  line-height: 1.2;
}
.detail-meta {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 1rem;
}
.detail-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}
.detail-body {
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.detail-body.html-body {
  white-space: normal;
}
.detail-body.html-body img { max-width: 100%; height: auto; }

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  width: min(560px, calc(100vw - 2rem));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(18, 53, 40, 0.35); }
#compose-form { padding: 1.1rem 1.2rem 1.25rem; }
#compose-form header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
#compose-form h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.7rem;
}
#compose-form footer { display: flex; justify-content: flex-end; }

.list-empty {
  color: var(--muted);
  padding: 1.5rem 0.5rem;
  text-align: center;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }
  .topbar { align-items: flex-start; flex-direction: column; }
}
