@font-face {
  font-family: 'Manrope';
  src: url('/fonts/manrope-latin.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('/fonts/plus-jakarta-sans-var-latin.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

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

:root {
  color-scheme: light dark;
  --bg: #1D1E20;
  --bg2: #222325;
  --bg3: #2A2B2E;
  --surface: #26272B;
  --surface-h: #2E3035;
  --border: #35363B;
  --border-h: #6D7078;

  --accent: #AA0000;
  --accent-hover: #C20A0A;
  --accent-light: #FF6B6B;
  --pastel-bg: #311E20;
  --pastel-ink: #FF8585;

  --green: #10B981;
  --green-ink: #34D399;
  --red: #FF6B6B;
  --yellow: #FBBF24;

  --text: #ECEDEF;
  --text-2: #A3A5AB;
  --text-3: #A3A5AB;

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 22px;

  --sidebar-w: 280px;
  --topbar-h: 64px;

  --font: 'Manrope', system-ui, -apple-system, sans-serif;
  --font-heading: 'Plus Jakarta Sans', system-ui, sans-serif;
  --trans: 180ms ease;
}

:root:has(> head > meta[name="color-scheme"][content="light"]),
html.light {
  color-scheme: light;
  --bg: #FAFAFA;
  --bg2: #FFFFFF;
  --bg3: #F3F4F6;
  --surface: #F3F4F6;
  --surface-h: #E5E7EB;
  --border: #E6E7EB;
  --border-h: #888A92;

  --accent: #AA0000;
  --accent-hover: #8A0000;
  --accent-light: #AA0000;
  --pastel-bg: #FCEAEA;
  --pastel-ink: #8A0000;

  --green: #047857;
  --green-ink: #047857;
  --red: #AA0000;
  --yellow: #B45309;

  --text: #1F2024;
  --text-2: #5C5D63;
  --text-3: #5C5D63;
}

html,
body {
  height: 100%;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

button,
a[href],
[role="button"] {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

:focus-visible {
  outline: 2px solid var(--accent-light);
  outline-offset: 2px;
}

html.is-embedded #standaloneSidebarFooter {
  display: none;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100dvh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--trans), min-width var(--trans), transform var(--trans);
  position: relative;
  z-index: 30;
  overflow: hidden;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.logo-img {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.logo-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.logo-text {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 15px;
  color: var(--text);
  line-height: 1.2;
}

.logo-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-light);
}

.sidebar-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px 6px;
  flex-shrink: 0;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-2);
}

.sidebar-actions {
  display: flex;
  gap: 4px;
}

.bulk-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 14px;
  background: var(--pastel-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.bulk-selected-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--pastel-ink);
}

.bulk-action-btns {
  display: flex;
  gap: 4px;
}

.account-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.account-item-empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--text-2);
  font-size: 13px;
}

.account-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  transition: background-color 140ms ease, border-color 140ms ease;
}

.account-item:hover {
  background: var(--bg3);
}

.account-item.active {
  background: var(--pastel-bg);
  border-color: color-mix(in srgb, var(--accent-light) 35%, transparent);
}

.account-avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #FFFFFF;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.account-info {
  flex: 1;
  min-width: 0;
}

.account-email {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-del {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.account-del:hover {
  background: var(--pastel-bg);
  color: var(--accent-light);
}

.sidebar-cta-wrap {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-add-account {
  width: 100%;
  min-height: 44px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #FFFFFF;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 140ms ease;
}

.btn-add-account:hover {
  background: var(--accent-hover);
}

.sidebar-footer {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sponsor-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--bg3);
  border: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}

.sponsor-link img {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
}

.sponsor-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.sponsor-label {
  font-size: 10px;
  color: var(--text-2);
  font-weight: 600;
}

.sponsor-name {
  font-size: 12px;
  color: var(--text);
}

/* Main area */
.main-wrapper {
  flex: 1;
  min-width: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.topbar-title-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar-title {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-2);
  font-size: 11px;
  font-family: inherit;
  text-align: left;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.sso-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--pastel-bg);
  color: var(--pastel-ink);
}

.btn-theme {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border-h);
  background: var(--bg3);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-theme:hover {
  border-color: var(--accent-light);
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.icon-btn:hover {
  border-color: var(--border-h);
}

.icon-btn-sm {
  min-width: 32px;
  min-height: 32px;
  border-radius: 8px;
}

.icon-btn-danger {
  color: var(--accent-light);
}

.connection-info {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--bg3);
  border: 1px solid var(--border);
}

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-2);
}

.connection-info.success .conn-dot {
  background: var(--green);
}

.connection-info.error .conn-dot {
  background: var(--red);
}

.connection-info.loading .conn-dot {
  background: var(--yellow);
}

.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--pastel-bg);
  color: var(--pastel-ink);
  font-size: 11.5px;
  font-weight: 700;
}

