:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e2e7ee;
  --text: #1c2430;
  --muted: #6b7686;
  --accent: #c0392b;
  --accent-dark: #96281b;
  --unread-bg: #fdf7f2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #96281b 0%, #c0392b 55%, #e67e22 100%);
  padding: 16px;
}
.login-card {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,.30);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
}
.login-logo { font-size: 44px; text-align: center; }
.login-card h1 { margin: 8px 0 2px; font-size: 22px; text-align: center; }
.login-sub { margin: 0 0 22px; text-align: center; color: var(--muted); font-size: 14px; }
.login-card label { font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
.login-card input {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
}
.login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-card button {
  margin-top: 20px;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-dark); }
.login-card button:disabled { opacity: .6; cursor: wait; }
.login-error {
  margin-top: 14px;
  background: #fdecea;
  color: #b3261e;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  text-align: center;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.spacer { flex: 1; }
.user-email { font-size: 13px; opacity: .9; overflow: hidden; text-overflow: ellipsis; }

.primary-btn {
  background: #fff;
  color: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.primary-btn:hover { background: #ffe9e5; }
.icon-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.topbar .icon-btn:hover { background: rgba(255,255,255,.15); }
.ghost-btn {
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn.danger { color: #b3261e; }

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

/* Sidebar */
.sidebar {
  width: 210px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar ul { list-style: none; margin: 8px 0; padding: 0; }
.sidebar li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 14px;
}
.sidebar li:hover { background: var(--bg); }
.sidebar li.active { background: #fdeae7; color: var(--accent-dark); font-weight: 600; }
.sidebar .count {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  padding: 1px 7px;
}

/* Message list */
.list-pane {
  width: 360px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.list-header {
  padding: 12px 14px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.message-list { flex: 1; overflow-y: auto; }
.msg-row {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.msg-row:hover { background: var(--bg); }
.msg-row.selected { background: #fdeae7; }
.msg-row.unread { background: var(--unread-bg); }
.msg-row .row1 { display: flex; gap: 8px; align-items: baseline; }
.msg-row .from {
  flex: 1;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-row.unread .from, .msg-row.unread .subject { font-weight: 700; }
.msg-row .date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.msg-row .subject {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.msg-row .preview {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.msg-row .clip { font-size: 12px; }
.empty-list { padding: 30px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.load-more {
  margin: 10px;
  padding: 9px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}

/* Detail */
.detail-pane { flex: 1; background: var(--panel); overflow-y: auto; min-width: 0; display: flex; flex-direction: column; }
.detail-empty { margin: auto; color: var(--muted); font-size: 15px; }
.detail { display: flex; flex-direction: column; flex: 1; padding: 16px 20px; min-height: 0; }
.detail-actions { display: flex; gap: 8px; margin-bottom: 12px; color: var(--text); flex-wrap: wrap; }
.detail h2 { margin: 0 0 10px; font-size: 19px; }
.detail-meta { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.meta-label { font-weight: 600; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.attachment {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  background: var(--bg);
}
.attachment:hover { border-color: var(--accent); }
.detail-body {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 14px;
  width: 100%;
  min-height: 300px;
  background: #fff;
}

/* Compose */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,20,30,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.compose {
  background: var(--panel);
  border-radius: 12px;
  width: 100%;
  max-width: 620px;
  padding: 0 18px 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
  max-height: 92vh;
  overflow-y: auto;
}
.compose-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 6px;
  font-size: 15px;
}
.compose label { font-size: 12px; font-weight: 600; margin: 10px 0 4px; color: var(--muted); }
.compose input, .compose textarea {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.compose input:focus, .compose textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.compose-foot { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.compose-foot .primary-btn { background: var(--accent); color: #fff; }
.compose-foot .primary-btn:hover { background: var(--accent-dark); }
.compose-foot .primary-btn:disabled { opacity: .6; cursor: wait; }
#compose-status { font-size: 13px; color: var(--muted); }

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c2430;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}

.only-mobile { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 52px;
    bottom: 0;
    left: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: 4px 0 18px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: translateX(0); }
  .list-pane { width: 100%; border-right: none; }
  .detail-pane {
    position: fixed;
    inset: 52px 0 0 0;
    z-index: 30;
    display: none;
  }
  .app.show-detail .detail-pane { display: flex; }
  .only-mobile { display: inline-block; }
  .brand span { display: none; }
  .user-email { display: none; }
}
