:root {
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1a2028;
  --border: #262d36;
  --text: #e8ecf1;
  --muted: #8a93a0;
  --accent: #4f9cf9;
  --accent-2: #2f6fd0;
  --danger: #e5534b;
  --ok: #3fb950;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; margin-top: 3rem; }
.clickable { cursor: pointer; }

.error {
  color: var(--danger);
  margin: 0.75rem 0;
  font-size: 0.9rem;
}

.brand {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand span { color: var(--accent); }

button {
  background: var(--accent-2);
  border: none;
  color: #fff;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s;
}
button:hover { background: var(--accent); }
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
button.ghost:hover { color: var(--text); border-color: var(--muted); background: transparent; }

input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
}
input:focus { border-color: var(--accent); }

/* ---- login ---- */
#view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2.5rem;
  width: min(400px, 90vw);
  text-align: center;
}
.login-box .muted { margin: 0.5rem 0 1.5rem; }
#login-form { display: flex; gap: 0.5rem; }
#login-form input { flex: 1; text-align: center; letter-spacing: 0.15em; }

/* ---- app shell ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-right { display: flex; align-items: center; gap: 0.9rem; }

.ws-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--danger);
  display: inline-block;
}
.ws-dot.connected { background: var(--ok); }

main { max-width: 900px; margin: 0 auto; padding: 1.5rem; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.section-head h2 { font-size: 1.15rem; font-weight: 600; }

#create-form { display: flex; gap: 0.5rem; align-items: center; }
.addr-input {
  display: flex;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.addr-input:focus-within { border-color: var(--accent); }
.addr-input input { border: none; background: transparent; border-radius: 0; min-width: 10rem; }
.addr-domain {
  color: var(--muted);
  padding-right: 0.7rem;
  font-size: 0.95rem;
  user-select: none;
}

/* ---- dashboard grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.9rem;
}
.account-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  position: relative;
}
.account-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.account-card .addr { font-weight: 600; word-break: break-all; }
.account-card .meta { color: var(--muted); font-size: 0.83rem; margin-top: 0.45rem; }
.badge {
  position: absolute;
  top: 0.85rem; right: 0.9rem;
  background: var(--accent-2);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}

/* ---- inbox list ---- */
.email-list { display: flex; flex-direction: column; gap: 0.55rem; }
.email-row {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.email-row:hover { border-color: var(--accent); }
.email-row .sender {
  flex: 0 0 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.email-row .subject {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.email-row .date { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.email-row.unread { border-left: 3px solid var(--accent); }
.email-row.unread .sender, .email-row.unread .subject { color: var(--text); font-weight: 600; }

/* ---- reader ---- */
.email-head { margin-bottom: 1rem; }
.email-head h2 { margin-bottom: 0.3rem; word-break: break-word; }
#email-frame {
  width: 100%;
  height: calc(100vh - 260px);
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

/* ---- toast ---- */
.toast {
  position: fixed;
  bottom: 1.4rem;
  right: 1.4rem;
  background: var(--panel-2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.75rem 1.1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  z-index: 50;
}

@media (max-width: 640px) {
  .email-row .sender { flex-basis: 110px; }
  #create-form { width: 100%; }
  .addr-input { flex: 1; }
  .addr-input input { min-width: 0; width: 100%; }
}
