:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.05);
}

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

body {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ---------- header ---------- */
header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.brand .logo { font-size: 22px; }
#domain-badge {
  background: #eef2ff;
  color: var(--primary-dark);
  border: 1px solid #c7d2fe;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.header-actions { margin-inline-start: auto; display: flex; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: #e2e8f0; color: var(--text); }
.btn.secondary:hover { background: #cbd5e1; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f8fafc; color: var(--text); }
.btn.danger.ghost { color: var(--danger); }
.btn.danger.ghost:hover { background: #fef2f2; }

/* ---------- layout ---------- */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr 1fr;
  gap: 16px;
  padding: 16px 20px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

aside, #inbox, #reader {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 60vh;
}

/* ---------- aside ---------- */
aside { padding: 14px; overflow-y: auto; max-height: calc(100vh - 90px); position: sticky; top: 76px; }
.add-box { display: flex; flex-direction: column; gap: 8px; }
.add-box input, .add-box select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.add-box input:focus, .add-box select:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
.hint { font-size: 12px; color: var(--muted); margin: 8px 2px 12px; }

#addr-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.addr-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  width: 100%;
  text-align: start;
  background: #fff;
  font-family: inherit;
}
.addr-item:hover { border-color: #c7d2fe; background: #f8fafc; }
.addr-item.active { border-color: var(--primary); background: #eef2ff; }
.addr-main { flex: 1; min-width: 0; }
.addr-email { font-weight: 600; font-size: 14px; direction: ltr; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.addr-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.addr-count {
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 9px;
  min-width: 26px;
  text-align: center;
}
.addr-del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  padding: 4px;
  border-radius: 6px;
}
.addr-del:hover { color: var(--danger); background: #fef2f2; }

/* ---------- inbox ---------- */
#inbox { display: flex; flex-direction: column; overflow: hidden; }
#inbox-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
#inbox-head > div { flex: 1; min-width: 0; }
#inbox-title { font-size: 16px; direction: ltr; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); font-size: 12px; }

#msg-list { list-style: none; overflow-y: auto; flex: 1; }
.msg-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.msg-item:hover { background: #f8fafc; }
.msg-item.unread { background: #eef2ff; border-inline-start: 3px solid var(--primary); }
.msg-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
  flex-shrink: 0;
}
.msg-main { flex: 1; min-width: 0; }
.msg-from { font-size: 14px; font-weight: 600; direction: ltr; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-subj { font-size: 13px; color: var(--text); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-time { font-size: 12px; color: var(--muted); direction: ltr; flex-shrink: 0; }
.empty-list { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- reader ---------- */
#reader { display: flex; flex-direction: column; overflow: hidden; }
#reader-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
#reader-head #btn-back { margin-inline-end: auto; }
#reader-meta { padding: 16px 18px 10px; border-bottom: 1px solid var(--border); }
#reader-meta h2 { font-size: 18px; margin-bottom: 8px; }
.meta-line { font-size: 13px; color: var(--muted); direction: ltr; text-align: left; margin: 2px 0; }
.meta-line b { color: var(--text); }
#reader-attachments { padding: 10px 18px; display: flex; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.att-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f1f5f9; border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; font-size: 13px;
  color: var(--text); text-decoration: none;
}
.att-chip:hover { background: #e2e8f0; }
#reader-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
#reader-body .text-body { white-space: pre-wrap; font-size: 14px; line-height: 1.7; direction: ltr; text-align: left; }
#reader-body iframe {
  width: 100%; border: none; border-radius: 8px;
  background: #fff; min-height: 55vh;
}

/* ---------- placeholder / login ---------- */
.placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 40px; }
.ph-icon { font-size: 48px; }
.placeholder h2 { font-size: 18px; }
.placeholder p { color: var(--muted); font-size: 14px; }

#login-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.login-card {
  background: #fff; border-radius: 16px;
  padding: 36px 32px; width: 340px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo { font-size: 40px; text-align: center; }
.login-card h1 { font-size: 20px; text-align: center; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.login-card input { padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; }
.login-card input:focus { outline: 2px solid #c7d2fe; }
.err { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 20px;
  border-radius: 10px; font-size: 14px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
  aside { position: static; max-height: none; }
}
@media (max-width: 640px) {
  header { flex-wrap: wrap; }
  .header-actions { margin-inline-start: 0; width: 100%; }
}