/* Dropdown */
.cyber-dropdown {
  position: relative;
}

.cyber-dropdown-btn {
  min-height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border-h);
  background: var(--bg3);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.cyber-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 170px;
  background: var(--bg2);
  border: 1px solid var(--border-h);
  border-radius: 14px;
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 3px;
  z-index: 50;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
}

.cyber-dropdown-menu.show {
  display: flex;
}

.cyber-dropdown-item {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
}

.cyber-dropdown-item:hover {
  background: var(--bg3);
}

.cyber-dropdown-item.active {
  background: var(--accent);
  color: #FFFFFF;
}

/* Split View */
.content-area {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}

.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 20px;
  gap: 14px;
}

.welcome-icon {
  width: 68px;
  height: 68px;
  border-radius: 20px;
  background: var(--pastel-bg);
  color: var(--pastel-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome-screen h2 {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 800;
}

.welcome-screen p {
  max-width: 44ch;
  color: var(--text-2);
  font-size: 14px;
}

.btn-primary {
  min-height: 46px;
  padding: 0 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #FFFFFF;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border-h);
  border-radius: var(--radius);
  background: var(--bg3);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
}

.email-list-panel {
  width: 380px;
  max-width: 100%;
  border-right: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.email-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.email-item {
  position: relative;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  transition: border-color 140ms ease, background-color 140ms ease;
}

.email-item:hover {
  border-color: var(--border-h);
}

.email-item.active {
  background: var(--pastel-bg);
  border-color: var(--accent-light);
}

.unread-dot {
  position: absolute;
  top: 16px;
  left: 10px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-light);
}

.email-item-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.email-item-sender {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-item-date {
  font-size: 11.5px;
  color: var(--text-2);
  flex-shrink: 0;
}

.email-item-subject {
  margin-top: 3px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-item-preview {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pagination {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.btn-page {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-h);
  background: var(--bg3);
  color: var(--text);
  font-weight: 600;
  font-size: 12.5px;
}

.page-info {
  font-size: 12px;
  color: var(--text-2);
}

.email-detail-panel {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.detail-placeholder,
.empty-state,
.error-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px 20px;
  text-align: center;
  color: var(--text-2);
}

.detail-header {
  padding: 18px 22px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.back-btn {
  display: none;
  align-self: flex-start;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-h);
  background: var(--bg3);
  color: var(--text);
  font-weight: 600;
  align-items: center;
  gap: 6px;
}

.detail-subject {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.detail-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.meta-row {
  display: flex;
  gap: 10px;
}

.meta-label {
  min-width: 68px;
  color: var(--text-2);
  font-weight: 600;
}

.meta-value {
  color: var(--text);
  word-break: break-word;
}

.detail-body {
  padding: 22px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  overflow-x: auto;
}

.ms-error-card {
  margin: 12px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--accent-light) 35%, transparent);
  background: var(--pastel-bg);
  color: var(--pastel-ink);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ms-error-code {
  font-weight: 800;
  font-size: 12px;
}

.ms-error-friendly {
  font-weight: 700;
  color: var(--text);
}

.ms-error-desc {
  font-size: 12.5px;
  color: var(--text-2);
}

.skeleton-item {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-line {
  height: 11px;
  border-radius: 6px;
  background: var(--bg3);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  width: 100%;
  max-width: 540px;
  background: var(--bg2);
  border: 1px solid var(--border-h);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 800;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
}

.required {
  color: var(--accent-light);
}

.bulk-counter {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
}

.bulk-counter.has-items {
  color: var(--accent-light);
}

.format-hint {
  font-size: 12px;
  color: var(--text-2);
}

textarea {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border-h);
  background: var(--bg3);
  color: var(--text);
  padding: 12px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}

.bulk-preview {
  max-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}

.preview-row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--green-ink);
}

.preview-row.err {
  color: var(--accent-light);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.modal-error {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--pastel-bg);
  color: var(--pastel-ink);
  font-size: 12.5px;
  font-weight: 600;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 80;
  background: var(--bg2);
  border: 1px solid var(--border-h);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-color: var(--green);
}

.toast.error {
  border-color: var(--accent-light);
}

.loader-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.loader-box {
  background: var(--bg2);
  border: 1px solid var(--border-h);
  border-radius: 16px;
  padding: 20px 26px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}

.loader-ring,
.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent-light);
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    width: min(84vw, 300px);
    min-width: min(84vw, 300px);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 16px 0 36px rgba(0, 0, 0, 0.45);
  }
  .email-list-panel {
    width: 100%;
    border-right: none;
  }
  .email-detail-panel {
    position: fixed;
    inset: 0;
    z-index: 40;
    transform: translateX(100%);
    transition: transform var(--trans);
  }
  .email-detail-panel.mobile-open {
    transform: translateX(0);
  }
  .back-btn {
    display: inline-flex;
  }
}
