:root {
  --bg: #0b1020;
  --bg2: #121a2f;
  --panel: #151f38;
  --panel2: #1b2744;
  --line: #2a395f;
  --text: #e8eefc;
  --muted: #93a0c2;
  --accent: #4f8cff;
  --accent2: #6ee7b7;
  --danger: #ff6b7a;
  --warn: #fbbf24;
  --ok: #34d399;
  --shadow: 0 12px 40px rgba(0,0,0,.35);
  --radius: 16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(79,140,255,.18), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(110,231,183,.10), transparent 45%),
    var(--bg);
}

.app {
  height: 100%;
  min-height: 100%;
  padding: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; margin-bottom: 16px; flex-shrink: 0;
}
.brand { display: flex; gap: 14px; align-items: center; }
.logo {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center; font-size: 24px;
  background: linear-gradient(145deg, #243358, #17233f);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-size: 1.25rem; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  flex: 1;
  min-height: 0;
  height: calc(100vh - 110px);
  max-height: calc(100vh - 110px);
  overflow: hidden;
}
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.card {
  background: linear-gradient(180deg, rgba(27,39,68,.95), rgba(18,26,47,.95));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.card h2 { margin: 0; font-size: 1rem; }
.import-card { flex: 0 0 auto; }
.import-card textarea {
  width: 100%;
  resize: vertical;
  min-height: 90px;
  max-height: 180px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0d1427;
  color: var(--text);
  padding: 12px;
  font-family: var(--mono);
  font-size: .8rem;
  line-height: 1.45;
}
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.check { color: var(--muted); font-size: .85rem; display: flex; gap: 8px; align-items: center; }
.status { margin-top: 10px; color: var(--muted); font-size: .85rem; min-height: 1.2em; }

.list-card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.account-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 6px;
  scrollbar-gutter: stable;
}
.account-list::-webkit-scrollbar { width: 10px; }
.account-list::-webkit-scrollbar-track {
  background: rgba(13, 20, 39, 0.8);
  border-radius: 999px;
}
.account-list::-webkit-scrollbar-thumb {
  background: #3d5288;
  border-radius: 999px;
  border: 2px solid rgba(13, 20, 39, 0.8);
}
.account-list::-webkit-scrollbar-thumb:hover { background: #4f8cff; }
.account-item {
  text-align: left; width: 100%;
  border: 1px solid var(--line);
  background: rgba(13,20,39,.75);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: .15s ease;
}
.account-item:hover { border-color: #3d5288; background: #17233f; }
.account-item.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(79,140,255,.35); }
.account-item .email { font-weight: 600; font-size: .92rem; word-break: break-all; }
.account-item .sub { margin-top: 4px; color: var(--muted); font-size: .78rem; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.viewer {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.viewer-inner { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.viewer-head {
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap;
}
.viewer-head h2 { margin: 0; font-size: 1.05rem; word-break: break-all; }
.meta-line { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.viewer-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mail-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 12px;
  min-height: 0;
  flex: 1;
}
.msg-list, .msg-read {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8,13,26,.55);
  min-height: 420px;
  overflow: auto;
}
.msg-item {
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid rgba(42,57,95,.7);
  background: transparent; color: var(--text); padding: 12px; cursor: pointer;
}
.msg-item:hover { background: rgba(79,140,255,.08); }
.msg-item.active { background: rgba(79,140,255,.14); }
.msg-item.unread .subject { font-weight: 700; }
.msg-item .subject { font-size: .92rem; margin-bottom: 4px; }
.msg-item .from { color: var(--muted); font-size: .8rem; }
.msg-item .preview { color: #a9b6d8; font-size: .78rem; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.msg-item .when { color: var(--muted); font-size: .72rem; margin-top: 6px; }

.msg-read { padding: 0; }
.read-empty, .empty {
  height: 100%; min-height: 320px; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px;
}
.empty-icon { font-size: 42px; margin-bottom: 8px; }
.read-head { padding: 18px 18px 12px; border-bottom: 1px solid var(--line); }
.read-head h3 { margin: 0 0 8px; font-size: 1.15rem; line-height: 1.35; }
.read-meta { color: var(--muted); font-size: .86rem; display: grid; gap: 4px; }
.read-body {
  padding: 0;
  background: #fff;
  color: #111;
  min-height: 280px;
}
.read-body iframe {
  width: 100%;
  min-height: 420px;
  border: 0;
  background: #fff;
}
.read-body pre {
  margin: 0; padding: 18px; white-space: pre-wrap; word-break: break-word;
  font-family: var(--sans); color: #111; background: #fff;
}

.btn, .file-btn, select, .search {
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #121a2f;
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
}
.btn, .file-btn { cursor: pointer; }
.btn:hover, .file-btn:hover { border-color: #4a629c; }
.btn.primary { background: linear-gradient(180deg, #4f8cff, #3a6fd6); border-color: #6aa0ff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: #ffd0d5; border-color: rgba(255,107,122,.45); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.file-btn { display: inline-flex; align-items: center; font-size: .85rem; }
.search { min-width: 160px; }
select { min-width: 130px; }

.pill, .badge {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 4px 10px; font-size: .78rem;
  border: 1px solid var(--line); background: rgba(13,20,39,.8); color: var(--muted);
}
.badge.ok { color: #b7ffe3; border-color: rgba(52,211,153,.4); background: rgba(16,80,55,.35); }
.badge.error { color: #ffd0d5; border-color: rgba(255,107,122,.4); background: rgba(90,24,34,.35); }
.badge.imported, .badge.unknown { color: #ffe7a8; border-color: rgba(251,191,36,.35); background: rgba(90,64,12,.28); }
.muted { color: var(--muted); font-size: .82rem; }
.hidden { display: none !important; }

.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  background: #17233f; border: 1px solid var(--line); color: var(--text);
  padding: 12px 14px; border-radius: 12px; box-shadow: var(--shadow); max-width: 360px;
}
.toast.error { border-color: rgba(255,107,122,.5); }
.toast.ok { border-color: rgba(52,211,153,.45); }

@media (max-width: 1100px) {
  .app { height: auto; min-height: 100%; overflow: auto; }
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .sidebar { height: auto; overflow: visible; }
  .list-card { min-height: 360px; max-height: 55vh; }
  .account-list { max-height: calc(55vh - 70px); }
  .mail-grid { grid-template-columns: 1fr; }
  .msg-list { max-height: 320px; }
}
