/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #10b981;
  --success-dark: #059669;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --border-radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--border-radius);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

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

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

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

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

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

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

.btn-secondary {
  background: var(--gray-200);
  color: var(--gray-700);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-300);
}

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

/* Auth Section */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
}

.auth-card {
  background: white;
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}

.auth-card h1 {
  text-align: center;
  margin-bottom: 0.5rem;
  color: var(--gray-900);
}

.auth-card .subtitle {
  text-align: center;
  color: var(--gray-500);
  margin-bottom: 2rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.tab {
  flex: 1;
  padding: 0.75rem;
  background: var(--gray-100);
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-weight: 500;
  color: var(--gray-600);
  transition: all 0.15s ease;
}

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

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
}

.form-group input,
.form-group textarea {
  padding: 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  transition: border-color 0.15s ease;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.error-message {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* Dashboard */
.dashboard {
  min-height: 100vh;
}

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

.header h1 {
  font-size: 1.25rem;
  color: var(--primary);
}

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

.user-name {
  color: var(--gray-600);
  font-size: 0.875rem;
}

.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: white;
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

/* Actions */
.actions {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

/* Gmail Status */
.gmail-status {
  background: #ecfdf5;
  border: 1px solid #10b981;
  padding: 0.75rem 1rem;
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.gmail-session-note {
  width: 100%;
  font-size: 0.75rem;
  color: var(--gray-500);
  margin: 0;
}

.gmail-connected {
  color: #065f46;
  font-size: 0.875rem;
}

/* Tables */
.emails-section,
.recent-opens-section {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.emails-section h2,
.recent-opens-section h2 {
  font-size: 1.125rem;
  margin-bottom: 1rem;
  color: var(--gray-800);
}

.table-container {
  overflow-x: auto;
}

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

th, td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

th {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--gray-500);
  background: var(--gray-50);
}

td {
  font-size: 0.875rem;
}

tbody tr:hover {
  background: var(--gray-50);
}

.empty-state {
  text-align: center;
  color: var(--gray-400);
  padding: 2rem;
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-info {
  background: #dbeafe;
  color: #1e40af;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.pagination button {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  background: white;
  border-radius: var(--border-radius);
  cursor: pointer;
}

.pagination button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Recent Opens */
.recent-opens-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.open-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  background: var(--gray-50);
  border-radius: var(--border-radius);
}

.open-info {
  display: flex;
  flex-direction: column;
}

.open-subject {
  font-weight: 500;
}

.open-details {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.open-time {
  font-size: 0.75rem;
  color: var(--gray-400);
}

/* Modals */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

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

.modal-large {
  max-width: 640px;
}

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

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

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

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

.modal form,
.modal-content > div:not(.modal-header) {
  padding: 1.5rem;
}

.modal form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Pixel Result */
.pixel-result {
  border-top: 1px solid var(--gray-200);
  padding: 1.5rem;
}

.pixel-result h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.code-block {
  background: var(--gray-800);
  color: #10b981;
  padding: 1rem;
  border-radius: var(--border-radius);
  font-family: monospace;
  font-size: 0.75rem;
  overflow-x: auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin: 0.5rem 0;
}

.code-block code {
  word-break: break-all;
}

.pixel-url-label {
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--gray-600);
}

/* Warning */
.warning {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
  padding: 1rem;
  border-radius: var(--border-radius);
  margin: 1rem 1.5rem;
  font-size: 0.875rem;
}

/* Form Actions */
.form-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.help-text {
  font-size: 0.75rem;
  color: var(--gray-500);
}

/* Email Details */
#email-details-content {
  padding: 1.5rem;
}

.detail-header {
  margin-bottom: 1.5rem;
}

.detail-header h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.detail-meta {
  font-size: 0.875rem;
  color: var(--gray-500);
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.detail-stat {
  background: var(--gray-50);
  padding: 1rem;
  border-radius: var(--border-radius);
  text-align: center;
}

.detail-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.detail-stat-label {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.readers-section h4 {
  margin-bottom: 1rem;
}

.reader-card {
  background: var(--gray-50);
  padding: 1rem;
  border-radius: var(--border-radius);
  margin-bottom: 0.75rem;
}

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

.reader-ip {
  font-weight: 600;
  font-family: monospace;
}

.reader-count {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.reader-location {
  font-size: 0.875rem;
  color: var(--gray-600);
}

.reader-times {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {
  .header {
    padding: 1rem;
  }

  .main-content {
    padding: 1rem;
  }

  .actions {
    flex-direction: column;
  }

  .actions .btn {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

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