/* ==========================================================================
   SendGrid Email Log Search — Styles
   ========================================================================== */

/* --- Variables --- */
:root {
  --primary: #1a73e8;
  --primary-hover: #1557b0;
  --primary-light: #e8f0fe;

  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #d2d6dc;
  --text: #1f2937;
  --text-muted: #6b7280;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --success: #16a34a;

  --status-processed: #ca8a04;
  --status-processed-bg: #fefce8;
  --status-delivered: #16a34a;
  --status-delivered-bg: #f0fdf4;
  --status-deferred: #0891b2;
  --status-deferred-bg: #ecfeff;
  --status-dropped: #dc2626;
  --status-dropped-bg: #fef2f2;
  --status-bounced: #dc2626;
  --status-bounced-bg: #fef2f2;
  --status-blocked: #6b7280;
  --status-blocked-bg: #f3f4f6;

  --radius: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* --- Layout --- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
}

.page-header {
  margin-bottom: 24px;
}

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

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text);
}

.page-header p {
  color: var(--text-muted);
  margin-top: 4px;
}

/* --- Card --- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 16px;
}

/* --- Form --- */
.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  width: 100%;
}

.form-group {
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.form-group label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-group .required {
  color: var(--error);
}

/* --- Custom Multi-Select --- */
.multi-select {
  position: relative;
}

.multi-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.multi-select-trigger:hover,
.multi-select-trigger:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  outline: none;
}

.multi-select-arrow {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 8px;
}

.multi-select-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 500;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow-y: auto;
  margin-top: 4px;
}

.multi-select-dropdown.active {
  display: block;
}

.multi-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text);
  transition: background 0.1s ease;
}

.multi-select-option:hover {
  background: var(--primary-light);
}

.multi-select-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  margin: 0;
}

.form-group input,
.form-group select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--card);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group input::placeholder {
  color: #9ca3af;
}

/* --- Toggle Switch --- */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.toggle-group label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 0.75rem;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  background: var(--bg);
}

.form-actions {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  width: 100%;
  padding-top: 8px;
}

/* --- Loading Spinner --- */
.spinner-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.spinner-overlay.active {
  display: flex;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--card);
  padding: 32px 48px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 300px;
}

.progress-container {
  width: 100%;
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 300px;
}

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

/* --- Error Display --- */
.error-display {
  display: none;
  background: var(--error-bg);
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.875rem;
}

.error-display.active {
  display: block;
}

.error-display .error-close {
  float: right;
  background: none;
  border: none;
  color: var(--error);
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}

/* --- Results --- */
.results-section {
  display: none;
}

.results-section.active {
  display: block;
}

