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

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-secondary: #6b7280;
  --primary: #F04E3C;
  --primary-hover: #d9432f;
  --primary-light: #fef2f1;
  --danger: #ef4444;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
  --transition: 0.2s ease;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Header */
header {
  background: #1a1a1a;
  border-bottom: none;
  padding: 2rem 0;
}

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

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.subtitle {
  color: #9ca3af;
  margin-top: 0.25rem;
  font-size: 0.95rem;
}

/* Main */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem;
}

/* Upload */
.upload-section {
  margin-bottom: 2.5rem;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-icon {
  width: 48px;
  height: 48px;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.drop-zone-content p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.browse-link {
  color: var(--primary);
  font-weight: 500;
  text-decoration: underline;
  cursor: pointer;
}

.drop-hint {
  font-size: 0.8rem !important;
  margin-top: 0.5rem;
  opacity: 0.6;
}

.upload-progress {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

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

.progress-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Grid */
.grid-header {
  display: none;
}

.pdf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}

/* Card */
.pdf-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.pdf-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.pdf-card-thumbnail {
  width: 100%;
  height: 180px;
  background: #f1f3f5;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.pdf-card-thumbnail canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.pdf-card-info {
  padding: 1rem;
}

.pdf-card-name {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pdf-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Language badge on thumbnail */
.lang-badge {
  position: absolute;
  bottom: 0.5rem;
  left: 0.5rem;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  z-index: 2;
  backdrop-filter: blur(4px);
}

/* Card actions row */
.pdf-card-actions {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.3rem;
  opacity: 0;
  transition: opacity var(--transition);
}

.pdf-card:hover .pdf-card-actions {
  opacity: 1;
}

.pdf-card-lang-edit {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  border: none;
  background: rgba(0,0,0,0.5);
  color: white;
  cursor: pointer;
  font-size: 0.7rem;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}

.pdf-card-lang-edit:hover {
  background: rgba(0,0,0,0.75);
}

.pdf-card-delete {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.pdf-card-delete:hover {
  background: var(--danger);
}

/* Language select in modal */
.lang-select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.lang-modal-file {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Empty state */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.95rem;
}

.empty-hint {
  font-size: 0.85rem !important;
  opacity: 0.6;
  margin-top: 0.25rem;
}

/* ========== READER ========== */
#reader-view {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #1a1d23;
}

.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: #22252d;
  border-bottom: 1px solid #2e3138;
  z-index: 10;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: 1px solid #3a3d45;
  border-radius: 8px;
  color: #d1d5db;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: all var(--transition);
}

.toolbar-btn:hover {
  background: #2e3138;
  color: white;
}

.toolbar-btn svg {
  width: 18px;
  height: 18px;
}

.toolbar-title {
  color: #d1d5db;
  font-size: 0.9rem;
  font-weight: 500;
  max-width: 40%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-controls {
  display: flex;
  gap: 0.5rem;
}

/* Reader container */
.reader-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 1rem;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.flipbook {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* StPageFlip page content */
.page-content {
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.page-content img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  -webkit-touch-callout: none;
  pointer-events: none;
}

/* Nav buttons */
.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  z-index: 5;
}

.nav-btn:hover {
  background: rgba(255,255,255,0.2);
}

.nav-btn:disabled {
  opacity: 0.2;
  cursor: default;
}

.nav-btn svg {
  width: 24px;
  height: 24px;
}

.nav-prev { left: 1rem; }
.nav-next { right: 1rem; }

/* Footer */
.reader-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: #22252d;
  border-top: 1px solid #2e3138;
}

#page-info {
  color: #9ca3af;
  font-size: 0.85rem;
  white-space: nowrap;
  min-width: 100px;
  text-align: center;
}

.page-slider {
  width: 300px;
  max-width: 40vw;
  accent-color: var(--primary);
}

/* Responsive */
@media (max-width: 768px) {
  main { padding: 1rem; }
  .drop-zone { padding: 2rem 1rem; }
  .pdf-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .toolbar-title { display: none; }
  .toolbar-btn span { display: none; }
  .nav-btn { width: 36px; height: 36px; }
  .page-slider { max-width: 50vw; }
  .header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .header-actions {
    align-self: stretch;
  }
  .btn-home, .admin-btn {
    flex: 1;
    justify-content: center;
  }
  /* Always show admin actions on mobile (no hover) */
  .pdf-card-actions {
    opacity: 1;
  }
}

/* Admin button */
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.btn-home {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  text-decoration: none;
  transition: all var(--transition);
}

.btn-home:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.admin-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: all var(--transition);
}

.admin-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.admin-btn.logged-in {
  border-color: var(--primary);
  background: rgba(240, 78, 60, 0.15);
  color: var(--primary);
}

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

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  width: 360px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
}

.modal input[type="password"] {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.modal input[type="password"]:focus {
  border-color: var(--primary);
}

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

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

.btn-primary {
  padding: 0.55rem 1.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition);
}

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

.btn-secondary {
  padding: 0.55rem 1.25rem;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

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

/* ========== DETAIL VIEW ========== */
#detail-view {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #1a1d23;
}

.detail-container {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  text-align: center;
}

.detail-page-wrapper {
  position: relative;
  display: inline-block;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  margin: 0 auto;
}

#detail-canvas {
  display: block;
}

.detail-text-layer {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  opacity: 1;
  line-height: 1;
}

.detail-text-layer > span {
  position: absolute;
  white-space: pre;
  color: transparent;
  cursor: text;
  user-select: text;
  transform-origin: 0% 0%;
}

.detail-text-layer > span::selection {
  background: rgba(240, 78, 60, 0.35);
  color: transparent;
}

.detail-text-layer > span::-moz-selection {
  background: rgba(240, 78, 60, 0.35);
  color: transparent;
}

.detail-text-layer br {
  display: none;
}

.zoom-level {
  color: #9ca3af;
  font-size: 0.85rem;
  min-width: 50px;
  text-align: center;
  user-select: none;
}

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

/* Loading spinner */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #3a3d45;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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