:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel2: #f3f4f6;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #D52B1E;
  --accent-soft: #fef2f2;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --font: 'DM Sans', system-ui, sans-serif;
  --sidebar: 240px;
}
* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.app {
  display: grid;
  grid-template-columns: var(--sidebar) 340px 1fr;
  height: 100%;
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .col-nav, .col-list { display: none; }
  .app.show-nav .col-nav,
  .app.show-list .col-list,
  .app.show-detail .col-detail { display: flex; }
}
.col-nav, .col-list, .col-detail {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.col-detail { border-right: 0; background: var(--bg); }
.top {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
}
.brand { font-weight: 700; letter-spacing: -0.02em; font-size: 15px; }
.brand span { color: var(--accent); }
.mailbox-card {
  margin: 0 10px 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(160deg, #fff 0%, #f8fafc 100%);
  display: flex; align-items: flex-start; gap: 10px;
}
.mailbox-card .avatar {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
  border: 1px solid #fecaca;
}
.mailbox-card .meta { min-width: 0; flex: 1; }
.mailbox-card .label {
  font-size: 11px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px;
}
.mailbox-card .address {
  font-size: 13px; font-weight: 700; color: var(--text);
  word-break: break-all; line-height: 1.3;
}
.mailbox-card .local {
  color: var(--accent);
}
.mailbox-card .status {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 6px; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: #ecfdf5; color: #047857;
}
.mailbox-card .status.warn { background: #fff7ed; color: #c2410c; }
.mailbox-card .status.dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  padding: 0;
}
.folder {
  display: flex; align-items: center; gap: 10px;
  margin: 2px 10px; padding: 10px 12px;
  border-radius: 8px; cursor: pointer;
  color: var(--text); font-size: 14px; border: 0; background: transparent;
  width: calc(100% - 20px); text-align: left; font-family: inherit;
}
.folder:hover { background: var(--panel2); }
.folder.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.folder i { width: 18px; text-align: center; }
.folder .count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: var(--panel2); color: var(--muted);
  padding: 1px 7px; border-radius: 999px;
}
.folder.active .count { background: #fee2e2; color: var(--accent); }
.scroll { flex: 1; overflow: auto; }
.msg-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--panel);
  transition: background .12s, box-shadow .12s;
}
.msg-item:hover { box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.msg-item.active {
  background: #fff7ed;
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}
.msg-item .from { font-weight: 600; font-size: 14px; }
.msg-item .subj {
  font-size: 13px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-item .meta {
  font-size: 11px; color: var(--muted); margin-top: 4px;
  display: flex; justify-content: space-between; gap: 8px;
}
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--panel2); color: var(--muted);
  display: inline-block;
}
.badge.warn { background: #fffbeb; color: var(--warn); }
.badge.spam { background: #fee2e2; color: var(--accent); }
.empty {
  padding: 48px 20px; text-align: center; color: var(--muted); font-size: 14px;
}
.detail-wrap {
  display: flex; flex-direction: column; height: 100%; min-height: 0;
  margin: 12px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
.detail-head { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.detail-head h1 { margin: 0 0 8px; font-size: 18px; font-weight: 700; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.detail-body {
  padding: 20px; overflow: auto; flex: 1;
  font-size: 14px; line-height: 1.55;
}
.detail-body img { max-width: 100%; }
.reply {
  border-top: 1px solid var(--border); padding: 12px 16px;
  display: flex; flex-direction: column; gap: 8px; background: #fafafa;
}
.reply textarea {
  width: 100%; min-height: 100px; resize: vertical;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  padding: 10px 12px; font-family: inherit; font-size: 14px;
}
.reply textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(213, 43, 30, 0.12);
}
.btn {
  appearance: none; border: 0; border-radius: 8px;
  padding: 9px 14px; font-weight: 600; font-size: 13px;
  cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--panel2); color: var(--text); }
.btn-secondary:hover { background: #e5e7eb; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(ellipse at top, #e8eef6, var(--bg));
}
.login-card {
  width: min(420px, 100%); background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 28px;
  box-shadow: 0 8px 28px rgba(26, 35, 48, 0.06);
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.login-card p { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel2);
  color: var(--text); margin-bottom: 12px; font-family: inherit;
}
.err { color: #dc2626; font-size: 13px; margin-bottom: 10px; }
.sig-panel { padding: 12px; border-top: 1px solid var(--border); }
.sig-panel textarea {
  width: 100%; min-height: 80px; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-family: inherit; font-size: 13px;
  margin: 8px 0;
}
.sig-item {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; margin-bottom: 8px; font-size: 12px;
}
.sig-item.default { border-color: #fecaca; background: var(--accent-soft); }
.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: #111827; color: white; padding: 10px 14px;
  border-radius: 8px; font-size: 13px; z-index: 50;
}
.compose-btn {
  margin: 8px 10px 4px;
  width: calc(100% - 20px);
  justify-content: center;
}
.att-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.att-chip {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 12px;
  cursor: pointer; max-width: 100%;
}
.att-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.att-chip .ico {
  width: 36px; height: 36px; border-radius: 8px;
  display: grid; place-items: center; background: #f3f4f6; color: #6b7280;
  flex-shrink: 0;
}
.att-chip .ico.pdf { background: #fee2e2; color: #b91c1c; }
.att-chip .ico.img { background: #dbeafe; color: #1d4ed8; }
.att-chip .meta { min-width: 0; }
.att-chip .name {
  font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px;
}
.att-chip .size { color: var(--muted); font-size: 11px; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(17,24,39,.45);
  display: grid; place-items: center; z-index: 60; padding: 16px;
}
.modal {
  width: min(720px, 100%); max-height: min(90vh, 900px);
  background: #fff; border-radius: 14px; border: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,.18);
}
.modal-head {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.modal-body { padding: 14px 16px; overflow: auto; flex: 1; }
.modal-foot {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: #fafafa;
}
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px;
}
.field-head label { margin: 0; }
.field-toggle {
  border: 0; background: transparent; color: var(--accent);
  font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; padding: 0;
}
.field input, .field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-family: inherit; font-size: 14px;
}
.field textarea { min-height: 160px; resize: vertical; }
.rcpt-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-height: 42px; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 8px; background: #fff; transition: border-color .12s, background .12s;
}
.rcpt-row.drag-over {
  border-color: var(--accent); background: var(--accent-soft);
}
.rcpt-row input {
  flex: 1; min-width: 140px; border: 0 !important; padding: 6px 4px !important;
  outline: none; background: transparent; font-size: 13px;
}
.rcpt-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f3f4f6; border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 8px 3px 3px;
  font-size: 12px; cursor: grab; user-select: none; max-width: 100%;
}
.rcpt-chip:active { cursor: grabbing; }
.rcpt-chip.dragging { opacity: .45; }
.rcpt-chip .av {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.rcpt-chip .em {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px;
}
.rcpt-chip .x {
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; padding: 0 2px; font-size: 11px; line-height: 1;
}
.rcpt-chip .x:hover { color: var(--accent); }
.draft-hint { font-size: 12px; color: var(--muted); margin-left: auto; }
.preview-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.75);
  z-index: 70; display: grid; place-items: center; padding: 16px;
}
.preview-box {
  background: #fff; border-radius: 12px; width: min(960px, 100%);
  max-height: 90vh; overflow: hidden; display: flex; flex-direction: column;
}
.preview-box header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--border); gap: 8px;
}
.preview-box .body { overflow: auto; flex: 1; background: #111; }
.preview-box img { max-width: 100%; display: block; margin: 0 auto; }
.preview-box iframe { width: 100%; height: 70vh; border: 0; background: #fff; }
.clip { color: var(--muted); font-size: 11px; margin-left: 4px; }
