:root {
  --navy: #00225f;
  --navy-deep: #031a4a;
  --blue: #1f5fbf;
  --ink: #0b1f4f;
  --text: #33405e;
  --muted: #5b6784;
  --line: #e3e8f2;
  --panel: #f4f7fb;
  --white: #fff;
  --danger: #9d2433;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "DM Sans", "Cairo", system-ui, sans-serif;
  color: var(--text);
  background: var(--panel);
}

button, input, textarea { font: inherit; }

button { cursor: pointer; }

.btn, .text-btn, .icon-btn {
  border: 0;
  background: var(--blue);
  color: var(--white);
}

.btn, .text-btn, .icon-btn, .older, .folders button, .toolbar button, .sig-list button {
  font-weight: 700;
}

.btn, .text-btn, .icon-btn, .older, .folders button, .toolbar button, .sig-list button, .attachments a {
  background: var(--blue);
  color: var(--white);
}

.btn:hover, .text-btn:hover, .icon-btn:hover, .older:hover, .folders button:hover, .toolbar button:hover, .sig-list button:hover, .attachments a:hover {
  background: var(--navy);
  color: var(--white);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 8px;
}

.btn:disabled, .text-btn:disabled { opacity: 0.6; cursor: wait; }

.text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 22px;
}

.form-error {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.mail-legal {
  position: fixed;
  z-index: 4;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  margin: 0;
  padding: 2px 20px 14px;
  text-align: left;
  font-size: 10px;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.42);
}

.mail-legal a {
  color: inherit;
  font-size: 10px;
  line-height: 1.3;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.mail-legal a:hover { color: rgba(255, 255, 255, 0.7); }

body:has(#app:not([hidden])) .mail-legal { color: #243056; }

body:has(#app:not([hidden])) .mail-legal a:hover { color: var(--navy); }

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px 64px;
  background:
    radial-gradient(900px 420px at 110% 120%, rgba(111, 168, 255, 0.35), transparent 60%),
    var(--navy);
}

.gate-card {
  width: min(440px, 100%);
  padding: 32px 28px;
  border-radius: 16px;
  background: var(--white);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.gate-card::before {
  content: "";
  display: block;
  height: 6px;
  margin: -32px -28px 22px;
  background: linear-gradient(90deg, var(--navy), var(--blue));
}

.gate-mark {
  display: block;
  width: 118px;
  height: auto;
}

.gate-en {
  margin: 14px 0 0;
  color: var(--navy);
  font-family: Montserrat, sans-serif;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.gate-ar {
  margin: 4px 0 0;
  color: var(--ink);
  font-family: Cairo, sans-serif;
  font-size: 18px;
  font-weight: 700;
}

.gate h1 {
  margin: 22px 0 6px;
  color: var(--ink);
  font-family: Montserrat, sans-serif;
  font-size: 32px;
}

.gate-lead { margin: 0 0 18px; }

.gate label, .compose label {
  display: block;
  margin-top: 12px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.gate input, .compose input, .compose textarea {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--white);
}

.gate input:focus, .compose input:focus, .compose textarea:focus {
  outline: 3px solid rgba(31, 95, 191, 0.35);
  border-color: var(--blue);
}

.gate .btn { width: 100%; margin-top: 16px; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--white);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 68px;
  padding: 0 16px;
  border-top: 4px solid var(--navy);
  border-bottom: 1px solid var(--line);
  background: var(--white);
}

.top-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--navy);
  font-family: Montserrat, sans-serif;
  font-weight: 800;
  text-decoration: none;
}

.who {
  margin: 0 auto 0 8px;
  color: var(--muted);
  font-size: 14px;
}

#folder-toggle { display: none; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(280px, 380px) minmax(0, 1fr);
  padding-bottom: 42px;
}

.folders {
  padding: 16px 10px 48px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.folders button {
  display: flex;
  width: 100%;
  margin: 0 0 4px;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  text-align: left;
}

.folders button[aria-current="true"],
.folders button[aria-current="true"]:hover {
  background: var(--navy);
  color: var(--white);
}

.list-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
}

.list-head, .compose-head, .reader-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.list-head {
  padding: 14px 16px 8px;
}

.list-head h2, .compose h2, .reader h2 {
  margin: 0;
  color: var(--ink);
  font-family: Montserrat, sans-serif;
  font-size: 20px;
}

.list { overflow: auto; }

.message {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--white);
  text-align: left;
}

.message strong, .message em, .message small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message strong { color: var(--ink); font-weight: 500; }

.message em {
  margin-top: 2px;
  color: var(--muted);
  font-style: normal;
  font-size: 14px;
}

.message small { margin-top: 4px; color: var(--muted); }

.message.unread strong { font-weight: 800; }