.results-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.results-meta span {
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: var(--radius);
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.table-wrapper {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 65vh;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.results-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.results-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.results-table th.sortable:hover {
  background: var(--primary-light);
}

.sort-arrow {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.results-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.results-table tbody tr:hover {
  background: var(--primary-light);
}

.results-table .cell-truncate {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Status Badges --- */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: capitalize;
  white-space: nowrap;
}

.status-processed {
  background: var(--status-processed-bg);
  color: var(--status-processed);
}

.status-delivered {
  background: var(--status-delivered-bg);
  color: var(--status-delivered);
}

.status-deferred {
  background: var(--status-deferred-bg);
  color: var(--status-deferred);
}

.status-dropped {
  background: var(--status-dropped-bg);
  color: var(--status-dropped);
}

.status-bounced {
  background: var(--status-bounced-bg);
  color: var(--status-bounced);
}

.status-blocked {
  background: var(--status-blocked-bg);
  color: var(--status-blocked);
}

.status-unknown {
  background: var(--bg);
  color: var(--text-muted);
}

/* --- Modal --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}

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

.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  margin-bottom: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* --- Warning Modal --- */
.warning-icon {
  font-size: 2rem;
  color: #f59e0b;
  margin-bottom: 12px;
}

/* --- Detail Modal --- */
.detail-modal .modal {
  max-width: 800px;
}

.detail-content {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.8125rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* --- Detail Event List in Modal --- */
.detail-events {
  list-style: none;
  padding: 0;
}

.detail-events li {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--bg);
}

.detail-events .event-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.detail-events .event-name {
  font-weight: 600;
  text-transform: capitalize;
}

.detail-events .event-time {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.detail-events .event-details {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.detail-events .event-details dt {
  font-weight: 500;
}

.detail-events .event-details dd {
  margin-left: 0;
  margin-bottom: 4px;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 0.875rem;
}

/* --- Summary Table --- */
.summary-container {
  margin-bottom: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.summary-table th {
  padding: 12px 14px;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
  text-align: center;
  color: var(--text);
}

.summary-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: var(--card);
}

.summary-table tbody tr:last-child td {
  border-bottom: none;
}

.summary-table tbody tr:hover td {
  background: var(--primary-light);
}

.summary-table .count-row td {
  font-weight: 600;
  color: var(--text);
  font-size: 0.9375rem;
}

.summary-table .rate-row td {
  color: var(--text-muted);
}

/* Badge-style status labels in summary */
.summary-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.summary-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.summary-dot-delivered { background: var(--status-delivered); }
.summary-dot-deferred  { background: var(--status-deferred); }
.summary-dot-bounced   { background: var(--status-bounced); }
.summary-dot-blocked   { background: var(--status-blocked); }
.summary-dot-dropped   { background: var(--status-dropped); }

/* --- Responsive --- */
@media (max-width: 768px) {
  .form-group {
    flex: 1 1 100%;
  }

  .results-table {
    font-size: 0.75rem;
  }

  .results-table th,
  .results-table td {
    padding: 6px 8px;
  }

  .results-table .cell-truncate {
    max-width: 120px;
  }

  .header-content {
    flex-direction: column;
    align-items: stretch;
  }

  .header-content .btn {
    align-self: flex-start;
  }
}

/* --- Instructions Modal --- */
.instructions-modal .modal {
  max-width: 700px;
  max-height: 85vh;
}

.instructions-content {
  font-size: 0.875rem;
  line-height: 1.6;
  max-height: calc(85vh - 140px);
  overflow-y: auto;
  padding-right: 8px;
}

.instructions-content h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 20px 0 8px 0;
  color: var(--text);
}

.instructions-content h2:first-child {
  margin-top: 0;
}

.instructions-content h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 16px 0 6px 0;
  color: var(--text);
}

.instructions-content p {
  margin: 0 0 12px 0;
  color: var(--text);
}

.instructions-content ul {
  margin: 0 0 12px 0;
  padding-left: 20px;
}

.instructions-content li {
  margin-bottom: 6px;
}

.instructions-content code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8125rem;
}

.instructions-content .feature-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 12px 0;
}

.instructions-content .feature-box strong {
  color: var(--primary);
}

.instructions-content .tip {
  background: var(--primary-light);
  border-left: 3px solid var(--primary);
  padding: 8px 12px;
  margin: 12px 0;
  font-size: 0.8125rem;
}

.instructions-content .note {
  background: #fef3c7;
  border-left: 3px solid #f59e0b;
  padding: 8px 12px;
  margin: 12px 0;
  font-size: 0.8125rem;
}

/* --- Hamburger Menu --- */
.hamburger-menu {
  position: relative;
  z-index: 100;
}

.hamburger-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow);
}

.hamburger-button:hover {
  background: var(--bg);
  box-shadow: var(--shadow-lg);
}

.hamburger-button:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-light);
}

.hamburger-icon {
  width: 24px;
  height: 24px;
  color: var(--text);
}

.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  min-width: 200px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.menu-dropdown.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.menu-nav {
  padding: 8px 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  transition: background 0.1s ease;
}

.menu-item:hover {
  background: var(--primary-light);
}

.menu-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.menu-item svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

.menu-item.active svg {
  color: var(--primary);
}

.menu-item-logout {
  color: var(--error);
}

.menu-item-logout:hover {
  background: var(--error-bg);
}

.menu-item-logout svg {
  color: var(--error);
}

.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

/* --- Responsive Hamburger Menu --- */
@media (max-width: 768px) {
  .hamburger-button {
    width: 40px;
    height: 40px;
  }

  .hamburger-icon {
    width: 20px;
    height: 20px;
  }

  .menu-dropdown {
    min-width: 180px;
  }

  .menu-item {
    padding: 10px 14px;
    font-size: 0.8125rem;
  }
}

/* --- Permission Badges --- */
.permission-badge {
  display: inline-block;
  padding: 4px 8px;
  margin: 2px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  background: #e9ecef;
  color: #495057;
}
