/* ==================== EMAIL — OUTLOOK (FLUENT) ==================== */
.email-page {
  --ol-bg: #f3f2f1;
  --ol-surface: #ffffff;
  --ol-surface-alt: #faf9f8;
  --ol-border: #e1dfdd;
  --ol-text: #242424;
  --ol-muted: #605e5c;
  --ol-accent: #0f6cbd;
  --ol-accent-hover: #115ea3;
  --ol-accent-weak: #ebf3fc;
  --ol-selected: #e5f1fb;
  --ol-hover: #f5f5f5;
  --ol-danger: #c42b1c;
  --ol-flag: #d13438;
}

[data-theme="dark"] .email-page {
  --ol-bg: #1f1f1f;
  --ol-surface: #292929;
  --ol-surface-alt: #242424;
  --ol-border: #3d3d3d;
  --ol-text: #f5f5f5;
  --ol-muted: #bdbdbd;
  --ol-accent: #479ef5;
  --ol-accent-hover: #62abf5;
  --ol-accent-weak: #0f3a5c;
  --ol-selected: #0f3a5c;
  --ol-hover: #333333;
  --ol-danger: #ff6b6b;
  --ol-flag: #ff8c8c;
}

.email-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  margin-bottom: 10px;
  background: var(--ol-surface);
  border: 1px solid var(--ol-border);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}

.email-ribbon-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.email-ribbon-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--ol-accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.email-ribbon-title h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  color: var(--ol-text);
}

.email-ribbon-title p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--ol-muted);
}

#emailToolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  flex-wrap: wrap;
}

#emailToolbar .email-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--ol-text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}

#emailToolbar .email-btn:hover {
  background: var(--ol-hover);
}

#emailToolbar .email-btn.primary {
  background: var(--ol-accent);
  border-color: var(--ol-accent);
  color: #fff;
}

#emailToolbar .email-btn.primary:hover {
  background: var(--ol-accent-hover);
  border-color: var(--ol-accent-hover);
}

#emailToolbar .email-btn.danger {
  margin-left: 0;
  color: var(--ol-danger);
  background: transparent;
  border-color: transparent;
}

#emailToolbar .email-btn.danger:hover {
  background: color-mix(in srgb, var(--ol-danger) 10%, transparent);
}

#emailToolbar .email-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

#emailToolbar .email-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.email-workspace {
  display: grid;
  grid-template-columns: 210px minmax(300px, 380px) minmax(0, 1fr);
  height: min(760px, calc(100vh - 235px));
  min-height: 520px;
  background: var(--ol-surface);
  border: 1px solid var(--ol-border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .06);
}

.email-nav {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--ol-surface-alt);
  border-right: 1px solid var(--ol-border);
  overflow: hidden;
}

.email-nav-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 4px;
  color: var(--ol-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.email-nav-list {
  flex: 1;
  min-height: 0;
  padding: 4px 6px 8px;
  overflow-y: auto;
}

.email-nav-section {
  padding: 12px 8px 4px;
  color: var(--ol-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.email-nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 34px;
  padding: 7px 9px;
  border-radius: 6px;
  color: var(--ol-text);
  cursor: pointer;
  user-select: none;
}

.email-nav-item:hover {
  background: var(--ol-hover);
}

.email-nav-item.is-selected {
  background: var(--ol-selected);
  color: var(--ol-accent);
  font-weight: 600;
}

.email-nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  color: inherit;
  flex-shrink: 0;
}

.email-nav-icon svg {
  width: 16px;
  height: 16px;
}

.email-nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.email-nav-count {
  margin-left: auto;
  color: var(--ol-muted);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.email-nav-item.is-selected .email-nav-count {
  color: var(--ol-accent);
}

.email-nav-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.email-nav-delete {
  margin-left: auto;
  width: 22px;
  height: 22px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ol-muted);
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  flex-shrink: 0;
}

.email-nav-group:hover .email-nav-delete,
.email-nav-group:focus-within .email-nav-delete {
  opacity: 1;
}

.email-nav-delete:hover {
  background: color-mix(in srgb, var(--ol-danger) 12%, transparent);
  color: var(--ol-danger);
}

.email-nav-empty {
  padding: 8px;
  color: var(--ol-muted);
  font-size: 12px;
  line-height: 1.4;
}

.email-list-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--ol-surface);
  border-right: 1px solid var(--ol-border);
  overflow-y: auto;
}

