/* Gmail-like Layout Styles */

.gmail-layout {
  display: flex;
  height: calc(100vh - 280px);
  min-height: 600px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
}

/* ========================================
   LEFT SIDEBAR (Labels)
   ======================================== */

.gmail-sidebar {
  width: 250px;
  min-width: 250px;
  background: #f8f9fa;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #e0e0e0;
  background: #fff;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.label-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.label-section {
  margin-bottom: 6px;
}

.label-section-title {
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Collapsible section styles */
.label-section-title.collapsible {
  display: flex;
  align-items: center;
  gap: 4px;
  user-select: none;
}

.label-section-title.collapsible:hover {
  background: rgba(0, 0, 0, 0.04);
  border-radius: 4px;
}

.collapse-arrow {
  font-size: 8px;
  transition: transform 0.2s ease;
  display: inline-block;
  width: 10px;
}

.collapsible-section.collapsed .collapse-arrow {
  transform: rotate(-90deg);
}

.collapsible-content {
  overflow: hidden;
  transition: max-height 0.2s ease;
}

.collapsible-section.collapsed .collapsible-content {
  display: none;
}

.section-total {
  margin-left: auto;
  background: #e8f0fe;
  color: #1a73e8;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
}

.section-total:empty,
.section-total[data-count="0"] {
  display: none;
}

/* Queue count tooltip indicator */
.queue-count.has-tooltip {
  cursor: help;
  border-bottom: 1px dotted #666;
}

/* VIP queue item styling */
.queue-item.vip {
  background: linear-gradient(90deg, rgba(255, 215, 0, 0.1), transparent);
}

.queue-item.vip:hover {
  background: rgba(255, 215, 0, 0.15);
}

/* Container for bubbles - allows wrapping */
.category-labels,
.relationship-labels,
.semantic-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 8px 4px 8px;
}

/* System labels stay full-width for now */
.label-section:first-child .label-item {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  user-select: none;
  border-radius: 4px;
}

/* Bubble/tag style for categories, relationships, tags */
.category-labels .label-item,
.relationship-labels .label-item,
.semantic-labels .label-item {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  user-select: none;
  border-radius: 12px;
  background: #e8e8e8;
  border: 1px solid #d0d0d0;
  gap: 4px;
}

.label-item:hover {
  background: #d8d8d8;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.label-item.active {
  background: #1976d2;
  border-color: #1565c0;
  color: white;
  font-weight: 500;
}

.label-item.active .label-name,
.label-item.active .label-icon {
  color: white;
}

.label-item.drag-over {
  background: #bbdefb;
  border: 2px dashed #1976d2;
}

.label-icon {
  font-size: 14px;
  line-height: 1;
}

.label-name {
  font-size: 11px;
  color: #333;
  white-space: nowrap;
}

.label-count {
  font-size: 10px;
  color: #666;
  background: rgba(255,255,255,0.6);
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 16px;
  text-align: center;
  font-weight: 600;
}

.label-item.active .label-count {
  background: rgba(255,255,255,0.3);
  color: white;
}

/* ========================================
   MAIN EMAIL LIST AREA
   ======================================== */

.gmail-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

/* Toolbar */
.gmail-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid #e0e0e0;
  background: #f8f9fa;
  min-height: 48px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 0 16px;
}

/* Search Box */
.search-container {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 400px;
  width: 100%;
}

.search-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px 0 0 4px;
  font-size: 14px;
  outline: none;
  min-width: 200px;
}

.search-input:focus {
  border-color: #1a73e8;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

.search-input.search-active {
  background: #e8f0fe;
  border-color: #1a73e8;
}

.search-clear-btn {
  position: absolute;
  right: 85px;
  padding: 4px 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: #999;
  display: none;
}

.search-clear-btn:hover {
  color: #333;
}

.search-input.search-active + .search-clear-btn {
  display: block;
}

.search-btn {
  padding: 8px 12px;
  background: #1a73e8;
  color: white;
  border: 1px solid #1a73e8;
  border-radius: 0;
  cursor: pointer;
  font-size: 14px;
}

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

.search-help-btn {
  padding: 8px 10px;
  background: #f8f9fa;
  border: 1px solid #ddd;
  border-left: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  color: #666;
}

.search-help-btn:hover {
  background: #e8e8e8;
}

/* Search Tooltip */
.search-tooltip {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 8px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 12px 16px;
  z-index: 1000;
  font-size: 13px;
}

.search-tooltip.visible {
  display: block;
}

.tooltip-title {
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
}

.tooltip-content p {
  margin: 6px 0;
  color: #555;
}

.tooltip-content ul {
  margin: 6px 0 6px 16px;
  padding: 0;
}

.tooltip-content li {
  margin: 4px 0;
  color: #555;
}

.tooltip-content code {
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 12px;
}

.gmail-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  margin: 0;
}

