/* CSS Variables */
:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --success-color: #22c55e;
  --error-color: #ef4444;
  --header-height: 64px;
  --footer-height: 48px;
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Base */
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-color);
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary-color);
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 6px;
  transition: all 0.2s;
}

.nav-link:hover, .nav-link.active {
  color: var(--primary-color);
  background: rgba(37, 99, 235, 0.1);
}

/* Main Content */
.main {
  flex: 1;
  margin-top: var(--header-height);
  margin-bottom: var(--footer-height);
  padding: 24px;
}

/* Footer */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--footer-height);
  background: var(--card-bg);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 12px;
}

/* Loading State */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
  color: var(--text-secondary);
}

/* Library Page */
.library-page {
  max-width: 1400px;
  margin: 0 auto;
}

.search-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.search-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--primary-color);
}

.category-filter {
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 14px;
  background: var(--card-bg);
  cursor: pointer;
  min-width: 200px;
}

.results-info {
  margin-bottom: 16px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* SOP Table */
.sop-table-container {
  background: var(--card-bg);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  overflow: hidden;
}

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

.sop-table th,
.sop-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.sop-table th {
  background: #f1f5f9;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.sop-table tbody tr:hover {
  background: #f8fafc;
}

.sop-table tbody tr:last-child td {
  border-bottom: none;
}

.col-id { width: 100px; }
.col-version { width: 80px; }
.col-date { width: 120px; }
.col-category { width: 150px; }
.col-actions { width: 100px; text-align: center; }

.view-btn {
  padding: 6px 16px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.view-btn:hover {
  background: var(--primary-hover);
}

.view-btn:disabled {
  background: var(--text-secondary);
  cursor: not-allowed;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
}

.page-btn {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

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

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

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

/* Viewer Page */
.viewer-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - var(--footer-height) - 48px);
}

.viewer-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.back-link {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}

.back-link:hover {
  text-decoration: underline;
}

.sop-info {
  flex: 1;
}

.sop-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.sop-meta {
  display: flex;
  gap: 16px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* PDF Toolbar */
.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #f1f5f9;
  border-radius: 8px;
  margin-bottom: 16px;
}

.toolbar-btn {
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.toolbar-btn:hover:not(:disabled) {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

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

.toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--border-color);
  margin: 0 8px;
}

.zoom-level {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 50px;
  text-align: center;
}

/* PDF Container */
.pdf-container {
  flex: 1;
  overflow: auto;
  background: #525659;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  padding: 16px;
  position: relative;
}

#pdf-canvas {
  background: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  /* Disable text selection */
  user-select: none;
  -webkit-user-select: none;
}

.pdf-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: white;
}

.pdf-loading.hidden {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Error Page */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  text-align: center;
}

.error-page h2 {
  color: var(--error-color);
  margin-bottom: 16px;
}

.error-page p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.btn {
  display: inline-block;
  padding: 10px 20px;
  background: var(--primary-color);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-weight: 500;
  transition: background 0.2s;
}

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

/* Category Tags */
.category-tag {
  display: inline-block;
  padding: 2px 8px;
  background: #e0f2fe;
  color: #0369a1;
  border-radius: 4px;
  font-size: 12px;
}

/* Responsive */
@media (max-width: 768px) {
  .search-bar {
    flex-direction: column;
  }

  .category-filter {
    min-width: 100%;
  }

  .sop-table {
    font-size: 13px;
  }

  .col-version,
  .col-category {
    display: none;
  }

  .viewer-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .pdf-toolbar {
    flex-wrap: wrap;
    justify-content: center;
  }
}