.email-list-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--ol-border);
  background: var(--ol-surface);
}

.email-list-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.email-list-title-row h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ol-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ol-accent-weak);
  color: var(--ol-accent);
  font-size: 11px;
  font-weight: 600;
}

.email-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--ol-border);
  border-radius: 4px;
  background: var(--ol-surface-alt);
  color: var(--ol-muted);
}

.email-search:focus-within {
  border-color: var(--ol-accent);
  box-shadow: 0 0 0 1px var(--ol-accent);
}

.email-search-icon {
  flex-shrink: 0;
}

.email-search input {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ol-text);
  font-size: 13px;
}

.email-search input:focus {
  outline: none;
}

.email-search-clear {
  width: 20px;
  height: 20px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ol-muted);
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.email-search-clear:hover {
  background: var(--ol-hover);
  color: var(--ol-text);
}

.email-list {
  flex: 1;
  min-height: 0;
  display: block;
  overflow-y: auto;
  background: var(--ol-surface);
  overscroll-behavior: contain;
}

.email-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--ol-border);
  cursor: pointer;
  background: transparent;
  transition: background .12s ease;
}

.email-row:hover {
  background: var(--ol-hover);
}

.email-row.is-selected {
  background: var(--ol-selected);
}

.email-row.is-selected:hover {
  background: color-mix(in srgb, var(--ol-selected) 82%, var(--ol-accent) 18%);
}

.email-unread-dot,
.email-unread-spacer {
  width: 7px;
  height: 7px;
  margin-top: 6px;
  flex-shrink: 0;
}

.email-unread-dot {
  border-radius: 50%;
  background: var(--ol-accent);
}

.email-row-main {
  flex: 1;
  min-width: 0;
}

.email-row-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.email-row-from {
  min-width: 0;
  color: var(--ol-text);
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-row.is-unread .email-row-from {
  font-weight: 700;
}

.email-row-date {
  margin-left: auto;
  color: var(--ol-muted);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

.email-row-subject {
  margin-top: 2px;
  color: var(--ol-text);
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-row.is-unread .email-row-subject {
  font-weight: 700;
}

.email-row-preview {
  margin-top: 2px;
  color: var(--ol-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-row-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  min-height: 14px;
  color: var(--ol-muted);
  font-size: 11px;
  overflow: hidden;
}

.email-row-flag,
.email-row-attach,
.email-row-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
}

.email-row-flag {
  color: var(--ol-flag);
}

.email-row-flag svg,
.email-row-attach svg {
  width: 13px;
  height: 13px;
}

.email-row-group {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-row-source {
  padding: 0 4px;
  border: 1px solid var(--ol-border);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}

.email-row-actions {
  display: flex;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .12s ease;
}

.email-row:hover .email-row-actions,
.email-row:focus-within .email-row-actions,
.email-row.is-selected .email-row-actions {
  opacity: 1;
}

.email-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ol-muted);
  flex-shrink: 0;
}

.email-icon-btn:hover {
  background: var(--ol-hover);
  color: var(--ol-text);
}

.email-icon-btn.is-active {
  color: var(--ol-flag);
  background: color-mix(in srgb, var(--ol-flag) 10%, transparent);
}

.email-icon-btn svg {
  width: 16px;
  height: 16px;
}

.email-row-action:hover {
  color: var(--ol-text);
}

.email-row-delete:hover {
  color: var(--ol-danger);
  background: color-mix(in srgb, var(--ol-danger) 10%, transparent);
}

.email-list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 220px;
  padding: 32px 20px;
  color: var(--ol-muted);
  text-align: center;
}

.email-list-empty svg {
  width: 30px;
  height: 30px;
  margin-bottom: 4px;
  opacity: .7;
}

.email-list-empty h4 {
  margin: 0;
  color: var(--ol-text);
  font-size: 14px;
  font-weight: 600;
}

.email-list-empty p {
  margin: 0;
  max-width: 280px;
  font-size: 12px;
  line-height: 1.5;
}

.email-reading-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--ol-surface);
}

