:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e2330;
  --border: #2a3142;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #6ea8fe;
  --accent-2: #3d7eff;
  --danger: #ff6b7a;
  --ok: #5ddea0;
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #1a2744 0%, var(--bg) 55%);
  color: var(--text);
}

#app {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-height: 0;
  background: var(--panel);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 18px 16px 10px;
}
.brand h1 { margin: 0; font-size: 1.1rem; letter-spacing: 0.02em; }
.logo {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #9b7bff);
  font-size: 1.2rem;
}
.muted { color: var(--muted); font-size: 0.85rem; margin: 2px 0 0; }

.search-box { padding: 8px 16px 4px; }
.search-box input, #token-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  outline: none;
}
.search-box input:focus, #token-input:focus { border-color: var(--accent); }

.list-meta {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; color: var(--muted); font-size: 0.8rem;
}

.email-list {
  list-style: none; margin: 0; padding: 0 8px 16px;
  overflow: auto; flex: 1;
}
.email-list li {
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 4px;
}
.email-list li:hover { background: var(--panel-2); }
.email-list li.active {
  background: color-mix(in srgb, var(--accent) 16%, var(--panel-2));
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}
.email-list .from { font-weight: 600; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-list .subject { color: var(--text); font-size: 0.88rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-list .to-line, .email-list .date { color: var(--muted); font-size: 0.75rem; margin-top: 4px; }

.detail { min-height: 0; overflow: auto; background: color-mix(in srgb, var(--bg) 40%, var(--panel)); }
.empty { height: 100%; display: grid; place-items: center; color: var(--muted); }
.viewer { padding: 28px 32px 48px; }
.hidden { display: none !important; }

.viewer-header { display: flex; justify-content: space-between; gap: 16px; align-items: start; }
.viewer-header h2 { margin: 0; font-size: 1.45rem; line-height: 1.3; }

.meta {
  display: grid; gap: 8px; margin: 18px 0;
  padding: 14px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--border);
}
.meta > div { display: grid; grid-template-columns: 64px 1fr; gap: 8px; }
.meta dt { color: var(--muted); margin: 0; }
.meta dd { margin: 0; word-break: break-word; }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.attachments a {
  display: inline-flex; gap: 6px; align-items: center;
  padding: 8px 12px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--accent); text-decoration: none; font-size: 0.85rem;
}
.attachments a:hover { border-color: var(--accent); }

.body {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: #111;
  padding: 20px;
  min-height: 200px;
  overflow: auto;
}
.body.plain {
  background: var(--panel);
  color: var(--text);
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
}
.body iframe {
  width: 100%; min-height: 420px; border: 0; background: #fff;
}

button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
button.primary {
  background: linear-gradient(135deg, var(--accent-2), #7a5cff);
  border: none; font-weight: 600;
}
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
button.ghost { background: transparent; border: none; font-size: 1.1rem; color: var(--muted); }
button:hover { filter: brightness(1.08); }

dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  background: var(--panel);
  color: var(--text);
  width: min(420px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
dialog h2 { margin-top: 0; }
.row { margin-top: 14px; display: flex; justify-content: flex-end; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { max-height: 45vh; }
}
