:root {
  --brand: #e03a33;
  --brand-dark: #c2241e;
  --ink: #1b2430;
  --muted: #6b7684;
  --line: #e2e6ea;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ok: #1c8c5a;
  --err: #c0392b;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* The `hidden` attribute must win over the layout rules below
   (.auth-wrap uses display:flex, which would otherwise override it). */
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- layout */
.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--ink);
  color: #fff;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-weight: 600;
  letter-spacing: .2px;
}

.topbar .brand img { height: 26px; display: block; }
.topbar .brand span { font-size: 13px; color: #9aa5b1; font-weight: 400; }

.topbar .who {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: #c9d1d9;
}

.main { flex: 1; display: flex; min-height: 0; }

/* ------------------------------------------------------------- auth page */
.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .04);
  overflow: hidden;
}

.auth-head {
  padding: 26px 28px 18px;
  border-bottom: 1px solid var(--line);
}

.auth-logo {
  margin-bottom: 16px;
}

.auth-logo img {
  height: 30px;
  display: block;
}

.auth-head h1 {
  margin: 0 0 4px;
  font-size: 21px;
  font-weight: 600;
}

.auth-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  flex: 1;
  border: 0;
  background: none;
  padding: 13px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .12s, border-color .12s;
}

.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.auth-body { padding: 22px 28px 26px; }

.field { margin-bottom: 15px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #39424f;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cfd6dd;
  border-radius: 5px;
  font: inherit;
  font-size: 14.5px;
  background: #fff;
  transition: border-color .12s, box-shadow .12s;
}

.field input:focus {
  outline: 0;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(224, 58, 51, .12);
}

.field .hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
}

.field .hint code {
  background: #eef1f4;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11.5px;
}

.btn {
  display: inline-block;
  width: 100%;
  padding: 11px 16px;
  border: 0;
  border-radius: 5px;
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  transition: background .12s;
  text-align: center;
}

.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn.ghost {
  background: none;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 500;
}

.btn.ghost:hover { background: #f2f4f6; color: var(--ink); }

.msg {
  padding: 10px 12px;
  border-radius: 5px;
  font-size: 13.5px;
  margin-bottom: 15px;
  display: none;
}

.msg.show { display: block; }
.msg.error { background: #fdecea; color: var(--err); border: 1px solid #f5c6c2; }
.msg.ok { background: #e8f6ef; color: var(--ok); border: 1px solid #bfe3d1; }

.auth-foot {
  padding: 14px 28px 20px;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: #fafbfc;
}

/* ------------------------------------------------------------ mail client */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.side-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: #98a2ae;
}

.folders { list-style: none; margin: 0; padding: 8px 0; }

.folders li button {
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  padding: 9px 16px;
  font: inherit;
  font-size: 14px;
  color: #39424f;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.folders li button:hover { background: #f2f4f6; }
.folders li button.active { background: #fdeceb; color: var(--brand); font-weight: 600; }
.folders li button .count { font-size: 11.5px; color: #98a2ae; font-weight: 400; }

.side-foot {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.side-foot a { display: block; margin-bottom: 6px; }

.content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toolbar {
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar input {
  padding: 7px 11px;
  border: 1px solid #cfd6dd;
  border-radius: 5px;
  font: inherit;
  font-size: 13.5px;
  width: 220px;
}

.toolbar input:focus {
  outline: 0;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(224, 58, 51, .12);
}

.tbtn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 5px;
  padding: 7px 13px;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  color: #39424f;
  white-space: nowrap;
}

.tbtn:hover { background: #f2f4f6; }
.tbtn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.tbtn.primary:hover { background: var(--brand-dark); }
.tbtn:disabled { opacity: .5; cursor: not-allowed; }

.list {
  flex: 1;
  overflow-y: auto;
  background: var(--panel);
}

.row {
  display: flex;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid #f0f2f4;
  cursor: pointer;
  align-items: baseline;
}

.row:hover { background: #fafbfc; }
.row.active { background: #fdeceb; }

.row .from {
  width: 190px;
  flex: 0 0 190px;
  font-weight: 600;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row.unread .from { color: var(--brand); }

.row .subj {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #39424f;
}

.row.unread .subj { font-weight: 600; color: var(--ink); }

.row .when {
  flex: 0 0 auto;
  font-size: 12px;
  color: #98a2ae;
  white-space: nowrap;
}

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.loading { padding: 40px 20px; text-align: center; color: var(--muted); }

/* --------------------------------------------------------------- reader */
.reader {
  flex: 1;
  overflow-y: auto;
  background: var(--panel);
  padding: 22px 26px 40px;
}

.reader h1 {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.35;
}

.reader .meta {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 18px;
  font-size: 13.5px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.reader .meta b { color: #39424f; font-weight: 600; }

.reader .body {
  font-size: 14.5px;
  line-height: 1.65;
  color: #26303b;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.reader .body img { max-width: 100%; height: auto; }
.reader .body table { max-width: 100%; border-collapse: collapse; }
.reader .body pre { background: #f4f6f8; padding: 12px; border-radius: 5px; overflow-x: auto; }

.attach-list {
  margin: 18px 0 0;
  padding: 12px 14px;
  background: #f7f9fa;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 13px;
}

.attach-list h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: #98a2ae; }
.attach-list ul { margin: 0; padding: 0; list-style: none; }
.attach-list li { padding: 3px 0; color: #39424f; }

/* -------------------------------------------------------------- compose */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.overlay.show { display: flex; }

.compose {
  background: var(--panel);
  border-radius: 7px;
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}

.compose header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.compose header button {
  border: 0;
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

.compose .body { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.compose .field { margin: 0; }
.compose textarea {
  width: 100%;
  min-height: 240px;
  padding: 11px 12px;
  border: 1px solid #cfd6dd;
  border-radius: 5px;
  font: inherit;
  font-size: 14px;
  resize: vertical;
}

.compose footer {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.compose footer .btn { width: auto; padding: 9px 20px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 12px 18px;
  border-radius: 5px;
  font-size: 14px;
  z-index: 100;
  display: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}

.toast.show { display: block; }
.toast.ok { background: #1c8c5a; color: #fff; }
.toast.err { background: var(--err); color: #fff; }

@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 30; height: 100%; transform: translateX(-100%); transition: transform .18s; }
  .sidebar.open { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .toolbar input { width: 130px; }
  .row .from { width: 110px; flex-basis: 110px; }
}