#emailDetail.is-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.email-reading-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  height: 100%;
  padding: 32px;
  color: var(--ol-muted);
  text-align: center;
}

.email-reading-empty svg {
  width: 40px;
  height: 40px;
  margin-bottom: 4px;
  opacity: .55;
}

.email-reading-empty h3 {
  margin: 0;
  color: var(--ol-text);
  font-size: 16px;
  font-weight: 600;
}

.email-reading-empty p {
  margin: 0;
  max-width: 340px;
  font-size: 13px;
}

.email-reading-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--ol-border);
  background: var(--ol-surface);
  flex-wrap: wrap;
}

.email-reading-toolbar-left {
  display: flex;
  align-items: center;
  gap: 4px;
}

.email-reading-toolbar-title {
  color: var(--ol-muted);
  font-size: 12px;
}

.email-reading-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  flex-wrap: wrap;
}

.email-reading-toolbar .email-btn {
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
}

.email-reading-toolbar .email-btn.primary {
  background: var(--ol-accent);
  border-color: var(--ol-accent);
  color: #fff;
}

.email-reading-toolbar .email-btn.primary:hover {
  background: var(--ol-accent-hover);
  border-color: var(--ol-accent-hover);
}

.email-reading-header {
  flex-shrink: 0;
  background: var(--ol-surface);
}

.email-reading-subject {
  margin: 14px 18px 8px;
  color: var(--ol-text);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.email-reading-sender {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 0 18px 14px;
  border-bottom: 1px solid var(--ol-border);
}

.email-avatar-lg {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ol-accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.email-sender-details {
  flex: 1;
  min-width: 0;
}

.email-sender-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.email-sender-name {
  color: var(--ol-text);
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.email-sender-address {
  color: var(--ol-muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.email-recipients {
  margin-top: 3px;
  color: var(--ol-muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.email-reading-date {
  margin-left: auto;
  color: var(--ol-muted);
  font-size: 12px;
  white-space: nowrap;
  padding-top: 2px;
}

.email-reading-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-bottom: 1px solid var(--ol-border);
  flex-wrap: wrap;
}

.email-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
  padding: 2px 8px;
  border: 1px solid var(--ol-border);
  border-radius: 999px;
  background: var(--ol-surface-alt);
  color: var(--ol-muted);
  font-size: 11px;
  line-height: 1.2;
}

.email-chip svg {
  width: 12px;
  height: 12px;
}

.email-chip-button {
  border-radius: 999px;
  font-family: inherit;
  cursor: pointer;
}

.email-chip-button:hover {
  border-color: var(--ol-accent);
  color: var(--ol-accent);
}

.email-reading-body {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 18px 20px;
  overflow-y: auto;
  overflow-wrap: anywhere;
  background: var(--ol-surface);
  color: var(--ol-text);
  font-size: 14px;
  line-height: 1.65;
  overscroll-behavior: contain;
}

.email-reading-body .email-body {
  max-height: none;
  overflow: visible;
}

.email-reading-body.is-plain .email-body-text {
  white-space: pre-wrap;
  font-family: var(--font-body);
  font-size: 14px;
  word-break: break-word;
}

.email-msg-note {
  padding: 14px 16px;
  border: 1px solid var(--ol-border);
  border-radius: 8px;
  background: var(--ol-surface-alt);
  color: var(--ol-muted);
  font-size: 13px;
}

.email-msg-note b {
  display: block;
  margin-bottom: 4px;
  color: var(--ol-text);
}

.email-attachments {
  margin: 0 0 16px 0;
  padding: 14px 16px;
  border: 1px solid var(--ol-border);
  border-radius: 10px;
  background: var(--ol-surface-alt);
}

.email-attachments h4 {
  margin: 0 0 10px 0;
  font-size: 14px;
  color: var(--ol-text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.email-attachments ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.email-attach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--ol-border);
  border-radius: 8px;
  background: var(--ol-surface);
  overflow: hidden;
}

.email-attach-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.email-attach-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--ol-surface-alt);
  color: var(--ol-text-muted);
  flex-shrink: 0;
}

.email-attach-icon.email-attach-image {
  color: #2563eb;
}

.email-attach-icon.email-attach-pdf {
  color: #dc2626;
}

.email-attach-icon.email-attach-word {
  color: #2b579a;
}

.email-attach-icon.email-attach-excel {
  color: #107c41;
}

.email-attach-icon.email-attach-zip {
  color: #0078d4;
}

.email-attach-icon.email-attach-text {
  color: #6b7280;
}

.email-attach-icon svg {
  width: 20px;
  height: 20px;
}

.email-attach-info {
  min-width: 0;
}

.email-attach-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  color: var(--ol-text);
}

.email-attach-size {
  display: block;
  font-size: 12px;
  color: var(--ol-text-muted);
  margin-top: 2px;
}

.email-attach-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.email-attach-download,
.email-attach-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ol-text-muted);
  cursor: pointer;
  text-decoration: none;
}

