/* ============================================================
   Design System - Apple Design + Emil Principles
   ============================================================ */

:root {
  /* Colors - Lighter theme */
  --base: #F1F5F9;
  --surface: #FFFFFF;
  --surface-elevated: #FFFFFF;
  --border: #CBD5E1;
  --border-subtle: #E2E8F0;

  /* Accent - Sky blue (Gmail-inspired) */
  --accent: #0EA5E9;
  --accent-hover: #0284C7;
  --accent-subtle: rgba(14, 165, 233, 0.15);

  /* Semantic colors */
  --success: #10B981;
  --success-subtle: rgba(16, 185, 129, 0.15);
  --error: #EF4444;
  --error-subtle: rgba(239, 68, 68, 0.15);
  --warning: #F59E0B;

  /* Text */
  --text: #0F172A;
  --text-secondary: #475569;
  --text-tertiary: #64748B;

  /* Layout */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  /* Emil's animation principles */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --duration-ui: 200ms;
  --duration-modal: 300ms;
}

/* ============================================================
   Reset & Base
   ============================================================ */

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

html {
  font-size: 16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--base);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100vh;
  overflow: hidden;
}

code {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.9em;
  background: var(--surface-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

/* ============================================================
   Container & Layout
   ============================================================ */

.container {
  max-width: 100%;
  margin: 0;
  padding: 8px;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  margin-bottom: 8px;
  flex-shrink: 0;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  width: 48px;
  height: 48px;
  background: var(--accent-subtle);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.header-title h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}

.header-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
}

.main-grid {
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 8px;
  align-items: start;
  flex: 1;
  min-height: 0;
}

@media (max-width: 1200px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   Panel Component
   ============================================================ */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.hint-text {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 400;
}

.panel-body {
  padding: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.panel-actions {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  background: var(--base);
}

/* ============================================================
   Input Section
   ============================================================ */

.input-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface-elevated);
  border-radius: var(--radius-sm);
}

.input-hint svg {
  flex-shrink: 0;
  color: var(--accent);
}

.accounts-input {
  width: 100%;
  min-height: 320px;
  padding: 16px;
  background: var(--base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  transition: border-color var(--duration-ui) var(--ease-out);
}

.accounts-input:focus {
  outline: none;
  border-color: var(--accent);
}

.accounts-input::placeholder {
  color: var(--text-tertiary);
}

.input-meta {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.account-count #account-count-number {
  font-weight: 600;
  color: var(--accent);
}

/* ============================================================
   Buttons - Emil's principles: scale(0.97) on press
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--duration-ui) var(--ease-out),
              background var(--duration-ui) var(--ease-out),
              box-shadow var(--duration-ui) var(--ease-out),
              opacity var(--duration-ui) var(--ease-out);
  user-select: none;
}

.btn:active {
  transform: scale(0.97); /* Emil principle: button press feedback */
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(14, 165, 233, 0.3);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.btn-secondary {
  background: var(--success);
  color: #fff;
  box-shadow: 0 1px 3px rgba(16, 185, 129, 0.3);
}

.btn-secondary:hover {
  background: #059669;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.btn-outline {
  background: var(--warning);
  color: #fff;
  border: 1px solid var(--warning);
  box-shadow: 0 1px 3px rgba(245, 158, 11, 0.3);
}

.btn-outline:hover {
  background: #D97706;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
}

.btn-docs {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: transform var(--duration-ui) var(--ease-out),
              background var(--duration-ui) var(--ease-out);
}

.btn-docs:hover {
  background: var(--border);
}

.btn-docs:active {
  transform: scale(0.97);
}

/* ============================================================
   Results Header & Filters
   ============================================================ */

.results-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  padding: 0 8px;
  background: var(--accent-subtle);
  color: var(--accent);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
}

.filter-chips {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-ui) var(--ease-out);
}

.chip:hover {
  background: var(--surface-elevated);
  border-color: var(--border);
}

.chip.active {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent);
}

.chip:active {
  transform: scale(0.95);
}

.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.chip-dot.success {
  background: var(--success);
}

.chip-dot.error {
  background: var(--error);
}

/* ============================================================
   Empty State
   ============================================================ */

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
}

.empty-illustration {
  text-align: center;
  max-width: 320px;
}

.empty-icon {
  width: 120px;
  height: 120px;
  margin: 0 auto 24px;
  color: var(--text-tertiary);
  opacity: 0.5;
}

.empty-illustration h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-illustration p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ============================================================
   Results Grid - Signature element with stagger animation
   ============================================================ */

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

@media (max-width: 768px) {
  .results-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   Result Card - Emil's principles: scale(0.95) entry
   ============================================================ */

.result-card {
  background: var(--surface-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);

  /* Emil principle: start from scale(0.95), not scale(0) */
  opacity: 0;
  transform: scale(0.95);
  animation: cardEnter var(--duration-ui) var(--ease-out) forwards;
  transition: all 0.2s cubic-bezier(0.23, 1, 0.32, 1);
}

.result-card:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
}

