/* More (⋮) menu styles */
#more-menu { -webkit-overflow-scrolling: touch; right: 16px; }
#more-menu .menu-item { cursor: pointer; }
@media (max-width: 480px) {
  #more-menu { right: calc(env(safe-area-inset-right, 0px) + 24px) !important; }
}
:root {
  --primary: #003366;            /* NimbusBlue */
  --primary-contrast: #ffffff;
  --primary-dark: #002244;
  --primary-light: #5A9FD4;
  --bg-gray-50: #f9fafb;
  --bg-gray-100: #f3f4f6;
  --text-primary: #1a1a1a;
  --text-secondary: #6b7280;
  --border-gray: #e5e7eb;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Dark mode variable overrides */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-gray-50: #1a1a1a;
    --bg-gray-100: #222;
    --text-primary: #e0e0e0;
    --text-secondary: #888;
    --border-gray: #333;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  }
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-gray-50);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--text-primary);
}
h1 {
  background: var(--primary);
  color: #fff;
  padding: 1.5em 2em;
  margin: 0 0 2em 0;
  font-weight: 700;
  letter-spacing: -0.02em;
  box-shadow: var(--shadow-md);
}
/* Hide big title only when forcing mobile */
body.force-mobile h1 { display: none; }
#email-list {
  /* Removed max-width constraint for full-width layout */
  margin: 0;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 2.5em;
}
.email {
  border-bottom: 1px solid var(--border-gray);
  padding: 1.5em 0;
  transition: all 0.2s ease;
}
.email:last-child {
  border-bottom: none;
}
.email:hover {
  background: var(--bg-gray-50);
  margin: 0 -1em;
  padding: 1.5em 1em;
  border-radius: 12px;
}
.subject {
  font-weight: 600;
  margin-bottom: 0.75em;
  font-size: 1.125rem;
  color: var(--text-primary);
}
.model-output {
  margin-bottom: 0.75em;
  color: var(--text-secondary);
  line-height: 1.6;
}
.button-row {
  margin-top: 1em;
  display: flex;
  gap: 0.75em;
  flex-wrap: wrap;
}
button {
  padding: 0.625em 1.25em;
  border: none;
  background: var(--primary);
  color: var(--primary-contrast);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  font-size: 0.9375rem;
  box-shadow: var(--shadow-sm);
}
button:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button.selected {
  background: var(--primary-dark);
  box-shadow: var(--shadow-md);
}

/* Sender action buttons - specific styling */
#trust-sender-btn:not(:disabled)::before {
  content: '✓ ';
  font-weight: bold;
}
#trust-sender-btn:disabled {
  background: #4caf50;
}
#trust-sender-btn:disabled::before {
  content: '✓ ';
}

#ignore-sender-btn:not(:disabled)::before {
  content: '✕ ';
}
#ignore-sender-btn:disabled {
  background: #f44336;
}
#ignore-sender-btn:disabled::before {
  content: '✕ ';
}

/* Sender actions container */
.sender-actions {
  margin: 0.5em 0;
  display: flex;
  gap: 0.5em;
  flex-wrap: wrap;
}

/* Nav link-style button and count display */
.link-button {
  background: transparent;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
  border: none;
  padding: 0;
  font: inherit;
}
.count-display {
  white-space: nowrap;            /* keep X / Y on one line */
  padding: 2px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 999px;           /* pill */
  background: #f9fafb;
  font-size: 12px;
}

