:root {
  --bg: #f6f0e4;
  --bg2: #fffdf8;
  --bg3: #fff6e8;
  --paper: #ffffff;
  --line: #ead9c2;
  --text: #2a241c;
  --muted: #7a6d5d;
  --accent: #e45c2b;
  --accent2: #f0783d;
  --sky: #2f8fbf;
  --danger: #c43c3c;
  --unread: #fff3c9;
  --sel: #ffe8c4;
  --shadow: 0 10px 30px rgba(120, 70, 20, 0.08);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 "Segoe UI", "Avenir Next", "Nunito Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.primary {
  background: linear-gradient(180deg, var(--accent2), var(--accent));
  border: 0;
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-weight: 650;
  box-shadow: 0 6px 14px rgba(228, 92, 43, 0.25);
}
.primary:hover { filter: brightness(1.06); }
.ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 999px;
}
.ghost:hover { background: var(--bg3); }
.ghost.small { padding: 4px 10px; font-size: 12px; }
#btn-delete-all { color: var(--danger); border-color: #f0c4c4; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; }

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 480px at 15% -10%, #ffe08a 0%, transparent 60%),
    radial-gradient(800px 500px at 110% 20%, #ffb48a 0%, transparent 55%),
    linear-gradient(180deg, #fff6d8, #f4e7d2 45%, #e7f4f8);
}
.login-card {
  width: 380px;
  background: rgba(255, 253, 248, 0.92);
  padding: 36px 32px;
  border-radius: 24px;
  border: 1px solid #f0d9b5;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 750;
  letter-spacing: -0.03em;
  color: #c94b1a;
}
.login-card p { margin: 0; }
.remember { flex-direction: row !important; align-items: center; gap: 8px !important; font-size: 14px !important; color: var(--text) !important; }
.login-card label, .sheet label, #settings-form label, #password-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}
.login-card input, .sheet input, .sheet textarea,
#settings-form input, #settings-form textarea,
#password-form input, .search-wrap input {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.login-card input:focus, .sheet input:focus, .search-wrap input:focus,
.sheet textarea:focus {
  outline: 3px solid rgba(228, 92, 43, 0.18);
  border-color: var(--accent2);
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: 64px 1fr;
  grid-template-columns: 1fr;
  background: var(--bg);
}
.body-panes {
  display: flex;
  min-height: 0;
  height: 100%;
}
.splitter {
  flex: 0 0 6px;
  cursor: col-resize;
  background: var(--line);
  position: relative;
  z-index: 2;
  touch-action: none;
}
.splitter:hover, .splitter.dragging { background: var(--accent2); }
body.resizing, body.resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}
.top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  background: #fffdf8;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 22px;
  color: #d3541a;
  min-width: 120px;
}
.brand img, .login-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
  background: #fff6e8;
}
.login-logo {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  margin: 0 auto 4px;
  box-shadow: var(--shadow);
}
.search-wrap { flex: 1; }
.search-wrap input { width: 100%; background: var(--bg3); }
.mail-count {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: #fff6e8;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
  font-weight: 750;
}
.mail-count.has-new {
  background: linear-gradient(180deg, var(--accent2), var(--accent));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 14px rgba(228, 92, 43, 0.25);
}
#mail-count-num { font-size: 18px; line-height: 1; }
.mail-count-lbl { font-size: 12px; font-weight: 650; }
.who { display: flex; align-items: center; gap: 8px; color: var(--muted); }
#account-switch {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  max-width: 280px;
}
.row-form.wrap { flex-wrap: wrap; align-items: center; }
.row-form.wrap select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
}

.folders {
  flex: 0 0 230px;
  width: 230px;
  min-width: 140px;
  background: #fff9ef;
  overflow: auto;
  padding: 14px 10px;
}
.folder {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 4px;
}
.folder:hover { background: #ffe9c8; }
.folder.active {
  background: #ffd9a3;
  font-weight: 700;
}
.folder-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.folder .ico { color: #c97a3a; flex: 0 0 16px; }
.folder.special-trash .ico { color: var(--danger); }
.folder.drop-target {
  outline: 2px dashed var(--accent);
  background: #ffe0cc;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.trash-btn { color: var(--danger); border-color: #f0c4c4; }
.row-trash {
  grid-column: 4;
  grid-row: 1 / span 2;
  align-self: center;
  justify-self: end;
  opacity: 0.2;
  border: 0;
  background: transparent;
  padding: 2px;
  color: var(--danger);
  border-radius: 8px;
  cursor: pointer;
}
.msg:hover .row-trash, .row-trash:focus { opacity: 1; background: #fdeaea; }
.folder .badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
  font-size: 11px;
  padding: 1px 7px;
}
.folder-actions { margin-top: 14px; }

.list {
  flex: 0 0 390px;
  width: 390px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--paper);
}
.list-toolbar, .pager {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  background: #fffaf1;
}
.pager { border-bottom: 0; border-top: 1px solid var(--line); }
.list-filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
  flex-wrap: wrap;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text);
}
.chip:hover { background: var(--bg3); }
.chip.active {
  background: #ffd9a3;
  font-weight: 700;
  border-color: #f0c48a;
}
.sort-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}
#sort-by {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--text);
}
.msg-list { flex: 1; overflow: auto; }
.msg {
  display: grid;
  grid-template-columns: 22px 1fr auto 28px;
  gap: 4px 8px;
  padding: 12px 14px;
  border-bottom: 1px solid #f1e4d2;
  cursor: pointer;
}
.msg:hover { background: #fff8ec; }
.msg.unseen { font-weight: 750; background: var(--unread); }
.msg.active { background: var(--sel); }
.msg .from { grid-column: 2; }
.msg .date { grid-column: 3; color: var(--muted); font-size: 12px; }
.msg .subj {
  grid-column: 2 / 4;
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.star { color: #e0a100; }

.read {
  flex: 1 1 auto;
  min-width: 240px;
  overflow: auto;
  background:
    linear-gradient(180deg, #fffefb, #fff8ee);
}
.read .empty {
  color: var(--muted);
  padding: 64px 40px;
  font-size: 18px;
  text-align: center;
}
.read-head { padding: 22px 26px 12px; border-bottom: 1px solid var(--line); }
.read-head h2 { margin: 0 0 8px; font-size: 22px; font-weight: 750; letter-spacing: -0.02em; }
.read-meta { color: var(--muted); font-size: 13px; }
.read-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.read-body { padding: 22px 26px 48px; }
.read-body img { max-width: 100%; }
.atts a { display: inline-block; margin: 8px 8px 0 0; color: var(--sky); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(80, 45, 10, 0.28);
  display: grid;
  place-items: center;
  z-index: 20;
}
.sheet {
  width: min(720px, 94vw);
  max-height: 90vh;
  overflow: auto;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow);
}
.compose-sheet { width: min(860px, 96vw); }
.sheet header { display: flex; justify-content: space-between; align-items: center; }
.sheet hr { border: 0; border-top: 1px solid var(--line); width: 100%; }
.editor {
  min-height: 220px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  overflow: auto;
}
.compose-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.compose-bar button {
  background: #fff6e8;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 9px;
}
.grow { flex: 1; }
.row-form { display: flex; gap: 8px; }
.row-form input {
  flex: 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
}
.contact {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
@media (max-width: 980px) {
  .body-panes { flex-direction: column; }
  .splitter { display: none; }
  .folders, .list { width: auto; flex: 0 0 auto; max-width: none; max-height: 28vh; }
  .read { min-height: 40vh; }
}
