:root {
  --bg: #0f1117;
  --bg-elev: #161922;
  --bg-hover: #1e2330;
  --border: #262c3d;
  --text: #e6e9f0;
  --muted: #8b94a8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --warn: #f59e0b;
  --ok: #22c55e;
  --radius: 8px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fb;
    --bg-elev: #ffffff;
    --bg-hover: #eef2f7;
    --border: #dce2ec;
    --text: #111827;
    --muted: #64748b;
  }
}

* { 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);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
}

.brand {
  font-weight: 700;
  font-size: 16px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.12); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.nav-section { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 6px 10px 4px; }

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
}
.nav-link:hover, .nav-link.active { background: var(--bg-hover); text-decoration: none; }
.nav-link.active { font-weight: 600; color: var(--accent); }
.nav-details > summary { list-style: none; cursor: pointer; }
.nav-details > summary::-webkit-details-marker { display: none; }
.nav-sub { padding-left: 18px; }
.nav-sub span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--muted);
}
.domain-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.domain-pill, .label-pill {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 4px;
  color: #fff;
  font-weight: 500;
}
a.domain-pill, a.label-pill { color: #fff; text-decoration: none; }
.filter-bar { display: flex; gap: 8px; margin: -8px 0 12px; flex-wrap: wrap; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 12px;
  text-decoration: none;
}

.main { padding: 20px 24px; max-width: 1100px; width: 100%; }

.topbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.search-input {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.msg-list {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.msg-row {
  display: grid;
  grid-template-columns: 28px 180px 1fr 90px;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.msg-row:last-child { border-bottom: none; }
a.msg-link { color: inherit; }
a.msg-link:hover { text-decoration: underline; }
.msg-row:hover { background: var(--bg-hover); text-decoration: none; }
.msg-row.unread { font-weight: 600; }
.msg-snippet { color: var(--muted); font-weight: 400; margin-left: 6px; }
.msg-subject-col { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-from-col { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-date-col { text-align: right; color: var(--muted); font-size: 12px; }

.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 13px;
}
.alert-ok { background: rgba(34, 197, 94, 0.14); border: 1px solid var(--ok); }
.alert-err { background: rgba(239, 68, 68, 0.14); border: 1px solid var(--danger); }
.alert-warn { background: rgba(245, 158, 11, 0.14); border: 1px solid var(--warn); }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="email"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.auth-wrap {
  max-width: 400px;
  margin: 80px auto;
  padding: 24px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.email-frame {
  width: 100%;
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

pre.email-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  margin: 0;
}

code, pre.code-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 4px;
  word-break: break-all;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .msg-row { grid-template-columns: 24px 1fr 70px; }
  .msg-from-col { display: none; }
}