/* Enlarge top-row icon buttons by 50% */
.nav-row { display:flex; align-items:center; gap: 2px; }
.nav-row button { font-size: 1.5em; line-height: 1; padding: 0.15em 0.25em; }
.nav-left { display: inline-flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.nav-right { display: inline-flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.nav-right .nav-tools { display: inline-flex; align-items: center; gap: 2px; }

/* Mobile: show only More (⋮) */
@media (max-width: 480px) {
  .nav-right .nav-tools { display: none; }
  #more-menu-btn { display: inline-flex; }
}
/* Desktop: show tools, optionally hide More (but keep for parity if desired) */
@media (min-width: 481px) {
  .nav-right .nav-tools { display: inline-flex; }
  /* Uncomment to hide More on desktop: */
  /* #more-menu-btn { display: none; } */
}

/* Reserve physical space for the right-side trigger/placeholder to stabilize centering */
.nav-right .nav-placeholder { width: 2em; height: 2em; }

/* Uniform transparent icon buttons in top nav */
.nav-row .icon-btn {
  font-size: 1.5em;              /* 50% bigger icons */
  width: 2em;                    /* square-ish hit area */
  height: 2em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;                    /* minimal padding */
  background: transparent;       /* drop block behind icons */
  color: var(--primary);
  border: none;
}
.nav-row .icon-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.nav-move { display: inline-flex; align-items: center; gap: 6px; justify-content: center; flex: 1 1 auto; }
.nav-move .count-display {
  min-width: 84px;               /* consistent width helps visual centering */
  text-align: center;
}
/* Allow center group to shrink on very small screens instead of pushing right group offscreen */
.nav-move { min-width: 0; }

/* JS polyfill fixed state for nav when sticky isn't supported */
.nav-row.polyfixed {
  position: fixed !important;
  top: env(safe-area-inset-top, 0) !important;
  left: 0; right: 0;
  z-index: 120 !important;
  background: #fff;
  padding-top: 4px; padding-bottom: 4px;
  padding-left: 12px; padding-right: calc(env(safe-area-inset-right, 0px) + 12px);
  border-bottom: 1px solid #eee;
}

/* Secondary filter row under nav */
.filter-row {
  display: flex;
  align-items: center;
  justify-content: center;       /* center label + dropdown */
  gap: 8px;
  margin-bottom: 8px;
}
.filter-row label { margin: 0; font-weight: 600; }

/* Top controls layout (Tone, Category, Actions) */
.top-controls {
  margin-bottom: 1.75em;         /* allow room for the hint placed below */
  display: flex;
  align-items: center;           /* vertical align */
  gap: 12px;                     /* consistent spacing */
  flex-wrap: wrap;               /* wrap on small screens */
}
.top-controls label {
  margin: 0;                     /* remove default inline spacing */
}
.control-height {
  height: 32px;                  /* unify control heights */
  line-height: 30px;             /* visually centered text */
}
.top-controls select.control-height {
  padding: 2px 6px;
}
.category-display {
  position: relative;            /* anchor the hint */
  display: flex;
  align-items: center;           /* center the box itself vertically */
  gap: 8px;
  min-height: 32px;              /* match control height so centering is correct */
}
.category-display-stack {
  position: relative;
  display: flex;
  flex-direction: column;
}
.category-label {
  white-space: nowrap;
}
.btn.action-btn {
  margin-left: 4px;
  height: 32px;                  /* match .control-height */
  padding: 0 12px;               /* compact, consistent */
  display: inline-flex;
  align-items: center;
}

/* Fixed-height scrollable email metadata panel */
.email-meta {
  max-height: 275px;
  background-color: var(--bg-gray-50);
  overflow: auto;
  padding: 1em;
  border-radius: 8px;
  border: 1px solid var(--border-gray);
}

.subject-badges {
  margin: 0.5em 0;
  display: flex;
  gap: 0.5em;
  flex-wrap: wrap;
}

.email-summary {
  display: inline;
  white-space: normal;
  line-height: 1.6;
}

/* Prevent long URLs/strings from forcing horizontal scroll */
.email-body, .email-meta { overflow-wrap: anywhere; word-break: break-word; }

/* Tree category selector styles */
.tree-selector ul.tree {
  list-style: none;
  margin: 0.2em 0 0.2em 1em;
  padding-left: 1em;
  border-left: 1px dashed #ccc;
}
.tree-selector .tree-item { margin: 2px 0; }
.tree-selector .toggle { margin-right: 6px; color: #666; }
.tree-selector .label { padding: 1px 4px; border-radius: 3px; }
.tree-selector .label:hover { background: #eef5ff; }
.tree-selector .label.selected { background: #d6e9ff; color: #000; }
.tree-selector .tree-item.add-new { margin-top: 4px; }
.tree-selector .add-link { color: #2563eb; font-size: 12px; }
.tree-selector .add-link:hover { text-decoration: underline; }
.tree-selector .add-input { font-size: 12px; padding: 2px 6px; }

/* Category display fixed width with tail ellipsis */
.category-display-value {
  display: inline-block;
  min-width: 260px;
  max-width: 260px;
  padding: 0.5em 0.75em;
  border: 1px solid var(--border-gray);
  border-radius: 8px;
  background: white;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}
.category-display-value:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-md);
}

.category-edit-hint {
  position: absolute;            /* render below the box without increasing row height */
  top: calc(100% + 2px);
  left: 0;
  font-size: 11px;
  color: #6b7280;
  user-select: none;
}

/* Lock page scroll when any modal is open */
body.modal-open { overflow: hidden; }

/* Avoid scroll chaining from modal to page */
#category-modal { overscroll-behavior: contain; }
#category-modal-tree { overscroll-behavior: contain; }

/* --- Mobile responsive pass --- */
@media (max-width: 480px) {
  body { font-size: 16px; }
  /* Compact, single-line sticky header title on mobile */
  h1 {
    font-size: 16px;
    padding: 8px 12px;
    line-height: 1.2;
    position: fixed;
    top: env(safe-area-inset-top, 0);
    left: 0; right: 0;
    z-index: 115;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Ensure login buttons are not hidden under the fixed title */
  #login-container {
    margin-top: calc(env(safe-area-inset-top, 0px) + 56px);
    padding: 12px;
  }
  #email-list { padding: 12px; border-radius: 0; box-shadow: none; }
  .nav-row {
  position: -webkit-sticky; /* Android/WebKit fallback */
  position: sticky;
  top: 0; /* fallback for browsers without env() */
  top: env(safe-area-inset-top, 0);
  z-index: 100;
    background: #fff; padding-top: 4px; padding-bottom: 4px;
    border-bottom: 1px solid #eee;
  }
  .nav-left, .nav-right { gap: 4px; }
  .nav-row .icon-btn { width: 40px; height: 40px; font-size: 22px; }
  .count-display { padding: 2px 8px; }
  #more-menu-btn { margin-right: 8px; }
  .filter-row { position: static; z-index: auto; }
  .email-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .email-table table { width: max-content; }
  .email-table th:first-child, .email-table td:first-child {
    position: sticky; left: 0; background: #fff; z-index: 1;
  }
  .top-controls { gap: 8px; }
  .category-display-value { min-width: 180px; max-width: 55vw; }
  .category-edit-hint { position: static; margin-top: 2px; }
  .category-display { margin-bottom: 10px; }
  .sender-actions button { height: 40px; }
  .email-meta { max-height: none; }
  .email-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* Full-screen-ish modals */
  #category-modal, #help-modal, #how-modal, #settings-modal {
    top: 0 !important; left: 0 !important; transform: none !important;
    width: 100vw !important; max-width: 100vw !important;
    height: 100vh !important; max-height: 100vh !important;
    border-radius: 0 !important; padding: 16px !important;
    overflow: auto !important;
  }
  #category-modal-tree { max-height: calc(100vh - 150px) !important; }
  #category-save, #category-cancel, #how-close, #help-close, #settings-save, #settings-cancel {
    height: 44px; padding: 0 14px; font-size: 16px;
  }
}

/* Force mobile styles regardless of width when body.force-mobile is present (debug/troubleshoot) */
body.force-mobile .nav-row {
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 0; right: 0;
  z-index: 120;
  background: #fff; padding-top: 4px; padding-bottom: 4px;
  border-bottom: 1px solid #eee;
}
body.force-mobile .nav-row .icon-btn { width: 40px; height: 40px; font-size: 22px; }
body.force-mobile .nav-left, body.force-mobile .nav-right { gap: 2px; }
body.force-mobile .nav-move { gap: 4px; }
body.force-mobile .nav-move .count-display { min-width: 64px; font-size: 11px; }
body.force-mobile .nav-left, body.force-mobile .nav-right { gap: 4px; }
body.force-mobile .nav-row .icon-btn { width: 44px; height: 44px; font-size: 24px; }
body.force-mobile .count-display { padding: 2px 10px; }
body.force-mobile .filter-row { position: static; z-index: auto; }
/* Avoid category hint overlapping buttons on mobile */
body.force-mobile .category-edit-hint { position: static; margin-top: 2px; }
body.force-mobile .category-display { margin-bottom: 6px; }

/* Subtle hint for horizontal scroll */
.scroll-hint { font-size: 12px; color: #6b7280; text-align: right; margin-top: 4px; }
body.force-mobile #email-list { padding: 12px; border-radius: 0; box-shadow: none; }
body.force-mobile .email-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
body.force-mobile .email-table table { width: max-content; }
body.force-mobile .email-table th:first-child, body.force-mobile .email-table td:first-child {
  position: sticky; left: 0; background: #fff; z-index: 1;
}

/* Desktop: hide the More (⋮) button */
@media (min-width: 481px) {
  #more-menu-btn { display: none !important; }
}

/* When sticky polyfill is active or in force-mobile, always show the More (⋮) button */
.nav-row.polyfixed #more-menu-btn,
body.force-mobile #more-menu-btn {
  display: inline-flex !important;
}
body.force-mobile .top-controls { gap: 8px; }
body.force-mobile .category-display-value { min-width: 180px; max-width: 55vw; }
body.force-mobile .sender-actions button { height: 40px; }
body.force-mobile .email-meta { max-height: none; }
body.force-mobile #category-modal, body.force-mobile #help-modal, body.force-mobile #how-modal, body.force-mobile #settings-modal {
  top: 0 !important; left: 0 !important; transform: none !important;
  width: 100vw !important; max-width: 100vw !important;
  height: 100vh !important; max-height: 100vh !important;
  border-radius: 0 !important; padding: 16px !important;
  overflow: auto !important;
}
body.force-mobile #category-modal-tree { max-height: calc(100vh - 150px) !important; }
body.force-mobile #category-save, body.force-mobile #category-cancel, body.force-mobile #how-close, body.force-mobile #help-close, body.force-mobile #settings-save, body.force-mobile #settings-cancel {
  height: 44px; padding: 0 14px; font-size: 16px;
}

