/* ============================================================
   EA Email Portal — Fluent UI-inspired OWA-like Styles
   ============================================================ */

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

body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  color: #323130;
  background: #faf9f8;
  overflow: hidden;
  height: 100vh;
}

.hidden { display: none !important; }

/* === Toast notification === */
.toast {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  font-size: 13px;
  color: #fff;
  transition: transform 0.25s ease;
}
.toast.hidden { display: none; }
.toast.success { background: #107c10; }
.toast.error { background: #a4262c; }
.toast-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  margin-left: 12px;
  line-height: 1;
}

/* === Offline banner === */
.offline-banner {
  background: #fff4ce;
  color: #835c00;
  text-align: center;
  padding: 8px;
  font-size: 12px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
}
.offline-banner.hidden { display: none; }

/* === Login screen === */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #0078d4 0%, #005a9e 100%);
}
.login-card {
  background: #fff;
  border-radius: 8px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  max-width: 400px;
  width: 90%;
}
.login-title {
  font-size: 24px;
  font-weight: 600;
  color: #323130;
  margin-bottom: 12px;
}
.login-subtitle {
  font-size: 14px;
  color: #605e5c;
  margin-bottom: 28px;
  line-height: 1.5;
}
.btn-login {
  padding: 12px 32px;
  font-size: 15px;
}