.message[aria-current="true"] { background: #eaf1fb; }

.older {
  margin: 8px;
  padding: 10px;
  border: 0;
  border-radius: 8px;
}

.reader {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 22px 28px 40px;
}

.reader-empty {
  height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
}

.reader-meta {
  margin: 8px 0 0;
  color: var(--muted);
  white-space: pre-line;
}

@media (min-width: 901px) {
  .reader .back { display: none; }
}

.reader-tools {
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.attachments a {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.mail-frame {
  width: 100%;
  min-height: 240px;
  border: 0;
}

.compose {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 26, 74, 0.46);
}

.compose-card {
  width: min(960px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 18px 20px 20px;
  border-radius: 16px;
  background: var(--white);
  box-shadow: 0 18px 50px rgba(3, 26, 74, 0.25);
}

#signature-modal { z-index: 6; }

.compose-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.compose .check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-weight: 650;
}

.compose .check input { width: auto; margin: 0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 12px 0 8px;
  padding: 6px;
  border: 0;
  border-radius: 10px;
  background: var(--blue);
  color: var(--white);
}

.toolbar button,
.toolbar select {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 0 8px;
  background: var(--white);
  color: var(--blue);
}

.toolbar button:hover,
.toolbar select:hover {
  background: var(--navy);
  color: var(--white);
}

.toolbar select option {
  background: var(--white);
  color: var(--ink);
}

.toolbar button[aria-pressed="true"],
.toolbar button[aria-pressed="true"]:hover {
  background: var(--navy);
  color: var(--white);
}

.toolbar .pop button,
.toolbar .pop button:hover {
  background: var(--blue);
  color: var(--white);
}

.toolbar .pop button:hover { background: var(--navy); }

.toolbar button[data-cmd],
.toolbar button[data-img-remove] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  padding: 0;
}

.toolbar button svg,
.color-btn svg {
  display: block;
  width: 18px;
  height: 18px;
}

.toolbar .color-btn {
  background: var(--white);
  color: var(--blue);
  min-height: 32px;
  padding: 0 4px 0 6px;
  border-radius: 6px;
}

.toolbar .color-btn:hover {
  background: var(--navy);
  color: var(--white);
}

.toolbar-gap {
  width: 1px;
  height: 22px;
  margin: 0 3px;
  background: rgba(255, 255, 255, 0.45);
}

.toolbar input,
.toolbar select { width: auto; margin: 0; }

.toolbar label,
.color-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  font-size: 13px;
  color: var(--white);
}

.toolbar .pop label { color: var(--ink); }

.sig-pick { font-weight: 700; color: var(--ink); }
.sig-pick select { min-width: 140px; }

.color-btn input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
}

.img-tools,
.pop {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.img-tools { flex-basis: 100%; }

.pop {
  flex-basis: 100%;
  padding: 8px;
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
}

.pop input { width: min(280px, 100%); }

.editor {
  min-height: 260px;
  max-height: 46vh;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--white);
  line-height: 1.5;
}

.sig-editor { min-height: 160px; max-height: 280px; }

.editor:focus {
  outline: 3px solid rgba(31, 95, 191, 0.35);
  border-color: var(--blue);
}

.editor img { max-width: 100%; height: auto; }
.editor img.picked { outline: 2px solid var(--blue); }
.editor table { border-collapse: collapse; width: 100%; }
.editor td { border: 1px solid var(--line); padding: 6px 8px; min-width: 40px; }
.editor blockquote {
  margin: 12px 0;
  padding-left: 12px;
  border-left: 3px solid var(--blue);
}
.editor [data-signature] {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.attach-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.attach-note { margin: 8px 0 0; color: var(--muted); font-size: 13px; }

.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.file-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.sig-layout {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 16px;
  margin-top: 12px;
}

.sig-list { display: flex; flex-direction: column; gap: 4px; }

.sig-list button {
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  text-align: left;
}

.sig-list button[aria-current="true"],
.sig-list button[aria-current="true"]:hover {
  background: var(--navy);
  color: var(--white);
}

.compose-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 12px; }

.empty, .status-line { padding: 24px 16px; color: var(--muted); }

@media (max-width: 900px) {
  #folder-toggle { display: inline-flex; }
  .who { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .folders {
    display: none;
    position: absolute;
    z-index: 3;
    top: 68px;
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    box-shadow: 8px 0 24px rgba(3, 26, 74, 0.12);
  }
  .folders.open { display: block; }
  .list-pane.hidden, .reader.hidden { display: none; }
  .reader { padding: 16px; }
  .compose { padding: 0; align-items: stretch; }
  .compose-card { width: 100%; max-height: 100%; border-radius: 0; }
  .compose-row, .sig-layout { grid-template-columns: 1fr; }
  .editor { max-height: none; }
  .topbar { height: auto; min-height: 68px; flex-wrap: wrap; padding: 8px 12px; }
}