/* ============ Advanced Settings Tab System (Phase 2) ============ */
.settings-tab-btn {
  transition: all 0.2s ease;
}

.settings-tab-btn:hover {
  background-color: #f0f0f0;
  color: var(--primary);
}

.settings-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary) !important;
}

.settings-tab-content {
  display: none;
}

.settings-tab-content.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideUp {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-100%);
  }
}

/* Horizontal scrollable tabs row */
.settings-tabs-row {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-gray);
}

.settings-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.settings-nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.settings-nav-btn.active {
  background: var(--primary-light, #e8f4fd);
  color: var(--primary);
  font-weight: 600;
  border-bottom: 2px solid var(--primary);
}

.settings-badge {
  display: none;
  background: #f59e0b;
  color: white;
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 8px;
  margin-left: auto;
}

.settings-badge.visible {
  display: inline-block;
}

/* Tab content styling */
.settings-tab-content h4 {
  color: var(--primary);
  margin-bottom: 0.5em;
  font-size: 1.1em;
}

.settings-tab-content label {
  cursor: pointer;
  user-select: none;
}

.settings-tab-content input[type="checkbox"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
}

.settings-tab-content input[type="text"],
.settings-tab-content input[type="number"],
.settings-tab-content input[type="file"],
.settings-tab-content select {
  padding: 0.625em 0.875em;
  border: 1px solid var(--border-gray);
  border-radius: 8px;
  font-size: 1em;
  transition: all 0.2s ease;
  font-family: inherit;
}

.settings-tab-content input[type="text"]:focus,
.settings-tab-content input[type="number"]:focus,
.settings-tab-content input[type="file"]:focus,
.settings-tab-content select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}

