/* Import serif fonts for calm workspace aesthetic */
@import url('https://fonts.googleapis.com/css2?family=Crimson+Text:ital,wght@0,400;0,600;0,700;1,400&family=Source+Serif+Pro:ital,wght@0,400;0,600;0,700;1,400&family=Source+Code+Pro:wght@400;600&display=swap');

/* CSS Custom Properties for Calm Workspace Theme */
:root {
  /* Paper-inspired background colors */
  --bg-primary: #F8F6F1;
  --bg-secondary: #F5F2ED;
  --bg-tertiary: #F0EDE6;
  
  /* Surface colors with subtle variations */
  --surface-primary: #FFFFFF;
  --surface-secondary: #FFFEF9;
  --surface-tertiary: #FFFBF5;
  --surface-hover: #FFF8F0;
  
  /* Text colors with high contrast */
  --text-primary: #2C2C2C;
  --text-secondary: #4A4A4A;
  --text-tertiary: #666666;
  --text-inverse: #2C2C2C;
  --text-muted: #888888;
  
  /* Accent colors */
  --accent-primary: #D4A574;
  --accent-secondary: #8B7355;
  --accent-subtle: #C9B79C;
  
  /* Border colors */
  --border-light: #E5E0D8;
  --border-medium: #D4CFC4;
  --border-dark: #C1B8A8;
  
  /* Shadow system for layered paper effect */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.16);
  --shadow-paper: 0 1px 3px rgba(0, 0, 0, 0.02), 0 2px 6px rgba(0, 0, 0, 0.04), 0 4px 8px rgba(0, 0, 0, 0.06);
  
  /* Typography */
  --font-serif: 'Source Serif Pro', 'Crimson Text', Georgia, serif;
  --font-mono: 'Source Code Pro', 'IBM Plex Mono', monospace;
  
  /* Spacing scale */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  
  /* Border radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;
}

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

body {
  font-family: var(--font-serif);
  background: var(--bg-primary);
  color: var(--text-inverse);
  min-height: 100vh;
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; }

p {
  margin-bottom: var(--space-md);
  color: var(--text-secondary);
}

/* Header Styles */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-dark);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-lg) 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.logo i {
  font-size: 2rem;
  color: var(--accent-primary);
}

.logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

/* Navigation */
.nav {
  display: flex;
  gap: var(--space-sm);
}

.nav-btn {
  background: transparent;
  border: 1px solid var(--border-dark);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-inverse);
  transition: all var(--transition-normal);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  position: relative;
  overflow: hidden;
}

.nav-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface-primary);
  transform: translateY(100%);
  transition: transform var(--transition-normal);
  z-index: -1;
}

.nav-btn:hover {
  border-color: var(--accent-primary);
  color: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.nav-btn:hover::before {
  transform: translateY(0);
}

.nav-btn.active {
  background: var(--surface-primary);
  color: var(--text-primary);
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-paper);
}

/* Main Content */
.main {
  padding: var(--space-xl) 0;
}

.tool-section {
  display: none;
  animation: fadeIn var(--transition-slow) ease;
}

.tool-section.active {
  display: block;
}

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

.tool-header {
  text-align: center;
  margin-bottom: var(--space-2xl);
}

.tool-header h2 {
  font-size: 2.25rem;
  margin-bottom: var(--space-sm);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

.tool-header p {
  font-size: 1.125rem;
  color: var(--text-muted);
  font-family: var(--font-serif);
  max-width: 600px;
  margin: 0 auto;
}

/* Upload Area */
.upload-area {
  background: var(--surface-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  text-align: center;
  border: 2px dashed var(--border-medium);
  transition: all var(--transition-normal);
  cursor: pointer;
  margin-bottom: var(--space-xl);
  box-shadow: var(--shadow-paper);
  position: relative;
  overflow: hidden;
}

.upload-area::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, transparent 0%, rgba(212, 165, 116, 0.03) 100%);
  pointer-events: none;
}