/* === Main app layout === */
.main-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* === Header === */
.header {
  background: #0078d4;
  color: #fff;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; }
.header-title { font-size: 16px; font-weight: 600; }
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.header-user-name { font-weight: 600; }
.header-user-email { opacity: 0.85; }
.btn-header-signout {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-header-signout:hover { background: rgba(255,255,255,0.25); }

/* === Three-panel layout === */
.panels-container {
  display: grid;
  grid-template-columns: 220px 350px 1fr;
  flex: 1;
  overflow: hidden;
  border-bottom: 1px solid #edebe9;
}

/* === Left panel === */
.panel-left {
  background: #f3f2f1;
  border-right: 1px solid #edebe9;
  overflow-y: auto;
  padding: 12px 0;
  resize: horizontal;
  min-width: 160px;
  max-width: 350px;
}
.panel-section { padding: 0 12px; margin-bottom: 16px; }
.panel-label {
  font-size: 11px;
  font-weight: 600;
  color: #605e5c;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding: 0 4px;
}
.mailbox-selector {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #c8c6c4;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}
.folder-list { display: flex; flex-direction: column; }
.folder-item {
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.1s;
}
.folder-item:hover { background: #e1dfdd; }

/* === Middle panel === */
.panel-middle {
  border-right: 1px solid #edebe9;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  resize: horizontal;
  min-width: 250px;
  max-width: 600px;
}
.toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #edebe9;
  flex-shrink: 0;
}
.btn-toolbar { font-size: 12px; padding: 6px 12px; }
.email-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.load-more {
  padding: 12px;
  text-align: center;
  flex-shrink: 0;
}

/* === Email list items === */
.email-list-item {
  padding: 10px 12px;
  border-bottom: 1px solid #f3f2f1;
  cursor: pointer;
  transition: background 0.1s;
}
.email-list-item:hover { background: #f3f2f1; }
.email-list-item.selected { background: #e1dfdd; border-left: 3px solid #0078d4; }
.email-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}
.email-item-sender {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.email-item-date {
  font-size: 11px;
  color: #605e5c;
  white-space: nowrap;
  margin-left: 8px;
}
.email-item-subject {
  font-size: 13px;
  color: #605e5c;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.email-item-category {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  background: #e1dfdd;
  color: #323130;
}

/* === Right panel (reading pane) === */
.panel-right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}
.reading-pane-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #a19f9d;
  font-size: 15px;
}
.reading-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.reading-pane-headers {
  padding: 16px 20px;
  border-bottom: 1px solid #edebe9;
  flex-shrink: 0;
}
.rp-subject {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  word-wrap: break-word;
}
.rp-meta {
  font-size: 13px;
  color: #605e5c;
  margin-bottom: 2px;
}
.reading-pane-body-container {
  flex: 1;
  overflow: hidden;
}
.rp-body-iframe {
  width: 100%;
  height: 100%;
  border: none;
}
.rp-categorization {
  padding: 12px 20px;
  border-top: 1px solid #edebe9;
  background: #faf9f8;
  flex-shrink: 0;
}
.rp-cat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.rp-cat-row label { font-weight: 600; }
.rp-cat-row select {
  padding: 4px 8px;
  border: 1px solid #c8c6c4;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
.rp-cat-actions {
  display: flex;
  gap: 8px;
}

/* === Tabs === */
.tabs {
  display: flex;
  border-top: 1px solid #edebe9;
  border-bottom: 1px solid #edebe9;
  padding: 0 16px;
  background: #fff;
  flex-shrink: 0;
}
.tab {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #605e5c;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-family: inherit;
}
.tab.active { color: #0078d4; border-bottom-color: #0078d4; }
.tab:hover { color: #0078d4; }
.tab:focus-visible { outline: 2px solid #0078d4; outline-offset: -2px; }

/* === Tab content === */
.tab-content {
  display: none;
  padding: 12px 16px;
  overflow-y: auto;
  flex: 0 0 auto;
  max-height: 40vh;
}
.tab-content.active { display: block; }

/* === Loading / empty === */
.loading, .empty-state {
  text-align: center;
  padding: 24px 0;
  color: #605e5c;
  font-size: 13px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid #0078d4; outline-offset: 2px; }
.btn-primary { background: #0078d4; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #106ebe; }
.btn-secondary { background: #fff; color: #0078d4; border: 1px solid #0078d4; }
.btn-secondary:hover:not(:disabled) { background: #f3f9fd; }
.btn-confirm { background: #107c10; color: #fff; }
.btn-confirm:hover:not(:disabled) { background: #0b6a0b; }
.btn-route { background: #8764b8; color: #fff; }
.btn-route:hover:not(:disabled) { background: #6b4fa0; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-retry { background: #d83b01; color: #fff; margin-left: 8px; }
.btn-retry:hover:not(:disabled) { background: #b7300a; }
.btn-danger { background: #a4262c; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #8b1f24; }

/* === Filter bar === */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.filter-bar label { font-weight: 600; font-size: 13px; }
.filter-bar select {
  padding: 5px 8px;
  border: 1px solid #c8c6c4;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}

/* === Email cards (review/status) === */
.email-card {
  background: #fff;
  border: 1px solid #edebe9;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.email-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}
.email-subject {
  font-weight: 600;
  font-size: 13px;
  flex: 1;
  margin-right: 8px;
  word-break: break-word;
}
.email-sender {
  font-size: 12px;
  color: #605e5c;
  margin-bottom: 8px;
}
.email-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 12px;
}
.confidence { color: #605e5c; }
.email-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.email-actions select {
  padding: 4px 6px;
  border: 1px solid #c8c6c4;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
}
.error-reason {
  color: #a4262c;
  font-size: 12px;
  margin-top: 4px;
}

/* === State badges === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.badge-Pending-Review  { background: #0078d4; }
.badge-Confirmed       { background: #107c10; }
.badge-Overridden      { background: #d83b01; }
.badge-Routed          { background: #8764b8; }
.badge-Failed          { background: #a4262c; }
.badge-Uncategorized   { background: #a19f9d; }

/* === Bulk actions bar === */
.bulk-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #edebe9;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.email-card .card-checkbox { margin-right: 8px; }
.bulk-progress {
  font-size: 12px;
  color: #605e5c;
  margin-left: 8px;
}

/* === Config tab === */
.config-list { display: flex; flex-direction: column; gap: 6px; }
.config-rule {
  background: #fff;
  border: 1px solid #edebe9;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}
.config-rule-info { flex: 1; }
.config-rule-info strong { font-size: 13px; }
.config-rule-info span { display: block; color: #605e5c; margin-top: 2px; }
.config-form { margin-top: 8px; }
.config-input {
  display: block;
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 6px;
  border: 1px solid #c8c6c4;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
.config-input:focus { outline: 2px solid #0078d4; outline-offset: -1px; }
.config-form-actions { display: flex; gap: 8px; margin-top: 4px; }

/* === Responsive: 1024px–1920px === */
@media (max-width: 1200px) {
  .panels-container {
    grid-template-columns: 180px 280px 1fr;
  }
}
@media (max-width: 1024px) {
  .panels-container {
    grid-template-columns: 160px 240px 1fr;
  }
  .header-user-email { display: none; }
}

/* === Focus styles for accessibility === */
select:focus-visible,
input:focus-visible {
  outline: 2px solid #0078d4;
  outline-offset: -1px;
}
.email-list-item:focus-visible {
  outline: 2px solid #0078d4;
  outline-offset: -2px;
}