/* Style profile sliders */
.style-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #e0e0e0;
  outline: none;
  transition: background 0.2s ease;
}

.style-slider:hover {
  background: #d0d0d0;
}

.style-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.style-slider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.style-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  border: none;
}

.style-slider::-moz-range-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.style-control-group {
  margin-bottom: 1.5em;
  padding: 1em;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
}

/* Sender rules list */
#settings-sender-rules-list ul {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

#settings-sender-rules-list li {
  margin: 0.5em 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#settings-sender-rules-list .remove-rule {
  background: #f44336;
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 1.1em;
  display: flex;
  align-items: center;
  justify-content: center;
}

#settings-sender-rules-list .remove-rule:hover {
  background: #d32f2f;
}

/* Category rules list */
#settings-category-rules-list .edit-rule,
#settings-category-rules-list .delete-rule {
  padding: 0.4em 0.8em;
  border: 1px solid #ddd;
  background: #f9f9f9;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9em;
}

#settings-category-rules-list .edit-rule:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

#settings-category-rules-list .delete-rule:hover {
  background: #f44336;
  color: white;
  border-color: #f44336;
}

/* Data management buttons */
#export-data-btn,
#import-data-btn,
#reset-data-btn,
#add-category-rule-btn {
  padding: 0.75em 1.5em;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1em;
  font-weight: 500;
  transition: all 0.2s ease;
}