.toolbar-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
}

.toolbar-btn:hover {
  background: #e0e0e0;
}

.toolbar-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: #e0e0e0;
  margin: 0 4px;
}

.toolbar-select {
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: white;
  font-size: 13px;
  cursor: pointer;
  height: 32px;
}

.toolbar-select:hover {
  border-color: #ccc;
}

.toolbar-select:focus {
  outline: none;
  border-color: #1a73e8;
}

.email-count-display {
  font-size: 13px;
  color: #666;
  margin: 0 8px;
}

/* Email List Container */
.gmail-email-list-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

/* Email List Header */
.gmail-email-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 2px solid #e0e0e0;
  background: #f8f9fa;
  font-weight: 600;
  font-size: 12px;
  color: #5f6368;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.header-checkbox-col {
  width: 42px; /* Match checkbox column width */
}

.header-info-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.header-meta-col {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  min-width: 180px;
}

.header-item {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: default;
}

.header-item.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.2s;
}

.header-item.sortable:hover {
  color: #1976d2;
}

.header-item.sortable.active {
  color: #1976d2;
}

.sort-indicator {
  font-size: 10px;
  color: #1976d2;
  min-width: 12px;
}

/* Email List */
.gmail-email-list {
  flex: 1;
  overflow-y: auto;
  background: #fff;
}

.gmail-email-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  cursor: pointer;
  transition: all 0.2s;
  background: #fff;
}

.gmail-email-row:hover {
  box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0, 0 1px 2px 0 rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
  z-index: 2;
}

.gmail-email-row.unread {
  font-weight: 600;
  background: #f7f9fb;
}

.gmail-email-row.selected {
  background: #e3f2fd !important;
}

.gmail-email-row.dragging {
  opacity: 0.5;
  background: #f0f0f0;
  border: 2px dashed #999;
}

/* Email Row Components */
.email-checkbox-col {
  display: flex;
  align-items: center;
  gap: 8px;
}

.email-star {
  font-size: 18px;
  cursor: pointer;
  color: #ccc;
  transition: color 0.2s;
}

.email-star:hover,
.email-star.starred {
  color: #fbc02d;
}

.email-info-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0; /* Allow text truncation */
}

.email-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.email-sender {
  font-size: 14px;
  color: #202124;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}

.gmail-email-row.unread .email-sender {
  font-weight: 700;
}

.email-labels {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.email-label-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: #e0e0e0;
  color: #666;
  white-space: nowrap;
}

.email-label-badge.category {
  background: #c8e6c9;
  color: #2e7d32;
}

.email-label-badge.priority {
  background: #ffccbc;
  color: #d84315;
}

.email-label-badge.relationship {
  background: #bbdefb;
  color: #1565c0;
}

.email-subject-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
}

.email-subject {
  color: #202124;
  /* Show full subject - removed truncation */
  word-break: break-word;
  line-height: 1.4;
}

.gmail-email-row.unread .email-subject {
  font-weight: 600;
}

.email-snippet {
  color: #5f6368;
  margin-left: 4px;
}

.email-meta-col {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: #5f6368;
}

.email-confidence {
  padding: 2px 6px;
  border-radius: 4px;
  background: #e8f5e9;
  color: #2e7d32;
  font-weight: 500;
}

.email-confidence.low {
  background: #fff3e0;
  color: #e65100;
}

.email-date {
  white-space: nowrap;
}

/* Attachment Icon */
.email-attachment-icon {
  color: #666;
}

/* Empty State */
.gmail-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #666;
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.gmail-empty-state p {
  margin: 4px 0;
  font-size: 16px;
}

.empty-subtitle {
  font-size: 14px;
  color: #999;
}