@keyframes cardEnter {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.result-card[data-status="loading"] {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--surface-elevated) 0%, rgba(14, 165, 233, 0.08) 100%);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.15);
}

.result-card[data-status="error"] {
  border-color: var(--error);
  background: var(--error-subtle);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.12);
}

.result-card[data-status="success"] {
  border-color: var(--border);
  background: var(--surface-elevated);
}

/* Card Loading State */
.card-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 12px;
  color: var(--text-secondary);
  font-size: 12px;
}

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

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.card-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--accent-subtle);
  color: var(--accent);
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
}

.card-email {
  flex: 1;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Error State */
.card-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  background: var(--base);
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 11px;
}

.icon-error {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--error);
  display: inline-block;
}

.icon-error {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--error);
  display: inline-block;
}

/* Success State with OTP */
.card-success {
  margin-bottom: 8px;
}

.otp-label {
  font-size: 10px;
  color: var(--text-secondary);
  margin-bottom: 5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.otp-code {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--accent-subtle);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.btn-copy-otp {
  width: 100%;
  padding: 8px;
  background: var(--base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-ui) var(--ease-out);
}

.btn-copy-otp:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--accent);
}

.btn-copy-otp:active {
  transform: scale(0.97);
}

.btn-copy-otp.copied {
  background: var(--success-subtle);
  border-color: var(--success);
  color: var(--success);
}

/* Card Meta */
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.email-count {
  font-size: 11px;
  color: var(--text-tertiary);
}

.btn-view-detail {
  padding: 5px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-ui) var(--ease-out);
}

.btn-view-detail:hover {
  background: var(--surface);
  color: var(--text);
}

.btn-view-detail:active {
  transform: scale(0.95);
}

/* Footer Actions */
.footer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Style footer action buttons with vibrant colors */
.footer-actions .btn-secondary {
  background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.footer-actions .btn-secondary:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
  transform: translateY(-1px);
}

.footer-actions .btn-outline {
  background: linear-gradient(135deg, #8B5CF6 0%, #7C3AED 100%);
  color: white;
  border: none;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.footer-actions .btn-outline:hover {
  background: linear-gradient(135deg, #7C3AED 0%, #6D28D9 100%);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.4);
  transform: translateY(-1px);
}

/* Export CSV button - Orange */
.footer-actions .btn-primary {
  background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(249, 115, 22, 0.3);
}

.footer-actions .btn-primary:hover {
  background: linear-gradient(135deg, #EA580C 0%, #C2410C 100%);
  box-shadow: 0 4px 16px rgba(249, 115, 22, 0.4);
  transform: translateY(-1px);
}

/* ============================================================
   Modal - Apple principles: origin-aware, interruptible
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal.open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 20, 0.8);
  backdrop-filter: blur(8px);

  opacity: 0;
  transition: opacity var(--duration-modal) var(--ease-out);
}

.modal.open .modal-backdrop {
  opacity: 1;
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Modal enters from scale(0.95), not center (Emil principle) */
  opacity: 0;
  transform: scale(0.95);
  transition: all var(--duration-modal) var(--ease-out);
}

.modal.open .modal-content {
  opacity: 1;
  transform: scale(1);
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-ui) var(--ease-out);
}

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

.modal-close:active {
  transform: scale(0.95);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

/* ============================================================
   Toast Notifications
   ============================================================ */

.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  padding: 16px 20px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  position: relative;

  /* Enter from top with scale(0.95) */
  opacity: 1;
  transform: translateY(0) scale(1);
  animation: toastEnter var(--duration-ui) var(--ease-out) forwards;
}

@keyframes toastEnter {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.toast.toast-success {
  border-color: var(--success);
  background: var(--success-subtle);
}

.toast.toast-error {
  border-color: var(--error);
  background: var(--error-subtle);
}

/* ============================================================
   Loading Spinner
   ============================================================ */

.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.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);
  }
}

/* ============================================================
   Reduced Motion - Apple principles
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .result-card {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .modal-content {
    transition: opacity var(--duration-ui) ease;
    transform: none !important;
  }
}

/* ============================================================
   Hover Media Query - Touch device protection
   ============================================================ */

@media (hover: hover) and (pointer: fine) {
  .btn:hover,
  .chip:hover,
  .btn-docs:hover,
  .btn-copy-otp:hover,
  .btn-view-detail:hover,
  .modal-close:hover {
    /* Hover states already defined above */
  }
}

/* ============================================================
   Animation for fallback toast - Top Right
   ============================================================ */

@keyframes slideInFromTop {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideOutToTop {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* Old animations for backward compatibility */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