#export-data-btn,
#import-data-btn,
#add-category-rule-btn {
  background: var(--primary);
  color: white;
}

#export-data-btn:hover,
#import-data-btn:hover,
#add-category-rule-btn:hover {
  background: #00264d;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 51, 102, 0.2);
}

#reset-data-btn {
  background: #f44336;
  color: white;
}

#reset-data-btn:hover {
  background: #d32f2f;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(244, 67, 54, 0.2);
}

/* Responsive adjustments */
@media (max-width: 480px) {
  #settings-modal {
    min-width: calc(100vw - 32px) !important;
    max-width: 100vw !important;
    max-height: 90vh !important;
    top: 5% !important;
  }
  
  .settings-tab-btn {
    font-size: 0.85em;
    padding: 10px 8px !important;
  }
  
  .settings-tab-content {
    padding: 12px !important;
  }
}

/* ============ Sender Manager Tab System (Phase 2) ============ */
.sender-type-tab {
  transition: all 0.2s ease;
}

.sender-type-tab:hover {
  background-color: #f0f0f0;
  color: var(--primary);
}

.sender-type-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary) !important;
}

#sender-table tbody tr:hover {
  background-color: #f9f9f9;
}

#sender-table td {
  border-bottom: 1px solid #eee;
}

.remove-sender:hover {
  background: #d32f2f !important;
  transform: translateY(-1px);
}

.sender-checkbox {
  cursor: pointer;
  width: 18px;
  height: 18px;
}

#sender-search {
  transition: all 0.2s ease;
  font-family: inherit;
}

#sender-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}

@media (max-width: 480px) {
  #sender-modal {
    min-width: calc(100vw - 32px) !important;
    max-width: 100vw !important;
    min-height: 80vh !important;
    top: 10% !important;
  }
  
  #sender-table {
    font-size: 0.9em;
  }
  
  #sender-table th,
  #sender-table td {
    padding: 8px !important;
  }
  
  .remove-sender {
    padding: 4px 8px !important;
    font-size: 0.8em !important;
  }
}

/* ============ Category Rule Builder (Phase 2 Part 3) ============ */
#rule-editor-modal {
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

#rule-form-content input[type="text"],
#rule-form-content input[type="number"],
#rule-form-content select {
  width: 100%;
  padding: 0.625em 0.875em;
  border: 1px solid var(--border-gray);
  border-radius: 8px;
  font-size: 0.95em;
  transition: all 0.2s ease;
  font-family: inherit;
}

#rule-form-content input[type="text"]:focus,
#rule-form-content input[type="number"]:focus,
#rule-form-content select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}

#rule-form-content label {
  display: block;
  margin-bottom: 0.5em;
  font-weight: 600;
  font-size: 0.95em;
}

#rule-form-content .settings-tab-content {
  padding: 0;
  animation: none;
}

#settings-category-rules-list {
  display: flex;
  flex-direction: column;
  gap: 1em;
}

#settings-category-rules-list .rule-card {
  padding: 1em;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fafafa;
  transition: all 0.2s ease;
}

#settings-category-rules-list .rule-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border-color: var(--primary);
}

#settings-category-rules-list code {
  background: #f0f0f0;
  padding: 2px 4px;
  border-radius: 2px;
  font-family: monospace;
  font-size: 0.9em;
}

#settings-category-rules-list button {
  padding: 0.4em 0.8em;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  transition: all 0.2s ease;
}

#settings-category-rules-list .edit-rule {
  background: #2196F3;
  color: white;
}

#settings-category-rules-list .edit-rule:hover {
  background: #1976D2;
  transform: translateY(-1px);
}

#settings-category-rules-list .delete-rule {
  background: #f44336;
  color: white;
}

#settings-category-rules-list .delete-rule:hover {
  background: #d32f2f;
  transform: translateY(-1px);
}

@media (max-width: 480px) {
  #rule-editor-modal {
    min-width: calc(100vw - 32px) !important;
    max-width: 100vw !important;
    top: 5% !important;
  }
  
  #rule-form-content {
    padding: 12px !important;
  }
}