/* ========================================
   DRAG AND DROP
   ======================================== */

.gmail-email-row[draggable="true"] {
  cursor: move;
}

.gmail-email-row.drag-over {
  border-top: 3px solid #1976d2;
}

.label-item[data-drop-target="true"] {
  position: relative;
}

.label-item[data-drop-target="true"]::after {
  content: "Drop here";
  position: absolute;
  right: 16px;
  font-size: 11px;
  color: #1976d2;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s;
}

.label-item.drag-over[data-drop-target="true"]::after {
  opacity: 1;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
  .gmail-sidebar {
    width: 200px;
    min-width: 200px;
  }

  .email-sender {
    max-width: 120px;
  }

  .email-meta-col {
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
  }
}

@media (max-width: 600px) {
  .gmail-sidebar {
    display: none;
  }

  .gmail-email-row {
    grid-template-columns: auto 1fr auto;
  }

  .email-meta-col .email-confidence {
    display: none;
  }
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.gmail-email-row {
  animation: slide-in 0.2s ease-out;
}

/* ========================================
   LOADING STATE
   ======================================== */

.gmail-email-list.loading {
  opacity: 0.6;
  pointer-events: none;
}

.gmail-email-list.loading::after {
  content: "Loading...";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.95);
  padding: 16px 24px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  font-weight: 500;
  color: #666;
}

/* ========================================
   READING PANE LAYOUTS (Outlook-style)
   ======================================== */

/* Container for list + reading pane */
.triage-content-area {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Layout mode: Off (default Gmail-style - click navigates away) */
.gmail-layout[data-reading-pane="off"] .triage-content-area {
  flex-direction: column;
}

.gmail-layout[data-reading-pane="off"] #inbox-list-container {
  flex: 1;
}

.gmail-layout[data-reading-pane="off"] #reading-pane {
  display: none;
}

/* Layout mode: Right (Outlook default - list left, reading pane right) */
.gmail-layout[data-reading-pane="right"] .triage-content-area {
  flex-direction: row;
}

.gmail-layout[data-reading-pane="right"] #inbox-list-container {
  width: 400px;
  min-width: 300px;
  max-width: 50%;
  border-right: 1px solid #e0e0e0;
  overflow-y: auto;
  resize: horizontal;
}

.gmail-layout[data-reading-pane="right"] #reading-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Layout mode: Bottom (list top, reading pane bottom) */
.gmail-layout[data-reading-pane="bottom"] .triage-content-area {
  flex-direction: column;
}

.gmail-layout[data-reading-pane="bottom"] #inbox-list-container {
  height: 300px;
  min-height: 200px;
  max-height: 50%;
  border-bottom: 1px solid #e0e0e0;
  overflow-y: auto;
  resize: vertical;
}

.gmail-layout[data-reading-pane="bottom"] #reading-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Reading pane container */
#reading-pane {
  background: #fff;
  display: none;
}

/* Show reading pane (with empty state) when in right/bottom mode */
.gmail-layout[data-reading-pane="right"] #reading-pane,
.gmail-layout[data-reading-pane="bottom"] #reading-pane {
  display: flex;
}

#reading-pane .reading-pane-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #666;
  font-size: 14px;
}

#reading-pane .reading-pane-empty .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* Reading pane content */
#reading-pane .thread-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

#reading-pane-content {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#reading-pane-content .reading-pane-body {
  flex: 1;
  overflow-y: auto;
}

/* Ensure iframe resizes properly */
#reading-pane-content .email-iframe {
  width: 100%;
  min-height: 200px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
}

/* Compact email rows when reading pane is active */
.gmail-layout[data-reading-pane="right"] .inbox-email-row,
.gmail-layout[data-reading-pane="bottom"] .inbox-email-row {
  padding: 8px 12px;
  min-height: 56px;
}

.gmail-layout[data-reading-pane="right"] .inbox-email-row .email-summary,
.gmail-layout[data-reading-pane="bottom"] .inbox-email-row .email-summary {
  display: none;
}

/* Selected email highlight in list when reading pane is shown */
.inbox-email-row.reading-active {
  background: #e3f2fd !important;
  border-left: 3px solid #1a73e8;
}

/* Layout toggle button */
.layout-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: #f1f3f4;
  border-radius: 4px;
  margin-left: 8px;
}