.upload-area:hover {
  border-color: var(--accent-primary);
  background: var(--surface-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.upload-area.dragover {
  border-color: var(--accent-secondary);
  background: var(--surface-hover);
  transform: scale(1.02);
  box-shadow: var(--shadow-xl);
}

.upload-content i {
  font-size: 3rem;
  color: var(--accent-primary);
  margin-bottom: var(--space-lg);
  opacity: 0.8;
}

.upload-content h3 {
  font-size: 1.5rem;
  margin-bottom: var(--space-sm);
  color: var(--text-primary);
  font-weight: 600;
}

.upload-content p {
  color: var(--text-tertiary);
  margin-bottom: var(--space-xl);
  font-size: 1rem;
}

.browse-btn {
  background: var(--accent-primary);
  color: var(--text-primary);
  border: none;
  padding: var(--space-sm) var(--space-xl);
  border-radius: var(--radius-md);
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}

.browse-btn:hover {
  background: var(--accent-secondary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Files Container */
.files-container {
  background: var(--surface-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-xl);
  box-shadow: var(--shadow-paper);
  border: 1px solid var(--border-light);
}

.files-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border-light);
}

.files-header h3 {
  font-size: 1.25rem;
  color: var(--text-primary);
  font-weight: 600;
}

.clear-all-btn {
  background: transparent;
  color: #B85450;
  border: 1px solid #E8B4B8;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.clear-all-btn:hover {
  background: #B85450;
  color: white;
  border-color: #B85450;
}

/* Files List */
.files-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  max-height: 400px;
  overflow-y: auto;
  padding-right: var(--space-sm);
}

.files-list::-webkit-scrollbar {
  width: 6px;
}

.files-list::-webkit-scrollbar-track {
  background: var(--surface-tertiary);
  border-radius: 3px;
}

.files-list::-webkit-scrollbar-thumb {
  background: var(--accent-subtle);
  border-radius: 3px;
}

.file-item {
  display: flex;
  align-items: center;
  padding: var(--space-lg);
  background: var(--surface-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  transition: all var(--transition-normal);
  cursor: move;
  box-shadow: var(--shadow-sm);
}

.file-item:hover {
  border-color: var(--accent-subtle);
  background: var(--surface-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.file-item.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
}

.file-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  margin-right: var(--space-lg);
  font-size: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.file-icon.pdf {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
  color: #dc2626;
}

.file-icon.image {
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
  color: #2563eb;
}

.file-info {
  flex: 1;
}

.file-name {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
  font-family: var(--font-serif);
}

.file-details {
  font-size: 0.875rem;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

.file-actions {
  display: flex;
  gap: var(--space-sm);
}

.file-action-btn {
  background: transparent;
  border: none;
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-action-btn:hover {
  background: var(--surface-tertiary);
  color: var(--text-primary);
}

.file-action-btn.delete:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* Action Buttons */
.action-buttons {
  display: flex;
  justify-content: center;
  gap: var(--space-lg);
}

.btn {
  padding: var(--space-md) var(--space-xl);
  border-radius: var(--radius-md);
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
  border: none;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  box-shadow: var(--shadow-sm);
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-secondary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

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

/* Split Container */
.split-container {
  background: var(--surface-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-xl);
  box-shadow: var(--shadow-paper);
  border: 1px solid var(--border-light);
}

.split-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border-light);
}

.split-header h3 {
  font-size: 1.25rem;
  color: var(--text-primary);
  font-weight: 600;
}

.split-controls {
  display: flex;
  gap: var(--space-sm);
}

.btn-select-all, .btn-deselect-all {
  background: var(--surface-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-medium);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.btn-select-all:hover, .btn-deselect-all:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--accent-subtle);
}

.btn-add-pages {
  background: #10b981;
  color: white;
  border: none;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.btn-add-pages:hover {
  background: #059669;
  transform: translateY(-1px);
}

/* Pages Preview */
.pages-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
  max-height: 400px;
  overflow-y: auto;
  padding: var(--space-lg);
  background: var(--surface-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}

.page-item {
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-normal);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: var(--space-md);
  background: var(--surface-primary);
  box-shadow: var(--shadow-sm);
}

.page-item:hover {
  border-color: var(--accent-subtle);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.page-item.selected {
  border-color: var(--accent-primary);
  background: var(--surface-hover);
  box-shadow: var(--shadow-paper);
}

.page-thumbnail {
  width: 100%;
  height: 180px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
  overflow: hidden;
  background: white;
}

.page-thumbnail canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.page-checkbox {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-family: var(--font-serif);
}

.page-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Progress Container */
.progress-container {
  background: var(--surface-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  text-align: center;
  box-shadow: var(--shadow-paper);
  border: 1px solid var(--border-light);
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--surface-tertiary);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: var(--space-lg);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  border-radius: 4px;
  transition: width var(--transition-normal) ease;
  width: 0%;
  box-shadow: 0 1px 2px rgba(212, 165, 116, 0.3);
}

.progress-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-family: var(--font-serif);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(26, 26, 26, 0.8);
  backdrop-filter: blur(8px);
}

.modal-content {
  background-color: var(--surface-primary);
  margin: 5% auto;
  padding: 0;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 800px;
  max-height: 80vh;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  animation: modalSlideIn var(--transition-normal) ease;
}

@keyframes modalSlideIn {
  from { transform: translateY(-30px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.close {
  color: var(--text-muted);
  float: right;
  font-size: 28px;
  font-weight: bold;
  padding: var(--space-lg);
  cursor: pointer;
  transition: color var(--transition-fast);
  font-family: var(--font-serif);
}

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

.modal-header {
  padding: var(--space-xl);
  border-bottom: 1px solid var(--border-light);
  background: var(--surface-secondary);
}

.modal-header h3 {
  margin: 0;
  color: var(--text-primary);
  font-weight: 600;
}

.modal-body {
  padding: var(--space-xl);
  text-align: center;
  max-height: 60vh;
  overflow-y: auto;
}

#preview-canvas {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
  box-shadow: var(--shadow-sm);
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.modal-body::-webkit-scrollbar {
  width: 6px;
}

.modal-body::-webkit-scrollbar-track {
  background: var(--surface-tertiary);
  border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb {
  background: var(--accent-subtle);
  border-radius: 3px;
}

.preview-info p {
  margin: var(--space-sm) 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-family: var(--font-mono);
}

/* Notifications */
.notification-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 2000;
}

.notification {
  background: var(--surface-primary);
  border-radius: var(--radius-md);
  padding: var(--space-lg) var(--space-xl);
  margin-bottom: var(--space-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-width: 320px;
  animation: notificationSlideIn var(--transition-normal) ease;
  border-left: 4px solid;
  font-family: var(--font-serif);
}

@keyframes notificationSlideIn {
  from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.notification.success {
  border-left-color: #8B7355;
}

.notification.error {
  border-left-color: #B85450;
}

.notification.info {
  border-left-color: #D4A574;
}

.notification i {
  font-size: 1.25rem;
}

.notification.success i {
  color: #8B7355;
}

.notification.error i {
  color: #B85450;
}

.notification.info i {
  color: #D4A574;
}

.notification-content {
  flex: 1;
}

.notification-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
  font-size: 0.9rem;
}

.notification-message {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    padding: 0 var(--space-md);
  }
  
  .header-content {
    flex-direction: column;
    gap: var(--space-lg);
  }
  
  .nav {
    width: 100%;
    justify-content: center;
  }
  
  .nav-btn {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
  }
  
  .tool-header h2 {
    font-size: 1.75rem;
  }
  
  .upload-area {
    padding: var(--space-xl) var(--space-lg);
  }
  
  .files-header {
    flex-direction: column;
    gap: var(--space-md);
    align-items: stretch;
  }
  
  .split-header {
    flex-direction: column;
    gap: var(--space-md);
    align-items: stretch;
  }
  
  .split-controls {
    flex-wrap: wrap;
  }
  
  .pages-preview {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--space-md);
    padding: var(--space-md);
  }
  
  .page-thumbnail {
    height: 140px;
  }
  
  .action-buttons {
    flex-direction: column;
  }
  
  .btn {
    width: 100%;
    justify-content: center;
  }
  
  .notification-container {
    left: var(--space-md);
    right: var(--space-md);
  }
  
  .notification {
    min-width: auto;
  }
}

/* Global scrollbar styles */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--accent-subtle);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* Hidden file inputs */
input[type="file"] {
  display: none;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
}

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

/* Paper texture overlay for surfaces */
.surface-primary::before,
.surface-secondary::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10px,
      rgba(212, 165, 116, 0.01) 10px,
      rgba(212, 165, 116, 0.01) 20px
    );
  pointer-events: none;
  opacity: 0.5;
}