/* ============ Analytics Dashboard (Phase 2 Part 4) ============ */
#analytics-modal {
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

#analytics-content {
  background: #f9f9f9;
}

.time-range-btn {
  transition: all 0.2s ease;
}

.time-range-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#analytics-content input[type="text"],
#analytics-content select {
  padding: 0.625em 0.875em;
  border: 1px solid var(--border-gray);
  font-size: 0.95em;
  border-radius: 8px;
  transition: all 0.2s ease;
  font-family: inherit;
}
#analytics-content input[type="text"]:focus,
#analytics-content select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}

#analytics-content table {
  background: white;
  border-radius: 6px;
  overflow: hidden;
}

#analytics-content table th {
  background: #f0f0f0;
  font-weight: 600;
  color: #333;
}

#analytics-content table tr:hover {
  background: #f9f9f9;
}

#export-csv-btn {
  transition: all 0.2s ease;
}

#export-csv-btn:hover {
  background: #e0e0e0;
  transform: translateY(-1px);
}

#export-pdf-btn {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Modal display rules: ensure flex layout when modals are shown via JavaScript */
#settings-modal[style*="display: block"] {
  display: flex !important;
}

#sender-modal[style*="display: block"] {
  display: flex !important;
}

#rule-editor-modal[style*="display: block"] {
  display: flex !important;
}

#analytics-modal[style*="display: block"] {
  display: flex !important;
}

@media (max-width: 480px) {
  #analytics-modal {
    min-width: calc(100vw - 32px) !important;
    max-width: 100vw !important;
    top: 5% !important;
    max-height: 95vh !important;
  }

  #analytics-content {
    padding: 12px !important;
  }

  #analytics-content > div {
    gap: 1em !important;
  }
}

/* ============ New Tab-Based Dashboard Styles ============ */

/* Ensure consistent CSS variable names */
:root {
  --nimbus-blue: var(--primary);
  --nimbus-blue-dark: var(--primary-dark);
  --nimbus-blue-pale: #e6f0ff;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
}

/* Hide h1 in new dashboard */
#reviewer h1 {
  display: none;
}

/* Ensure main reviewer container is visible */
#reviewer {
  min-height: 100vh;
}

