/* Raymond Archive v2.0 - Ultra-Modern UI */

:root {
  --bg-primary: #0b1020;
  --bg-secondary: #121a2e;
  --bg-tertiary: #1a2642;
  --text-primary: #e7ecff;
  --text-secondary: #aab3d6;
  --text-muted: #6b7a99;
  --border: rgba(255,255,255,.08);
  --border-hover: rgba(255,255,255,.15);
  --accent: #6ea8fe;
  --accent-hover: #5a96ec;
  --danger: #ff6b6b;
  --success: #51cf66;
  --warning: #ffd93d;
  --sidebar-width: 260px;
  --preview-width: 420px;
  --header-height: 56px;
  --transition-speed: 0.15s;
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  --text-primary: #212529;
  --text-secondary: #495057;
  --text-muted: #868e96;
  --border: rgba(0,0,0,.08);
  --border-hover: rgba(0,0,0,.15);
  --accent: #3b82f6;
  --accent-hover: #2563eb;
}

* { 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-primary);
  color: var(--text-primary);
  overflow: hidden;
  line-height: 1.5;
}

/* =========================
   Layout: 3-Panel Design
   ========================= */

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 20px;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.brand a {
  color: var(--text-primary);
  text-decoration: none;
}

.brand-icon {
  width: 24px;
  height: 24px;
  color: var(--accent);
}

.header-nav {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.header-nav a, .header-nav button {
  padding: 8px 14px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: all var(--transition-speed) ease;
  cursor: pointer;
}

.header-nav a:hover, .header-nav button:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}

.header-nav a.active {
  background: var(--bg-tertiary);
  border-color: var(--border-hover);
  color: var(--accent);
}

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* =========================
   Sidebar: Folders & Filters
   ========================= */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition-speed) ease;
  cursor: pointer;
  margin-bottom: 2px;
}

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

.nav-item.active {
  background: var(--bg-tertiary);
  color: var(--accent);
  font-weight: 600;
}

.nav-item-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-item-label {
  flex: 1;
}

.nav-item-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.nav-section {
  margin-top: 20px;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 8px 12px 6px;
}

/* =========================
   Email List: Table View
   ========================= */

.email-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

.list-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-secondary);
}

.search-box {
  flex: 1;
  max-width: 500px;
}

.search-input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  transition: all var(--transition-speed) ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 168, 254, 0.1);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.list-toolbar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-secondary);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-text {
  font-size: 13px;
  color: var(--text-secondary);
}

.list-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.email-table {
  width: 100%;
  border-collapse: collapse;
}

.email-table thead {
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.email-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.email-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition-speed) ease;
}

.email-table tbody tr:hover {
  background: var(--bg-secondary);
}

.email-table tbody tr.selected {
  background: rgba(110, 168, 254, 0.08);
}

.email-table tbody tr.active {
  background: rgba(110, 168, 254, 0.12);
  border-left: 3px solid var(--accent);
}

.email-table td {
  padding: 14px 16px;
  font-size: 14px;
  vertical-align: middle;
}

.email-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
}

.email-subject {
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 400px;
}

.email-sender, .email-date {
  color: var(--text-secondary);
  font-size: 13px;
}

.email-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(110, 168, 254, 0.12);
  color: var(--accent);
  border: 1px solid rgba(110, 168, 254, 0.2);
}

.tag-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* =========================
   Preview Pane: Email Content
   ========================= */

.preview-pane {
  width: var(--preview-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.preview-subject {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
  line-height: 1.3;
}

.preview-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-meta-row {
  display: flex;
  gap: 8px;
  font-size: 13px;
}

.preview-meta-label {
  color: var(--text-muted);
  min-width: 60px;
}

.preview-meta-value {
  color: var(--text-secondary);
  flex: 1;
}

.preview-actions {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.preview-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.preview-body-content {
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.6;
  font-size: 14px;
  color: var(--text-primary);
}

.preview-attachments {
  padding: 20px;
  border-top: 1px solid var(--border);
}

.attachment-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.attachment-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  transition: all var(--transition-speed) ease;
  cursor: pointer;
}

.attachment-item:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-hover);
}

.attachment-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
}

.attachment-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

.attachment-size {
  font-size: 12px;
  color: var(--text-muted);
}

/* =========================
   Buttons & Inputs
   ========================= */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-speed) ease;
  text-decoration: none;
}

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

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
  border-color: var(--border-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

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

.btn-sm {
  padding: 6px 10px;
  font-size: 13px;
}

.btn-icon {
  width: 16px;
  height: 16px;
}

/* =========================
   Bulk Selection Toolbar
   ========================= */

.bulk-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 12px 20px;
  background: rgba(110, 168, 254, 0.12);
  border-bottom: 1px solid rgba(110, 168, 254, 0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bulk-toolbar-info {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.bulk-toolbar-actions {
  display: flex;
  gap: 8px;
}

/* =========================
   Loading & Empty States
   ========================= */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 40px;
  text-align: center;
}

.empty-state-icon {
  width: 60px;
  height: 60px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.empty-state-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state-description {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 400px;
}

/* =========================
   Pagination
   ========================= */

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

.pagination-btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* =========================
   Responsive Design
   ========================= */

/* Tablet: Hide sidebar, keep list + preview */
@media (max-width: 1200px) {
  .sidebar {
    position: fixed;
    left: -260px;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    z-index: 1001;
    transition: left var(--transition-speed) ease;
  }
  
  .sidebar.open {
    left: 0;
  }
  
  .sidebar-overlay {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
  }
  
  .sidebar-overlay.open {
    display: block;
  }
}

/* Mobile: Single column, toggle between list and preview */
@media (max-width: 768px) {
  :root {
    --preview-width: 100%;
  }
  
  .preview-pane {
    position: fixed;
    top: var(--header-height);
    right: -100%;
    width: 100%;
    height: calc(100vh - var(--header-height));
    z-index: 1002;
    transition: right var(--transition-speed) ease;
  }
  
  .preview-pane.open {
    right: 0;
  }
  
  .header-nav a span {
    display: none;
  }
  
  .email-subject {
    max-width: 200px;
  }
}

/* =========================
   Utilities
   ========================= */

.hidden { display: none !important; }
.visible { display: block !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.p-4 { padding: 16px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.font-semibold { font-weight: 600; }
.text-muted { color: var(--text-muted); }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* =========================
   Theme Toggle
   ========================= */

.theme-toggle {
  position: relative;
  width: 52px;
  height: 26px;
  background: var(--bg-tertiary);
  border-radius: 13px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition-speed) ease;
}

.theme-toggle-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: transform var(--transition-speed) ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle.active .theme-toggle-slider {
  transform: translateX(26px);
}

.theme-icon {
  width: 12px;
  height: 12px;
  color: var(--bg-primary);
}
