:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --accent: #3b5bfd;
  --accent-contrast: #ffffff;
  --danger: #d64545;
  --unread-bg: #eef1ff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1d2028;
    --border: #2b2f3a;
    --text: #e6e8ee;
    --text-muted: #9aa1ae;
    --accent: #6b8cff;
    --accent-contrast: #0d1020;
    --danger: #ef6a6a;
    --unread-bg: #1c2340;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.compose-btn {
  display: block;
  text-align: center;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-weight: 600;
}
.compose-btn:hover { text-decoration: none; opacity: 0.9; }

.mailbox-switcher select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.85rem;
}

.folder-list { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }
.folder-link {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.folder-link:hover { background: var(--bg); text-decoration: none; }
.folder-link.active { background: var(--unread-bg); color: var(--accent); font-weight: 600; }

.unread-badge {
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.05rem 0.45rem;
  line-height: 1.4;
}

.user-info {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.user-email { margin-bottom: 0.4rem; word-break: break-all; }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
}

.content {
  flex: 1;
  padding: 1.5rem 2rem;
  max-width: 900px;
  overflow-x: auto;
}

.toolbar h1 { display: flex; align-items: center; gap: 0.75rem; font-size: 1.3rem; }
.count-badge { font-size: 0.85rem; font-weight: 400; color: var(--text-muted); }

.message-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-top: 1rem; }
.message-row {
  display: grid;
  grid-template-columns: 200px 1fr 160px;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  text-decoration: none;
}
.message-row:last-child { border-bottom: none; }
.message-row:hover { background: var(--bg); text-decoration: none; }
.message-row.unread { background: var(--unread-bg); font-weight: 600; }
.col-from, .col-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-date { color: var(--text-muted); font-size: 0.85rem; text-align: right; }
.flag-star { color: #e0a800; margin-right: 0.3rem; }

.empty-state { color: var(--text-muted); padding: 2rem 0; text-align: center; }

.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; color: var(--text-muted); }

.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2.5rem; width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 1.3rem; margin-top: 0; }

form label { display: block; margin-bottom: 1rem; font-size: 0.9rem; color: var(--text-muted); }
form input[type=text], form input[type=email], form input[type=password], form textarea, form select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
form textarea { resize: vertical; font-family: inherit; }

.btn-primary, .btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); font-weight: 600; }
.btn-danger { color: var(--danger); border-color: var(--danger); }

.inline-form { display: inline-block; margin-right: 0.4rem; }

.alert { padding: 0.7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: rgba(214, 69, 69, 0.12); color: var(--danger); border: 1px solid var(--danger); }
.alert-success { background: rgba(52, 168, 83, 0.12); color: #2e7d32; border: 1px solid #2e7d32; }

.settings-link { display: block; font-size: 0.85rem; margin-bottom: 0.4rem; }
.settings-section { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem 1.5rem; margin-bottom: 1.5rem; max-width: 640px; }
.settings-section h2 { margin-top: 0; font-size: 1.05rem; }
.settings-section .hint { color: var(--text-muted); font-size: 0.85rem; margin-top: -0.5rem; margin-bottom: 1rem; }
.checkbox-label { display: flex !important; align-items: center; gap: 0.5rem; }
.checkbox-label input[type=checkbox] { width: auto; margin: 0; }
.date-row { display: flex; gap: 1rem; }
.date-row label { flex: 1; }

.message-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 1.25rem; }
.message-meta { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.2rem; }
.message-meta strong { color: var(--text); }

.attachments { margin-bottom: 1.25rem; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.4rem; }
.attachment-chip {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.85rem;
}
.attachment-size { color: var(--text-muted); }

.message-body { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }
.plain-body { white-space: pre-wrap; word-wrap: break-word; font-family: inherit; margin: 0; }
.body-frame { width: 100%; min-height: 200px; border: none; background: var(--surface); }

.error-page { padding: 3rem; text-align: center; }

@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .content { padding: 1rem; max-width: 100%; }
  .message-row { grid-template-columns: 1fr; }
  .col-date { text-align: left; }
}