/* Empty state styling */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* Email review card additional styles */
.email-review-card {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.email-review-card h3 {
  color: var(--primary);
  margin-bottom: 1rem;
}

.email-review-card h4 {
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

/* Review form styling */
.review-form {
  background: var(--bg-gray-50);
  padding: 2rem;
  border-radius: 12px;
  margin-top: 2rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.form-control {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-gray);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: white;
}

.form-control:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-color: var(--primary);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* Responsive adjustments for new dashboard */
@media (max-width: 768px) {
  .dashboard-container {
    padding: 1rem;
  }

  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .email-review-card {
    padding: 1.5rem;
  }

  .review-form {
    padding: 1.5rem;
  }
}

/* ===== PWA Install Banner Styles ===== */

.pwa-install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid #e0e0e0;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  z-index: 1000;
  transition: transform 0.3s ease;
}

.pwa-install-banner.hidden {
  transform: translateY(100%);
}

.pwa-install-icon {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  flex-shrink: 0;
}

.pwa-install-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.pwa-install-text strong {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.pwa-install-text span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.pwa-install-btn {
  background: #1a73e8;
  color: white;
  border: none;
  padding: 0.5rem 1.25rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
  flex-shrink: 0;
}

.pwa-install-btn:hover {
  background: #1557b0;
}

.pwa-install-dismiss {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
  flex-shrink: 0;
}

.pwa-install-dismiss:hover {
  background: var(--bg-gray-100);
}

@media (max-width: 480px) {
  .pwa-install-banner {
    padding: 0.625rem 0.75rem;
    gap: 0.75rem;
  }

  .pwa-install-icon {
    width: 40px;
    height: 40px;
  }

  .pwa-install-text strong {
    font-size: 0.875rem;
  }

  .pwa-install-text span {
    font-size: 0.75rem;
  }

  .pwa-install-btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }
}

/* ===== Relationship Widget Styles ===== */

.relationship-widget {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
}

.relationship-section,
.priority-section,
.tags-section {
  margin-bottom: 1.5rem;
}

.section-label {
  display: block;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.section-label .hint {
  display: block;
  font-weight: 400;
  color: #64748b;
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Multi-Select Relationship Buttons */
.btn-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border: 2px solid #cbd5e1;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.95rem;
  color: #334155;
}

.btn-tag:hover {
  border-color: #94a3b8;
  background: #f8fafc;
  color: #1e293b;
}

.btn-tag.active {
  border-color: #2563eb;
  background: #dbeafe;
  color: #1e40af;
}

.btn-tag .emoji {
  font-size: 1.2em;
}

.btn-tag .checkmark {
  color: #2563eb;
  font-weight: bold;
}

/* Single-Select Priority Buttons */
.btn-priority {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border: 2px solid #cbd5e1;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.95rem;
  color: #334155;
}

.btn-priority:hover {
  border-color: #94a3b8;
  background: #f8fafc;
  color: #1e293b;
}

.btn-priority.active {
  font-weight: 600;
}

.btn-priority.priority-vip.active {
  border-color: #dc2626;
  background: #fee2e2;
  color: #991b1b;
}

.btn-priority.priority-important.active {
  border-color: #f59e0b;
  background: #fef3c7;
  color: #92400e;
}

.btn-priority.priority-normal.active {
  border-color: #6b7280;
  background: #f3f4f6;
  color: #374151;
}

.btn-priority.priority-low.active {
  border-color: #9ca3af;
  background: #f9fafb;
  color: #6b7280;
}

.btn-priority.priority-ignored.active {
  border-color: #6b7280;
  background: #e5e7eb;
  color: #4b5563;
}

/* Context Tag Buttons (Smaller) */
.btn-tag-small {
  padding: 0.5rem 0.75rem;
  border: 1px solid #cbd5e1;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.875rem;
  color: #334155;
}

.btn-tag-small:hover {
  border-color: #94a3b8;
  background: #f8fafc;
  color: #1e293b;
}

.btn-tag-small.active {
  border-color: #6366f1;
  background: #e0e7ff;
  color: #4338ca;
}

/* Action Buttons */
.action-buttons {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e2e8f0;
}

.action-buttons .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.action-buttons .icon {
  font-size: 1.1em;
}

/* ========================================
   DARK MODE SUPPORT - Element overrides
   ======================================== */
@media (prefers-color-scheme: dark) {
    /* Main containers with hardcoded backgrounds */
    #email-list,
    .email:hover,
    .email-meta,
    .page-header,
    .tree-category-selector,
    .category-tree,
    .review-form input,
    .review-form textarea,
    .review-form select,
    .settings-tab-content input,
    .settings-tab-content select {
        background: #1a1a1a !important;
        color: #e0e0e0 !important;
    }

    /* Cards and panels */
    .email-review-card,
    .settings-panel,
    .modal-content,
    .dropdown-menu,
    .table-wrapper,
    .stats-section {
        background: #1a1a1a !important;
        border-color: #333 !important;
    }

    /* Tables */
    table th,
    table td {
        background: #1a1a1a !important;
        color: #e0e0e0 !important;
        border-color: #333 !important;
    }

    table thead th {
        background: #222 !important;
    }

    table tbody tr:hover td {
        background: #2a2a2a !important;
    }

    /* Form inputs */
    input,
    textarea,
    select {
        background: #2a2a2a !important;
        color: #e0e0e0 !important;
        border-color: #444 !important;
    }

    input::placeholder,
    textarea::placeholder {
        color: #666 !important;
    }

    /* Category tree */
    .category-node {
        color: #e0e0e0 !important;
    }

    .category-node:hover {
        background: #2a2a2a !important;
    }

    .category-node.selected {
        background: #1a4a7a !important;
        color: #fff !important;
    }

    /* Tags */
    .btn-tag-small {
        background: #2a2a2a !important;
        border-color: #444 !important;
        color: #e0e0e0 !important;
    }

    .btn-tag-small:hover {
        background: #333 !important;
        border-color: #555 !important;
    }

    .btn-tag-small.active {
        background: #1e3a5f !important;
        border-color: #2d5a8f !important;
        color: #6db3ff !important;
    }

    /* Borders */
    .action-buttons {
        border-top-color: #333 !important;
    }

    hr {
        border-color: #333 !important;
    }
}