.layout-toggle button {
  padding: 6px 8px;
  background: transparent;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  opacity: 0.6;
  transition: all 0.15s;
}

.layout-toggle button:hover {
  opacity: 1;
  background: #e0e0e0;
}

.layout-toggle button.active {
  opacity: 1;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.layout-toggle button[title]::after {
  content: attr(title);
  position: absolute;
  display: none;
}

/* ========================================
   DARK MODE SUPPORT
   ======================================== */
@media (prefers-color-scheme: dark) {
    /* Main containers */
    .gmail-layout,
    .gmail-main {
        background: #1a1a1a !important;
    }

    .gmail-sidebar {
        background: #1a1a1a !important;
        border-right-color: #333 !important;
    }

    .gmail-header {
        background: #1a1a1a !important;
        border-bottom-color: #333 !important;
    }

    /* Compose button */
    .compose-button {
        background: #2d5a8f !important;
        color: #fff !important;
    }

    .compose-button:hover {
        background: #1a73e8 !important;
    }

    /* Labels/folders list */
    .label-item {
        color: #e0e0e0 !important;
    }

    .label-item:hover {
        background: #2a2a2a !important;
    }

    .label-item.active {
        background: #1e3a5f !important;
        color: #6db3ff !important;
    }

    .label-count {
        color: #888 !important;
    }

    /* Email rows */
    .gmail-email-row {
        background: #1a1a1a !important;
        border-bottom-color: #333 !important;
    }

    .gmail-email-row:hover {
        background: #222 !important;
    }

    .gmail-email-row.selected {
        background: #1a4a7a !important;
    }

    .gmail-email-row.unread {
        background: #1e2a3a !important;
    }

    /* Email content */
    .email-sender-name {
        color: #e0e0e0 !important;
    }

    .email-subject-text {
        color: #e0e0e0 !important;
    }

    .email-snippet {
        color: #888 !important;
    }

    .email-date {
        color: #888 !important;
    }

    /* Category badges */
    .category-chip,
    .label-chip {
        background: #1e3a5f !important;
        color: #6db3ff !important;
    }

    /* Star/checkbox */
    .star-button {
        color: #888 !important;
    }

    .star-button.starred {
        color: #f4b400 !important;
    }

    /* Importance marker */
    .importance-marker {
        background: #4a3a1a !important;
    }

    /* Drag and drop */
    .label-item.drag-over::after {
        background: rgba(26, 115, 232, 0.3) !important;
    }

    /* Search */
    .gmail-search {
        background: #2a2a2a !important;
        border-color: #444 !important;
    }

    .gmail-search input {
        background: transparent !important;
        color: #e0e0e0 !important;
    }

    .gmail-search input::placeholder {
        color: #888 !important;
    }

    /* Checkbox styles */
    .email-checkbox {
        border-color: #555 !important;
    }

    .email-checkbox:checked {
        background: #1a73e8 !important;
        border-color: #1a73e8 !important;
    }

    /* Pagination */
    .pagination-info {
        color: #888 !important;
    }

    .pagination-btn {
        color: #888 !important;
        background: transparent !important;
    }

    .pagination-btn:hover:not(:disabled) {
        background: #2a2a2a !important;
        color: #e0e0e0 !important;
    }

    .pagination-btn:disabled {
        color: #555 !important;
    }

    /* Confidence indicator */
    .confidence-indicator {
        background: #2a2a2a !important;
    }

    /* Preview panel */
    .preview-panel {
        background: #1a1a1a !important;
        border-left-color: #333 !important;
    }

    .preview-header {
        background: #1a1a1a !important;
        border-bottom-color: #333 !important;
    }

    .preview-subject {
        color: #fff !important;
    }

    .preview-meta {
        color: #888 !important;
    }

    .preview-body {
        color: #e0e0e0 !important;
    }

    /* Empty state */
    .empty-inbox {
        color: #888 !important;
    }

    /* Layout toggle */
    .layout-toggle {
        background: #2a2a2a !important;
    }

    .layout-toggle button {
        color: #888 !important;
    }

    .layout-toggle button:hover {
        background: #333 !important;
        color: #e0e0e0 !important;
    }

    .layout-toggle button.active {
        background: #1a1a1a !important;
        color: #fff !important;
    }
}
