:root {
  --bg: #070b14;
  --bg-2: #0c1424;
  --panel: rgba(12, 18, 32, 0.82);
  --panel-solid: #101a2c;
  --line: rgba(120, 180, 255, 0.22);
  --text: #e8f1ff;
  --muted: #8aa3c2;
  --accent: #2f9bff;
  --accent-2: #14c8c8;
  --danger: #ff5d6c;
  --ok: #3dd68c;
  --radius: 18px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --font: "IBM Plex Sans Arabic", "Sora", system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}
body { min-height: 100dvh; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

#hex-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

#app { position: relative; z-index: 1; min-height: 100dvh; }

.view { min-height: 100dvh; }
.login-view {
  display: grid;
  place-items: center;
  padding: 24px 16px calc(24px + var(--safe-bottom));
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px 24px 22px;
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}

.brand { text-align: center; margin-bottom: 6px; }
.brand h1 {
  margin: 10px 0 4px;
  font-family: Sora, var(--font);
  font-size: 1.55rem;
  letter-spacing: 0.02em;
}
.brand p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.brand-mark {
  width: 54px;
  height: 54px;
  margin: 0 auto;
  background:
    linear-gradient(135deg, rgba(47,155,255,.35), rgba(20,200,200,.25)),
    var(--bg-2);
  clip-path: polygon(25% 6%, 75% 6%, 100% 50%, 75% 94%, 25% 94%, 0 50%);
  border: 1px solid rgba(120,180,255,.35);
  box-shadow: 0 0 0 6px rgba(47,155,255,.08);
}
.brand-mark.sm { width: 36px; height: 36px; margin: 0; }

label { display: grid; gap: 6px; }
label span { color: var(--muted); font-size: 0.85rem; }
input, textarea {
  width: 100%;
  background: rgba(6, 10, 20, 0.9);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47,155,255,.18);
}
textarea { resize: vertical; min-height: 160px; }

.btn, #login-btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 650;
  box-shadow: 0 12px 28px rgba(40,140,255,.28);
}
.btn.block, #login-btn { width: 100%; }
.btn.ghost, .btn.danger.ghost {
  background: transparent;
  box-shadow: none;
  border: 1px solid var(--line);
  color: var(--text);
}
.btn.danger { color: #ffd0d5; border-color: rgba(255,93,108,.4); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #fff; }

.error { color: #ff9eaa; margin: 0; font-size: 0.9rem; }
.hint { margin: 0; text-align: center; color: var(--muted); font-size: 0.78rem; }

.app-view {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100dvh;
}

.sidebar {
  background: rgba(8, 12, 22, 0.88);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  backdrop-filter: blur(14px);
}
.sidebar-top { display: grid; gap: 14px; }
.brand-mini { display: flex; gap: 10px; align-items: center; }
.brand-mini strong { display: block; }
.brand-mini small { color: var(--muted); word-break: break-all; }

.folder-list {
  margin-top: 18px;
  display: grid;
  gap: 6px;
  overflow: auto;
  flex: 1;
}
.folder-item {
  text-align: right;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 12px;
  padding: 10px 12px;
}
.folder-item.active, .folder-item:hover {
  color: var(--text);
  background: rgba(47,155,255,.12);
  border-color: rgba(47,155,255,.2);
}
.sidebar-bottom { margin-top: auto; padding-top: 12px; }

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: rgba(7, 11, 20, 0.55);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.topbar h2 { margin: 0; flex: 1; font-size: 1.05rem; font-weight: 650; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(10,16,28,.7);
  color: var(--text);
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  min-height: 0;
}
.list-pane, .read-pane {
  min-height: 0;
  overflow: auto;
}
.list-pane { border-left: 1px solid var(--line); }
.message-list { display: grid; }
.msg-item {
  display: grid;
  gap: 4px;
  text-align: right;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid rgba(120,180,255,.1);
  background: transparent;
  color: inherit;
}
.msg-item:hover { background: rgba(47,155,255,.08); }
.msg-item.active { background: rgba(47,155,255,.14); }
.msg-item.unread .msg-subject { font-weight: 700; color: #fff; }
.msg-subject { font-size: 0.95rem; }
.msg-from { color: var(--muted); font-size: 0.82rem; }
.msg-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.75rem;
}
.empty, .loading {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.read-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.read-body { padding: 18px 18px 40px; }
.read-body h3 { margin: 0 0 8px; font-size: 1.25rem; }
.read-meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 18px; line-height: 1.7; }
.read-content {
  background: rgba(10,16,28,.65);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  line-height: 1.8;
  overflow-wrap: anywhere;
}
.read-content iframe {
  width: 100%;
  min-height: 320px;
  border: 0;
  background: #fff;
  border-radius: 10px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(3, 6, 12, 0.66);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-card {
  width: min(640px, 100%);
  max-height: min(90dvh, 820px);
  overflow: auto;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.compose-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.compose-card h3 { margin: 0; }
.compose-card form {
  display: grid;
  gap: 12px;
  padding: 16px;
}
.compose-actions {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
}
.grow { align-content: start; }

.mobile-nav { display: none; }
.mobile-only { display: none; }

@media (max-width: 920px) {
  .app-view { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    transform: translateX(110%);
    transition: transform .22s ease;
    z-index: 15;
  }
  .sidebar.open { transform: translateX(0); }
  .workspace { grid-template-columns: 1fr; }
  .read-pane { display: none; }
  .read-pane.show {
    display: block;
    position: absolute;
    inset: 57px 0 64px 0;
    background: var(--bg);
    z-index: 5;
  }
  .list-pane.hide { display: none; }
  .mobile-only { display: inline-flex; align-items: center; justify-content: center; }
  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    padding: 8px 10px calc(8px + var(--safe-bottom));
    background: rgba(8,12,22,.94);
    border-top: 1px solid var(--line);
    z-index: 12;
  }
  .mobile-nav button {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 10px 6px;
    border-radius: 12px;
  }
  .mobile-nav button.active {
    color: var(--text);
    background: rgba(47,155,255,.14);
  }
  .main { padding-bottom: 70px; }
}