.email-attach-download:hover,
.email-attach-preview:hover {
  background: var(--ol-surface-alt);
  color: var(--ol-text);
}

.email-attach-download svg,
.email-attach-preview svg {
  width: 18px;
  height: 18px;
}

/* Inline image rendering in email body */
.email-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  margin: 8px auto;
}

/* Attachment preview modal */
#attachPreviewModal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  align-items: center;
  justify-content: center;
}

#attachPreviewModal .modal-content {
  background: #fff;
  border-radius: 8px;
  width: 90vw;
  max-width: 1000px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

#attachPreviewModal .modal-content img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
}

@media (max-width: 768px) {
  .email-attach-item {
    flex-direction: column;
    align-items: flex-start;
  }
  .email-attach-actions {
    align-self: flex-end;
    margin-top: 8px;
  }
}

.email-msg-note p {
  margin: 4px 0;
}

@media (max-width: 1100px) {
  .email-workspace {
    grid-template-columns: 190px minmax(280px, 330px) minmax(0, 1fr);
  }
}

@media (max-width: 980px) {
  .email-ribbon {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  #emailToolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .email-workspace {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
  }

  .email-nav {
    border-right: 0;
    border-bottom: 1px solid var(--ol-border);
  }

  .email-nav-heading {
    display: none;
  }

  .email-nav-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    overflow: visible;
  }

  .email-nav-section {
    display: none;
  }

  .email-nav-item {
    width: auto;
    flex: 0 0 auto;
    min-height: 32px;
    padding: 5px 9px;
    white-space: nowrap;
  }

  .email-nav-empty {
    white-space: nowrap;
  }

  .email-nav-delete {
    opacity: .6;
  }

  .email-list-pane {
    border-right: 0;
  }

  .email-list {
    max-height: 58vh;
  }

  .email-row-actions {
    opacity: 1;
  }

  .email-reading-pane {
    display: none;
  }

  .email-workspace.is-reading .email-nav,
  .email-workspace.is-reading .email-list-pane {
    display: none;
  }

  .email-workspace.is-reading .email-reading-pane {
    display: flex;
    min-height: 68vh;
  }
}

@media (max-width: 600px) {
  .email-ribbon-title p {
    display: none;
  }

  #emailToolbar .email-btn {
    flex: 0 0 auto;
  }

  .email-reading-subject {
    margin: 12px 14px 6px;
    font-size: 18px;
  }

  .email-reading-sender {
    padding: 0 14px 12px;
    flex-wrap: wrap;
  }

  .email-reading-date {
    width: 100%;
    margin-left: 52px;
    text-align: left;
  }

  .email-reading-meta {
    padding: 8px 14px;
  }

  .email-reading-body {
    padding: 14px;
  }
}
