* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #64748b;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #f8fafc;
  --bg-dark: #e2e8f0;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --white: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1);
}

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

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-badge {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 500;
}

.status-badge.online {
  background: #dcfce7;
  color: #166534;
}

.status-badge.offline {
  background: #fee2e2;
  color: #991b1b;
}

/* Main Layout */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
}

.sidebar-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
  margin-bottom: 0;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.section-header h3 {
  margin-bottom: 0;
}

.mailbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.mailbox-item {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: background 0.15s;
  gap: 0.5rem;
}

.mailbox-item:hover {
  background: var(--bg);
}

.mailbox-item.active {
  background: var(--primary);
  color: var(--white);
}

.mailbox-item.selected {
  background: #dbeafe;
}

.mailbox-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.mailbox-info {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-width: 0;
}

.mailbox-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mailbox-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.mailbox-count {
  background: var(--bg-dark);
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.mailbox-item.active .mailbox-count {
  background: rgba(255, 255, 255, 0.2);
}

.mailbox-copy-btn {
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 0.125rem 0.25rem;
  font-size: 0.75rem;
  border-radius: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.mailbox-item:hover .mailbox-copy-btn {
  opacity: 1;
}

.mailbox-copy-btn:hover {
  color: var(--primary);
  background: #dbeafe;
}

.mailbox-copy-btn.copied {
  color: var(--success);
  background: #dcfce7;
}

.mailbox-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 0.125rem 0.25rem;
  font-size: 0.875rem;
  border-radius: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.mailbox-item:hover .mailbox-delete-btn {
  opacity: 1;
}

.mailbox-delete-btn:hover {
  color: var(--danger);
  background: #fee2e2;
}

.server-info {
  font-size: 0.875rem;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 0.375rem 0;
}

.info-row code {
  background: var(--bg);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
}

/* Content Area */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.email-list-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.email-list-header {
  padding: 1rem 1.5rem;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.email-list-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.email-list {
  flex: 1;
  overflow-y: auto;
  background: var(--white);
}

.email-item {
  display: flex;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.email-item:hover {
  background: var(--bg);
}

.email-item.unread {
  background: #eff6ff;
}

.email-item.unread:hover {
  background: #dbeafe;
}

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

.email-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  margin-right: 1rem;
  flex-shrink: 0;
}

.email-body {
  flex: 1;
  min-width: 0;
}

.email-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.email-from {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-date {
  color: var(--text-light);
  font-size: 0.875rem;
  flex-shrink: 0;
  margin-left: 1rem;
}

.email-subject {
  color: var(--text);
  margin-bottom: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-preview {
  color: var(--text-light);
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  color: var(--text-light);
}

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

/* Email View */
.email-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--white);
}

.email-view-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

.email-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.email-content-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.email-content-subject {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.email-content-meta {
  display: flex;
  gap: 2rem;
  font-size: 0.875rem;
  color: var(--text-light);
}

.email-content-meta strong {
  color: var(--text);
}

.email-content-body {
  font-size: 1rem;
  line-height: 1.7;
}

.email-content-body pre {
  white-space: pre-wrap;
  font-family: inherit;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

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

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

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

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

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-dark);
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-xs {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 0.5rem;
  background: transparent;
  border: 1px solid var(--border);
}

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

/* Form Elements */
.select {
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  background: var(--white);
  cursor: pointer;
}

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

.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

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

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--white);
  border-radius: 0.5rem;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

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

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

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

.modal-content form {
  padding: 1.5rem;
}

/* Generate Status */
.gen-status {
  padding: 0.75rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.gen-status.loading {
  background: #fef3c7;
  color: #92400e;
}

.gen-status.success {
  background: #dcfce7;
  color: #166534;
}

.gen-status.error {
  background: #fee2e2;
  color: #991b1b;
}

/* Generation Progress */
.gen-progress {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.gen-progress-text {
  font-weight: 500;
}

.gen-progress-bar {
  height: 8px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.gen-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.gen-progress-count {
  font-size: 0.8125rem;
  text-align: right;
}

/* Jobs List */
.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
}

.jobs-empty {
  color: var(--text-light);
  font-size: 0.8125rem;
  text-align: center;
  padding: 0.5rem;
}

.job-item {
  background: var(--bg);
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

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

.job-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.job-rerun-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 24px;
  height: 24px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.job-rerun-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.job-item.processing {
  background: #fef3c7;
  border-left: 3px solid var(--warning);
}

.job-item.completed {
  background: #dcfce7;
  border-left: 3px solid var(--success);
}

.job-item.failed {
  background: #fee2e2;
  border-left: 3px solid var(--danger);
}

.job-item.pending {
  background: var(--bg);
  border-left: 3px solid var(--secondary);
}

.job-topic {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.job-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-light);
  font-size: 0.75rem;
}

.job-progress-bar {
  height: 4px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 2px;
  margin-top: 0.375rem;
  overflow: hidden;
}

.job-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.job-item.completed .job-progress-fill {
  background: var(--success);
}

.job-item.failed .job-progress-fill {
  background: var(--danger);
}

/* Utility */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .email-list-header {
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}
