*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; }
:root {
  --amg-primary: #c99664;
  --amg-primary-hover: #a87443;
  --amg-primary-deep: #7b4b24;
  --amg-primary-light: #f5dfc6;
  --amg-primary-soft: rgba(201, 150, 100, .16);
}
body {
  margin: 0;
  font-family: "Manrope", "IBM Plex Sans Arabic", sans-serif;
  background: #f6f7fb;
  color: #111827;
}
body.webmail-auth { overflow: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.mail-app {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  background: #f6f7fb;
}

.mail-state-login {
  grid-template-columns: 1fr;
}
.mail-state-login .mail-sidebar { display: none; }

.mail-sidebar {
  height: 100dvh;
  overflow: auto;
  border-right: 1px solid #e6e8ee;
  background: #ffffff;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-row img { width: 42px; height: 42px; object-fit: contain; }
.brand-row strong {
  display: block;
  color: #c99664;
  font-size: 0.92rem;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.brand-row span {
  color: #667085;
  font-size: .78rem;
}

.compose-btn,
.primary-btn,
.smart-install,
.send-btn {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--amg-primary);
  color: #111827;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 16px;
  font-size: .88rem;
  font-weight: 800;
  transition: .16s ease;
}
.compose-btn:hover,
.primary-btn:hover,
.smart-install:hover,
.send-btn:hover { background: var(--amg-primary-hover); }
.compose-btn {
  width: 100%;
  margin-top: 8px;
}

.mail-folders {
  display: grid;
  gap: 4px;
  margin-top: 10px;
}
.mail-folders button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #1f2937;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  text-align: left;
}
.mail-folders button:hover { background: #f3f4f6; }
.mail-folders button.active {
  background: #efeff2;
  color: #111827;
  font-weight: 800;
}
.mail-folders b {
  min-width: 22px;
  border-radius: 999px;
  background: #667085;
  color: #fff;
  padding: 1px 6px;
  font-size: .72rem;
  text-align: center;
}
.mail-folders b:empty { display: none; }
.folder-add {
  min-height: 38px;
  border: 1px dashed #cfd6e4;
  border-radius: 8px;
  background: #ffffff;
  color: #586174;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
}
.folder-add:hover { border-color: var(--amg-primary); color: var(--amg-primary-hover); }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.icon-tool,
.topbar-actions button,
.message-actions button,
.select-all,
.reader-tool,
.compose-window-btn,
.tool-btn {
  min-height: 36px;
  border: 1px solid #d7deea;
  border-radius: 8px;
  background: #ffffff;
  color: #344054;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  font-size: .82rem;
  font-weight: 800;
}
.icon-tool:hover,
.topbar-actions button:hover,
.message-actions button:hover,
.select-all:hover,
.reader-tool:hover,
.compose-window-btn:hover,
.tool-btn:hover {
  border-color: var(--amg-primary);
  color: var(--amg-primary-hover);
}

.mail-main {
  min-width: 0;
  min-height: 100dvh;
}

.login-panel {
  min-height: 100dvh;
  padding: clamp(24px, 5vw, 72px);
  background:
    radial-gradient(circle at 18% 18%, rgba(201, 150, 100, .16), transparent 28%),
    linear-gradient(120deg, #ffffff 0%, #ffffff 56%, #fff7ef 82%, #f7eadc 100%),
    #ffffff;
}
.login-grid {
  width: min(100%, 1080px);
  min-height: calc(100dvh - clamp(48px, 10vw, 144px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  align-items: center;
  gap: clamp(36px, 7vw, 120px);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 38px;
}
.login-brand img { width: 44px; height: 44px; object-fit: contain; }
.login-brand strong {
  font-size: 1.15rem;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.login-card h1 {
  margin: 0 0 22px;
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1.15;
}
.login-card p {
  color: #475467;
  line-height: 1.65;
}
.mail-form {
  margin-top: 22px;
  display: grid;
  gap: 12px;
}
label {
  color: #111827;
  font-size: .82rem;
  font-weight: 800;
}
input,
textarea,
.compose-editor {
  width: 100%;
  border: 1px solid #d7deea;
  border-radius: 8px;
  background: #ffffff;
  color: #111827;
  padding: 12px 14px;
  outline: none;
}
input:focus,
textarea:focus,
.compose-editor:focus {
  border-color: var(--amg-primary);
  box-shadow: 0 0 0 3px var(--amg-primary-soft);
}
.password-field {
  position: relative;
}
.password-field input { padding-right: 46px; }
.password-field button {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: #667085;
}
.form-message,
#compose-message {
  min-height: 20px;
  color: #9a6535;
  font-size: .84rem;
}

.login-promo h2 {
  max-width: 620px;
  margin: 0;
  font-size: clamp(2.25rem, 5.2vw, 4.2rem);
  line-height: 1.08;
  letter-spacing: 0;
}
.login-promo h2 span {
  background: linear-gradient(90deg, #111827 0%, #111827 44%, var(--amg-primary-deep) 66%, var(--amg-primary) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.eyebrow {
  margin: 0 0 12px;
  color: var(--amg-primary-hover);
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .07em;
}
.login-promo > p {
  max-width: 560px;
  color: #344054;
  line-height: 1.7;
}
.feature-list {
  display: grid;
  gap: 16px;
  margin: 26px 0;
  padding: 0;
  list-style: none;
}
.feature-list li {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #111827;
  font-weight: 600;
}
.feature-list i { color: var(--amg-primary-hover); }
.smart-install {
  margin-top: 8px;
  min-width: 220px;
  background: linear-gradient(135deg, var(--amg-primary-light), var(--amg-primary) 54%, var(--amg-primary-hover));
  color: #111827;
  box-shadow: 0 14px 30px rgba(201, 150, 100, .28);
}
.smart-install:hover {
  background: linear-gradient(135deg, #f8e7d3, var(--amg-primary) 48%, var(--amg-primary-deep));
  color: #111827;
}
.install-help {
  display: block;
  margin-top: 10px;
  color: #667085;
}
body.app-installed .smart-install,
body.app-installed .install-help { display: none; }

.mail-workspace {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.mail-topbar {
  min-height: 64px;
  border-bottom: 1px solid #e6e8ee;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
}
.search-box {
  width: min(100%, 430px);
  min-height: 42px;
  border: 1px solid #d7deea;
  border-radius: 8px;
  background: #ffffff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  color: #667085;
}
.search-box input {
  border: 0;
  box-shadow: none;
  padding: 0;
  min-height: auto;
}
.topbar-actions {
  display: flex;
  gap: 8px;
}

.mail-list-view {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: #ffffff;
}
.folder-head {
  min-height: 96px;
  border-bottom: 1px solid #e6e8ee;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 24px 16px;
}
.folder-head h2 {
  margin: 0;
  font-size: 1.5rem;
}
.folder-head p {
  margin: 4px 0 0;
  color: #667085;
  font-size: .88rem;
}
.toolbar-hint {
  color: #475467;
  font-size: .86rem;
  font-weight: 800;
}
.message-actions {
  border-bottom: 1px solid #e6e8ee;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
}
.message-actions button,
.select-all {
  min-height: 34px;
  padding: 0 10px;
  font-size: .78rem;
}
.select-all input {
  width: auto;
  padding: 0;
  box-shadow: none;
}

.message-list {
  min-height: 0;
  overflow: auto;
  background: #ffffff;
}
.message-row {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-bottom: 1px solid #edf0f5;
  background: #ffffff;
  color: #111827;
  display: grid;
  grid-template-columns: 34px 28px minmax(120px, 220px) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  text-align: left;
}
.message-row:hover,
.message-row.active,
.message-row.selected { background: #f6f7fb; }
.message-row.unread { font-weight: 800; }
.message-check {
  width: 18px;
  height: 18px;
  padding: 0;
}
.star-icon { color: #98a2b3; }
.row-sender,
.row-subject,
.row-date {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sender { color: #344054; }
.row-subject { color: #111827; }
.row-date {
  color: #667085;
  font-size: .78rem;
}
.message-open {
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
  min-width: 0;
}

.message-reader {
  height: 100%;
  overflow: auto;
  background: #ffffff;
  padding: 24px;
}
.mail-workspace.reading .mail-list-view { display: none; }
.mail-workspace.reading .message-reader { display: block !important; }
.reader-actions-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}
.reader-header {
  border: 1px solid #e0e4ec;
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 18px;
}
.reader-subject {
  margin: 0 0 18px;
  font-size: clamp(1.6rem, 4vw, 2.5rem);
  line-height: 1.15;
}
.reader-meta {
  padding: 20px;
  display: grid;
  gap: 10px;
  color: #344054;
}
.reader-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}
.reader-body {
  border-top: 1px solid #e0e4ec;
  padding: 24px 20px;
  color: #1f2937;
  line-height: 1.75;
  white-space: pre-wrap;
}
.reader-footer-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  border-top: 1px solid #e6e8ee;
  background: rgba(255,255,255,.96);
  padding: 12px 0;
}
.empty-reader {
  min-height: 50vh;
  display: grid;
  place-items: center;
  align-content: center;
  color: #667085;
  text-align: center;
}
.empty-reader i {
  font-size: 2rem;
  color: var(--amg-primary-hover);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .42);
  z-index: 40;
}
.compose-card {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(620px, calc(100vw - 48px));
  height: min(78dvh, 680px);
  border: 1px solid #d7deea;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(15,23,42,.22);
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto auto;
  overflow: hidden;
}
.compose-header {
  min-height: 42px;
  background: #f8fafc;
  border-bottom: 1px solid #edf0f5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
}
.compose-header strong { font-size: .92rem; }
.compose-window-btn {
  width: 30px;
  min-height: 30px;
  border: 0;
  background: transparent;
  padding: 0;
}
.compose-line {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #edf0f5;
  padding: 0 16px;
  color: #667085;
}
.compose-line strong {
  color: #344054;
  font-size: .88rem;
}
.compose-card input {
  border: 0;
  border-bottom: 1px solid #edf0f5;
  border-radius: 0;
  box-shadow: none;
}
.compose-editor {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  min-height: 220px;
  overflow: auto;
  line-height: 1.7;
}
.compose-editor:empty::before {
  content: attr(data-placeholder);
  color: #98a2b3;
}
.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 14px 10px;
}
.attachment-chip {
  border: 1px solid #d7deea;
  border-radius: 999px;
  background: #f8fafc;
  color: #344054;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: .78rem;
}
.compose-toolbar {
  min-height: 54px;
  border-top: 1px solid #edf0f5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
}
.send-btn {
  min-height: 36px;
  padding: 0 18px;
}
.tool-btn {
  width: 34px;
  min-height: 34px;
  padding: 0;
}
.toolbar-select {
  width: 54px;
  height: 34px;
  border: 1px solid #d7deea;
  border-radius: 8px;
  background: #ffffff;
  color: #344054;
  padding: 0 6px;
  font-weight: 800;
}
.attach-btn input { display: none; }

.pwa-toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: min(92vw, 460px);
  border: 1px solid #d7deea;
  border-radius: 10px;
  background: #111827;
  color: #ffffff;
  padding: 12px 16px;
  font-weight: 800;
  box-shadow: 0 18px 45px rgba(0,0,0,.22);
  z-index: 60;
}

html[dir="rtl"] body { text-align: right; }
html[dir="rtl"] .mail-app { direction: rtl; }
html[dir="rtl"] .mail-state-login { grid-template-columns: 1fr; }
html[dir="rtl"] .mail-sidebar {
  border-right: 0;
  border-left: 1px solid #e6e8ee;
}
html[dir="rtl"] .mail-folders button,
html[dir="rtl"] .message-row,
html[dir="rtl"] .message-open { text-align: right; }
html[dir="rtl"] .password-field input {
  padding-right: 14px;
  padding-left: 46px;
}
html[dir="rtl"] .password-field button {
  right: auto;
  left: 8px;
}
html[dir="rtl"] .compose-card {
  right: auto;
  left: 24px;
}

@media (max-width: 920px) {
  .login-grid {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 34px;
  }
  .login-card { order: 1; }
  .login-promo {
    order: 2;
    display: flex;
    flex-direction: column;
  }
  .smart-install {
    order: -2;
    width: min(100%, 420px);
    margin-top: 0;
  }
  .install-help {
    order: -1;
    width: min(100%, 420px);
    margin-bottom: 22px;
  }
  .login-promo h2 { font-size: clamp(2rem, 9vw, 3.1rem); }
}

@media (max-width: 780px) {
  .mail-app,
  html[dir="rtl"] .mail-app {
    grid-template-columns: 1fr;
  }
  .mail-state-auth {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }
  body.webmail-auth { overflow: auto; }
  .mail-sidebar,
  html[dir="rtl"] .mail-sidebar {
    grid-column: auto;
    height: auto;
    max-height: 44dvh;
    border-right: 0;
    border-left: 0;
    border-bottom: 1px solid #e6e8ee;
    position: sticky;
    top: 0;
    z-index: 12;
  }
  .mail-workspace {
    height: auto;
    min-height: 70dvh;
    overflow: visible;
  }
  .mail-topbar {
    align-items: stretch;
    flex-direction: column;
  }
  .search-box { width: 100%; }
  .message-row {
    grid-template-columns: 28px 1fr auto;
    grid-template-areas:
      "check sender date"
      "check subject subject";
    min-height: 72px;
    padding: 10px 12px;
  }
  .message-check { grid-area: check; }
  .star-icon { display: none; }
  .row-sender { grid-area: sender; }
  .row-subject { grid-area: subject; }
  .row-date { grid-area: date; }
}

@media (max-width: 560px) {
  .login-panel { padding: 22px; }
  .login-brand { margin-bottom: 24px; }
  .feature-list { gap: 12px; }
  .smart-install { width: 100%; }
  .folder-head {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }
  .message-actions { padding: 10px; }
  .message-actions button span,
  .select-all span { display: none; }
  .message-reader { padding: 16px; }
  .compose-card {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }
  html[dir="rtl"] .compose-card {
    right: 0;
    left: 0;
  }
}

.mail-state-auth {
  grid-template-columns: 260px minmax(0, 1fr);
  grid-template-areas: "sidebar main";
}
.mail-state-auth .mail-sidebar { grid-area: sidebar; }
.mail-state-auth .mail-main { grid-area: main; }

html[dir="rtl"] .mail-state-auth,
body.lang-rtl .mail-state-auth {
  grid-template-columns: minmax(0, 1fr) 260px;
  grid-template-areas: "main sidebar";
  direction: rtl;
}
html[dir="rtl"] .mail-state-auth .mail-sidebar,
body.lang-rtl .mail-state-auth .mail-sidebar {
  grid-area: sidebar;
  grid-column: auto;
  border-right: 0;
  border-left: 1px solid #e6e8ee;
}
html[dir="rtl"] .mail-state-auth .mail-main,
body.lang-rtl .mail-state-auth .mail-main {
  grid-area: main;
  grid-column: auto;
  direction: rtl;
}
html[dir="rtl"] .mail-state-auth .mail-topbar,
body.lang-rtl .mail-state-auth .mail-topbar,
html[dir="rtl"] .folder-head,
body.lang-rtl .folder-head,
html[dir="rtl"] .message-actions,
body.lang-rtl .message-actions {
  direction: rtl;
}
html[dir="rtl"] .mail-folders button,
body.lang-rtl .mail-folders button {
  grid-template-columns: 22px 1fr auto;
}
html[dir="rtl"] .mail-state-login,
body.lang-rtl .mail-state-login {
  grid-template-columns: 1fr;
  direction: rtl;
}
html[dir="rtl"] .search-box input,
body.lang-rtl .search-box input,
html[dir="rtl"] .compose-card input,
body.lang-rtl .compose-card input,
html[dir="rtl"] .compose-editor,
body.lang-rtl .compose-editor {
  direction: rtl;
  text-align: right;
}
html[dir="rtl"] .reader-meta-row,
body.lang-rtl .reader-meta-row {
  flex-direction: row-reverse;
}

@media (max-width: 780px) {
  html[dir="rtl"] .mail-state-auth,
  body.lang-rtl .mail-state-auth {
    grid-template-columns: 1fr;
    grid-template-areas:
      "sidebar"
      "main";
  }
  html[dir="rtl"] .mail-state-auth .mail-sidebar,
  body.lang-rtl .mail-state-auth .mail-sidebar {
    border-left: 0;
    border-bottom: 1px solid #e6e8ee;
  }
}
