/* Dark Material palette matching the Android client (MyIMAPemailTheme darkTheme = true). */
:root {
  --bg: #141218;
  --surface: #1d1b20;
  --surface-2: #272329;
  --surface-3: #322d38;
  --outline: #49454f;
  --text: #e6e0e9;
  --muted: #cac4d0;
  --primary: #d0bcff;
  --on-primary: #381e72;
  --error: #f2b8b5;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.error { color: var(--error); margin: 8px 0 0; }
[hidden] { display: none !important; }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.primary-btn {
  background: var(--primary);
  color: var(--on-primary);
  border: 0;
  border-radius: 20px;
  padding: 8px 18px;
  font-weight: 600;
}
.icon-btn {
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 17px;
}
.icon-btn:hover { background: var(--surface-3); }

/* ---------- Login ---------- */
.login-view { display: grid; place-items: center; min-height: 100%; padding: 24px; }
.login-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 16px;
  padding: 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card p { margin: 0 0 20px; font-size: 13px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.login-card input { margin-top: 6px; }
.login-card .row { display: flex; gap: 12px; }
.login-card .grow { flex: 1; }
.login-card .port { width: 92px; }
/* The domain is fixed, so it sits inside the field as static text. */
.suffixed {
  display: flex;
  align-items: center;
  margin-top: 6px;
  background: var(--surface-2);
  border: 1px solid var(--outline);
  border-radius: 8px;
}
.suffixed:focus-within { outline: 2px solid var(--primary); outline-offset: -1px; }
.suffixed input {
  margin-top: 0;
  min-width: 0;
  background: transparent;
  border: 0;
  padding-right: 0;
}
.suffixed input:focus { outline: none; }
.suffixed .suffix {
  padding: 0 12px 0 2px;
  color: var(--muted);
  white-space: nowrap;
}
.login-card button[type=submit] {
  width: 100%;
  margin-top: 6px;
  background: var(--primary);
  color: var(--on-primary);
  border: 0;
  border-radius: 24px;
  padding: 12px;
  font-weight: 600;
}
.login-card button[disabled] { opacity: .6; cursor: default; }

/* ---------- Layout ---------- */
.mail-view { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--outline);
}
.topbar strong { font-size: 16px; }
.unread-toggle { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.unread-toggle input { width: auto; }
.chip {
  background: var(--primary); color: var(--on-primary);
  border-radius: 12px; padding: 2px 10px; font-size: 13px; font-weight: 600;
}

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

.folder-pane {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--outline);
  overflow-y: auto;
  padding: 12px 8px;
}
.account-email { font-size: 12px; color: var(--muted); padding: 0 10px 10px; word-break: break-all; }
.folder-pane a {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  word-break: break-all;
}
.folder-pane a:hover { background: var(--surface-2); }
.folder-pane a.active { background: var(--surface-3); color: var(--primary); font-weight: 600; }

.list-pane {
  width: 380px;
  flex-shrink: 0;
  border-right: 1px solid var(--outline);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.message-list { flex: 1; }
.status { padding: 14px; font-size: 13px; color: var(--muted); }

.msg {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--surface-2);
  cursor: pointer;
}
.msg:hover { background: var(--surface-2); }
.msg.active { background: var(--surface-3); }
.msg input { width: auto; flex-shrink: 0; margin-top: 4px; }
.msg-main { min-width: 0; flex: 1; }
.msg-sender { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.msg-sender span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-date { flex-shrink: 0; font-size: 12px; }
.msg-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .msg-subject, .msg.unread .msg-sender span:first-child { font-weight: 700; color: var(--text); }

.reader-pane { flex: 1; overflow-y: auto; min-width: 0; }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); }
#reader { padding: 20px 24px 40px; }
#reader h2 { margin: 0 0 12px; font-size: 20px; }
.reader-meta { font-size: 13px; margin-bottom: 14px; }
.reader-meta > div { margin-bottom: 2px; word-break: break-word; }
.reader-meta .muted { display: inline-block; width: 36px; }
.reader-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.reader-actions button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--outline);
  border-radius: 18px;
  padding: 7px 16px;
}
.reader-actions button:hover { background: var(--surface-3); }
.reader-body { border-top: 1px solid var(--outline); padding-top: 16px; }
.reader-body pre { white-space: pre-wrap; word-wrap: break-word; margin: 0; font: inherit; }
.reader-body iframe { width: 100%; border: 0; background: #fff; border-radius: 8px; }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.attachment {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--outline);
  border-radius: 16px; padding: 6px 12px; font-size: 13px;
  color: var(--text); text-decoration: none;
}
.attachment:hover { background: var(--surface-3); }
.attachment button { background: none; border: 0; color: var(--muted); padding: 0; font-size: 15px; }

/* ---------- Compose ---------- */
.compose-dialog {
  width: min(720px, 94vw);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--outline);
  border-radius: 16px;
  padding: 0;
}
.compose-dialog::backdrop { background: rgba(0, 0, 0, .6); }
#compose-form { padding: 16px 20px 20px; }
.compose-header { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.field { position: relative; display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.field label { width: 58px; flex-shrink: 0; font-size: 13px; color: var(--muted); }
.suggestions {
  position: absolute;
  top: 100%;
  left: 70px;
  right: 0;
  z-index: 10;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--surface-3);
  border: 1px solid var(--outline);
  border-radius: 8px;
  max-height: 210px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.suggestions li { padding: 9px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.suggestions li:hover, .suggestions li.active { background: var(--primary); color: var(--on-primary); }
#body { min-height: 220px; resize: vertical; }
.quoted {
  margin: 12px 0 0;
  padding: 10px;
  max-height: 150px;
  overflow-y: auto;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

.move-dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--outline); border-radius: 16px;
  width: min(360px, 92vw);
}
.move-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.move-dialog h3 { margin: 0 0 12px; }
.move-list { max-height: 50vh; overflow-y: auto; margin-bottom: 12px; }
.move-list a { display: block; padding: 10px; border-radius: 8px; cursor: pointer; color: var(--text); }
.move-list a:hover { background: var(--surface-2); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--outline); border-radius: 8px;
  padding: 12px 20px; z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .folder-pane { position: absolute; z-index: 20; height: calc(100% - 55px); }
  .folder-pane:not(.open) { display: none; }
  .list-pane { width: 340px; }
}
@media (max-width: 720px) {
  .list-pane { width: 100%; border-right: 0; }
  .reader-pane { display: none; }
  body.reading .list-pane { display: none; }
  body.reading .reader-pane { display: block; }
  .unread-toggle { display: none; }
  .topbar strong { font-size: 14px; }
  .field { flex-wrap: wrap; }
  .suggestions { left: 0; }
}
