:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6ebf2;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: #eff6ff;
  --danger: #ef4444;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --font: "Segoe UI", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-light { background: var(--surface-2); }
.btn-block { width: 100%; }

.muted { color: var(--muted); font-size: 0.875rem; }
.alert { padding: 0.75rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.alert-error { background: #fef2f2; color: #b91c1c; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background: linear-gradient(180deg, #eef4ff 0%, #f8fafc 100%);
}
.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  padding: 2rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 0.25rem; }
.auth-card-wide { width: min(520px, 100%); }
.auth-card label { display: block; margin: 1rem 0; font-size: 0.875rem; font-weight: 600; }
.auth-card input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}
.auth-hint { margin: 1rem 0 0; text-align: center; }
.otp-input {
  letter-spacing: 0.35em;
  font-size: 1.25rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.totp-setup {
  display: grid;
  gap: 1rem;
  justify-items: center;
  margin: 1.25rem 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
}
.totp-qr {
  border-radius: 12px;
  background: #fff;
  padding: 0.5rem;
}
.totp-secret {
  display: block;
  margin-top: 0.35rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: #fff;
  border: 1px dashed var(--border);
  word-break: break-all;
  font-size: 0.85rem;
}
.settings-shell { max-width: 720px; margin: 0 auto; padding: 1.5rem; }
.settings-header { margin-bottom: 1.25rem; }
.settings-header h1 { margin: 0.35rem 0 0.15rem; }
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
}
.settings-card h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.status-ok { color: #15803d; font-weight: 600; }
.status-warn { color: #b45309; font-weight: 600; }

.mail-app {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px 360px minmax(0, 1fr);
  background: var(--bg);
}

.mail-nav {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  margin-bottom: 1rem;
}
.avatar, .mail-item-avatar, .reading-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #93c5fd, #3b82f6);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.profile-name { font-weight: 700; font-size: 0.95rem; }
.profile-email { color: var(--muted); font-size: 0.8rem; word-break: break-all; }

.compose-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  margin-bottom: 1rem;
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.25);
}
.compose-btn:hover { background: var(--accent-hover); color: #fff; }

.account-picker select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 0.75rem;
}

.folder-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
  overflow: auto;
}
.folder-link {
  display: grid;
  grid-template-columns: 20px 1fr auto auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  color: var(--text);
  font-size: 0.92rem;
}
.folder-link:hover,
.folder-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.folder-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.folder-count {
  color: var(--muted);
  font-size: 0.78rem;
  min-width: 1.5rem;
  text-align: right;
}

.folder-icon {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 3px;
  opacity: 0.8;
}
.folder-icon-star { border-radius: 50%; border-style: dotted; }
.folder-icon-sent { transform: rotate(45deg); border-radius: 2px; }

.nav-footer {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.nav-settings {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
}
.sync-form { margin-top: 0.25rem; }

.mail-list-pane {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.list-header {
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.list-header h1 {
  margin: 0;
  font-size: 1.35rem;
}
.list-header p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.list-search {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.list-search input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.mail-list {
  overflow: auto;
  flex: 1;
}
.mail-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 0.75rem;
  align-items: start;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  color: inherit;
  position: relative;
}
.mail-item:hover,
.mail-item.selected {
  background: var(--accent-soft);
}
.mail-item.unread .mail-item-from,
.mail-item.unread .mail-item-subject {
  font-weight: 700;
}
.mail-item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}
.mail-item-from {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mail-item-date {
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}
.mail-item-subject {
  font-size: 0.88rem;
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mail-item-snippet {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unread-dot {
  position: absolute;
  left: 0.35rem;
  top: 1.2rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.attach-icon {
  grid-column: 3;
  grid-row: 1 / span 3;
  align-self: center;
  font-size: 0.85rem;
}

.mail-reading-pane {
  background: var(--bg);
  min-height: 0;
  overflow: auto;
  padding: 1rem;
}
.reading-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.reading-actions { display: flex; gap: 0.35rem; }
.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.reading-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem 1.5rem;
  min-height: calc(100vh - 4rem);
}
.reading-meta {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  margin-bottom: 1rem;
}
.reading-from { font-weight: 700; font-size: 1rem; }
.reading-subject {
  margin: 0 0 1rem;
  font-size: 1.5rem;
  line-height: 1.3;
}
.reading-content { margin-bottom: 1.5rem; }
.html-frame {
  width: 100%;
  min-height: 55vh;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.plain-body {
  line-height: 1.7;
  white-space: pre-wrap;
}
.reading-footer {
  display: flex;
  gap: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--muted);
}
.reading-empty .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.compose-page, .settings-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
}
.compose-form label { display: block; margin-bottom: 0.85rem; font-size: 0.875rem; font-weight: 600; }
.compose-form input, .compose-form select, .compose-form textarea {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font: inherit;
}
.compose-form textarea { font-family: ui-monospace, monospace; font-size: 0.8rem; }
.compose-toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }
.checkbox { display: flex !important; align-items: center; gap: 0.5rem; }
.ai-output { background: var(--surface-2); padding: 1rem; border-radius: 10px; white-space: pre-wrap; }
.hidden { display: none; }

.settings-grid { display: grid; gap: 2rem; grid-template-columns: 1fr 1fr; }
.account-list { list-style: none; padding: 0; }
.account-list li {
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 0.5rem;
  background: #fff;
}
.account-list span { display: block; color: var(--muted); font-size: 0.875rem; }

@media (max-width: 1100px) {
  .mail-app { grid-template-columns: 220px 320px minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .mail-app { grid-template-columns: 1fr; }
  .mail-nav, .mail-list-pane { display: none; }
  .mail-reading-pane { padding: 0.75rem; }
}
