:root {
  --bg: #0d0e13;
  --panel: #14161d;
  --panel-2: #1a1d26;
  --hover: #20232e;
  --line: #262a37;
  --text: #e9eaf0;
  --muted: #8a8fa3;
  --faint: #5d6274;
  --accent: #8b6bff;
  --accent-2: #ff4fa3;
  --grad: linear-gradient(135deg, #7c5cff 0%, #ff4fa3 100%);
  --ok: #3ddc97;
  --warn: #ffb547;
  --bad: #ff5c7a;
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: #a995ff; }
button { cursor: pointer; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(600px 400px at 20% 10%, rgba(124, 92, 255, .18), transparent 60%),
    radial-gradient(600px 400px at 85% 90%, rgba(255, 79, 163, .14), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.login-card h1 { margin: 18px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--accent); }
.input-suffix { display: flex; align-items: stretch; }
.input-suffix .input { border-radius: 10px 0 0 10px; border-right: 0; }
.input-suffix em {
  font-style: normal;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--hover);
  border: 1px solid var(--line);
  border-radius: 0 10px 10px 0;
  color: var(--muted);
  white-space: nowrap;
}
.error { color: var(--bad); min-height: 20px; margin: 4px 0 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px 14px;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary {
  background: var(--grad);
  border: 0;
  color: #fff;
  font-weight: 600;
  padding: 10px 16px;
}
.btn-primary:hover { background: var(--grad); filter: brightness(1.08); }
.btn-wide { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--hover); }
.btn-danger:hover { color: var(--bad); }

/* ---------- logo ---------- */
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--grad);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 6px 18px rgba(124, 92, 255, .35);
}
.logo small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }

/* ---------- layout ---------- */
.shell {
  height: 100%;
  display: grid;
  grid-template-columns: 232px minmax(300px, 400px) 1fr;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 18px;
  min-height: 0;
}
.folders { display: flex; flex-direction: column; gap: 2px; }
.folder {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
}
.folder:hover { background: var(--hover); color: var(--text); }
.folder.active { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.folder .ico { width: 18px; text-align: center; }
.folder .count { margin-left: auto; font-size: 12px; color: var(--text); background: rgba(139, 107, 255, .22); padding: 1px 8px; border-radius: 99px; }
.side-bottom { margin-top: auto; border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.me { font-size: 12px; color: var(--muted); padding: 0 4px 6px; word-break: break-all; }
.me b { color: var(--text); display: block; font-size: 13px; }

.list-pane {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.list-head { padding: 14px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.list-head h2 { margin: 0; font-size: 17px; flex: 1; }
.search { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.list { overflow-y: auto; flex: 1; }
.item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 12px 14px 12px 22px;
  position: relative;
}
.item:hover { background: var(--panel); }
.item.active { background: var(--panel-2); }
.item.unread::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 18px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--grad);
}
.item .row1 { display: flex; gap: 8px; align-items: baseline; }
.item .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.item.unread .who, .item.unread .subj { color: var(--text); font-weight: 600; }
.item .when { font-size: 12px; color: var(--faint); white-space: nowrap; }
.item .subj { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .snip { margin-top: 2px; font-size: 12.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--hover); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); background: rgba(61, 220, 151, .12); }
.badge.warn { color: var(--warn); background: rgba(255, 181, 71, .12); }
.badge.bad { color: var(--bad); background: rgba(255, 92, 122, .12); }
.empty { padding: 48px 20px; text-align: center; color: var(--faint); }
.more { margin: 12px auto; display: block; }

.reader { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.reader-empty { margin: auto; text-align: center; color: var(--faint); }
.reader-empty .logo-mark { width: 64px; height: 64px; font-size: 26px; border-radius: 18px; margin: 0 auto 14px; opacity: .85; }
.toolbar { display: flex; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.toolbar .spacer { flex: 1; }
.msg { overflow-y: auto; padding: 22px 26px 40px; flex: 1; }
.msg h1 { font-size: 21px; margin: 0 0 16px; line-height: 1.3; word-break: break-word; }
.meta { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 18px; }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  flex: none;
}
.meta .lines { flex: 1; min-width: 0; }
.meta .from b { margin-right: 6px; }
.meta .from span, .meta .to { color: var(--muted); font-size: 13px; word-break: break-all; }
.meta .date { color: var(--faint); font-size: 12.5px; white-space: nowrap; }
.auth { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.body-text { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; line-height: 1.6; }
.body-frame { width: 100%; border: 0; border-radius: 12px; background: #fff; min-height: 200px; }
.img-note {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.att {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  max-width: 280px;
}
.att:hover { border-color: var(--accent); }
.att .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .size { color: var(--faint); font-size: 12px; }

/* ---------- compose & modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, .6);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 20;
}
.sheet {
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .55);
  overflow: hidden;
}
.sheet.small { max-width: 420px; }
.sheet-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { margin: 0; flex: 1; font-size: 16px; }
.sheet-body { padding: 14px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.line-field { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.line-field label { width: 56px; color: var(--muted); font-size: 13px; flex: none; }
.line-field input { flex: 1; background: transparent; border: 0; outline: none; padding: 6px 0; min-width: 0; }
.compose-text {
  min-height: 260px;
  resize: vertical;
  background: transparent;
  border: 0;
  outline: none;
  line-height: 1.55;
  padding: 6px 0;
}
.sheet-foot { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.sheet-foot .spacer { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--hover); border-radius: 99px; padding: 3px 6px 3px 10px; font-size: 12.5px; }
.chip button { border: 0; background: transparent; color: var(--muted); padding: 0 4px; }
.hidden-file { display: none; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.only-mobile { display: none; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform .2s;
  }
  .shell.drawer .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5); }
  .shell.reading .list-pane { display: none; }
  .shell:not(.reading) .reader { display: none; }
  .only-mobile { display: inline-flex; }
  .msg { padding: 18px 16px 40px; }
  .overlay { padding: 0; }
  .sheet { max-height: 100vh; height: 100%; border-radius: 0; max-width: none; }
  .sheet.small { height: auto; border-radius: 18px; margin: 16px; }
}
