:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-deep: #0d1117;
  --border: #d0d7de;
  --border-soft: #e7eaee;
  --text: #1f2328;
  --muted: #6e7781;
  --accent: #0969da;
  --accent-hover: #0860ca;
  --accent-soft: #ddf4ff;
  --danger: #cf222e;
  --danger-soft: #ffebe9;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 8px 28px rgba(15,23,42,0.08);
}
* { box-sizing: border-box; }
html, body, #root { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg-soft);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

/* AUTH */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 36px 32px 28px;
  width: 100%;
  max-width: 420px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 6px;
  color: var(--text);
}
.auth-brand-mark { color: var(--accent); font-size: 22px; line-height: 1; }
.auth-card h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 6px 0 4px;
}
.auth-card .auth-sub {
  color: var(--muted);
  margin: 0 0 22px;
  font-size: 13px;
}
.auth-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 18px;
}
.auth-tab {
  background: transparent;
  border: 0;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.auth-tab.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.auth-form input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  background: var(--bg);
}
.auth-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.auth-fld { display: flex; flex-direction: column; }
.auth-row { display: flex; gap: 10px; }
.auth-row .auth-fld { flex: 1; }
.auth-suffix {
  display: flex;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}
.auth-username-row {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}
.auth-username-row input {
  border: 0;
  border-radius: 0;
}
.auth-username-row input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.auth-username-suffix {
  background: var(--bg-soft);
  padding: 0 12px;
  display: flex;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  border-left: 1px solid var(--border-soft);
}
.auth-cta {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 500;
  margin-top: 6px;
}
.auth-cta:hover { background: var(--accent-hover); }
.auth-cta:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-msg {
  margin: 12px 0 0;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.auth-msg.err { background: var(--danger-soft); color: var(--danger); }
.auth-msg.ok { background: #dafbe1; color: #1a7f37; }
.auth-foot {
  text-align: center;
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted);
}
.auth-foot a { color: var(--muted); }

/* APP SHELL */
.app-shell {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
}
.app-top {
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
}
.app-brand-mark { color: var(--accent); font-size: 20px; line-height: 1; }
.app-top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.app-mailbox {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-soft);
  padding: 5px 10px;
  border-radius: 999px;
}
.app-mailbox strong { color: var(--text); }
.app-btn {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
}
.app-btn:hover { background: var(--accent-hover); }
.app-btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 13px;
}
.app-btn-ghost:hover { background: var(--bg-soft); }

/* MAIN PANES */
.app-main {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 0;
}
.list-pane {
  background: var(--bg);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.list-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}
.list-head h2 { font-size: 14px; font-weight: 600; color: var(--text); margin: 0; }
.list-refresh {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
}
.list-refresh:hover { background: var(--bg-soft); color: var(--text); }
.list-scroll { flex: 1; overflow-y: auto; }
.list-empty {
  padding: 32px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.list-empty strong { display: block; color: var(--text); margin-bottom: 4px; font-size: 14px; }
.list-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border-soft);
  padding: 14px 18px;
  cursor: pointer;
  display: block;
}
.list-item:hover { background: var(--bg-soft); }
.list-item.on { background: var(--accent-soft); }
.list-from {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-subj {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-meta {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

/* MESSAGE PANE */
.msg-pane {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.msg-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
}
.msg-head {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg-subj { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.msg-meta { font-size: 12px; color: var(--muted); }
.msg-meta strong { color: var(--text); font-weight: 500; }
.msg-body {
  flex: 1;
  overflow: auto;
  padding: 0;
}
.msg-iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
}
.msg-text {
  padding: 22px 24px;
  font-size: 14px;
  white-space: pre-wrap;
  font-family: inherit;
  line-height: 1.6;
}

/* COMPOSE DRAWER */
.compose-drawer {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 520px;
  max-width: calc(100vw - 36px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(15,23,42,0.18);
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}
.compose-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-soft);
  border-top-left-radius: 14px;
  border-top-right-radius: 14px;
}
.compose-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.compose-close {
  background: transparent;
  border: 0;
  font-size: 18px;
  color: var(--muted);
  padding: 0 6px;
  cursor: pointer;
}
.compose-fields {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.compose-fld {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 8px;
}
.compose-fld label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  width: 56px;
  flex-shrink: 0;
}
.compose-fld input {
  flex: 1;
  border: 0;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  padding: 4px 0;
  background: transparent;
}
.compose-body textarea {
  flex: 1;
  width: 100%;
  border: 0;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  padding: 12px 16px;
  background: transparent;
  min-height: 200px;
  line-height: 1.6;
}
.compose-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}
.compose-foot .app-btn { padding: 7px 18px; }
.compose-status { font-size: 12px; color: var(--muted); }
.compose-status.err { color: var(--danger); }
.compose-status.ok { color: #1a7f37; }

@media (max-width: 720px) {
  .app-main { grid-template-columns: 1fr; }
  .list-pane.hidden, .msg-pane.hidden { display: none; }
  .compose-drawer { right: 8px; bottom: 8px; left: 8px; width: auto; }
}
