/* ══════════════════════════════════════════════════════════
   PDF Splitter – Web Edition (Premium Dark UI)
   ══════════════════════════════════════════════════════════ */

:root {
  --bg-base: #09090b;
  --bg-card: #131316;
  --bg-card-hover: #1a1a1f;
  --bg-input: #18181b;
  --border: #27272a;
  --border-light: #3f3f46;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #7c3aed;
  --accent-light: #a78bfa;
  --accent-glow: rgba(124, 58, 237, 0.25);
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 180ms ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --sidebar-width: 300px;
}

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

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
  user-select: none;
}

/* ── Header ──────────────────────────────────────────────── */

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 18px;
  background: #0c0c0f;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-icon {
  width: 20px;
  height: 20px;
  color: var(--accent-light);
}

#header h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

/* ── Main Layout ─────────────────────────────────────────── */

#app {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */

#sidebar {
  width: var(--sidebar-width);
  min-width: 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

#sidebar::-webkit-scrollbar { width: 5px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 10px; }

/* ── Resize Handle ───────────────────────────────────────── */

.resize-handle {
  width: 5px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  position: relative;
  transition: background 150ms ease;
  z-index: 10;
}
.resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 32px;
  border-radius: 2px;
  background: var(--border-light);
  opacity: 0;
  transition: opacity 150ms ease;
}
.resize-handle:hover,
.resize-handle.dragging {
  background: var(--accent);
}
.resize-handle:hover::after,
.resize-handle.dragging::after {
  opacity: 1;
}

body.resizing {
  cursor: col-resize !important;
  user-select: none !important;
}
body.resizing * {
  cursor: col-resize !important;
}

/* ── Cards ───────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  transition: border-color var(--transition);
}
.card:hover {
  border-color: var(--border-light);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.card-header .card-label {
  margin-bottom: 0;
}

.depth-control {
  display: flex;
  align-items: center;
  gap: 6px;
}
.depth-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}
.depth-select {
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 11px;
  font-family: var(--font);
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}
.depth-select:focus {
  border-color: var(--accent);
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn-primary {
  width: 100%;
  padding: 10px 16px;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition);
}
.btn-primary svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary:hover {
  border-color: var(--accent);
  color: var(--accent-light);
  background: rgba(124, 58, 237, 0.06);
}

.btn-accent {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  color: white;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition);
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-accent svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-accent:hover:not(:disabled) {
  filter: brightness(1.15);
  box-shadow: 0 4px 20px var(--accent-glow);
  transform: translateY(-1px);
}
.btn-accent:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-accent:active:not(:disabled) {
  transform: translateY(0);
}

/* ── File Info ───────────────────────────────────────────── */

.file-info {
  margin-top: 10px;
  padding: 10px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.file-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-all;
  line-height: 1.4;
}
.file-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Chapter List ────────────────────────────────────────── */

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 45vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}
.chapter-list::-webkit-scrollbar { width: 4px; }
.chapter-list::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 10px; }

.chapter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.chapter-item:hover { background: var(--bg-card-hover); }

.chapter-item input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-light);
  border-radius: 4px;
  background: var(--bg-input);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: all var(--transition);
}
.chapter-item input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.chapter-item input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 2px; left: 5px;
  width: 4px; height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.chapter-title {
  font-size: 12.5px;
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

.chapter-pages {
  font-size: 10.5px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ── Chapter Search ──────────────────────────────────────── */

.chapter-search-wrap {
  position: relative;
  margin-bottom: 6px;
}
.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  pointer-events: none;
}
.chapter-search {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 12.5px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.chapter-search::placeholder { color: var(--text-muted); }
.chapter-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.chapter-item.search-hidden {
  display: none !important;
}

.chapter-title mark {
  background: rgba(124, 58, 237, 0.35);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Text Input ──────────────────────────────────────────── */

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.text-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.text-input::placeholder { color: var(--text-muted); }
.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Action Card ─────────────────────────────────────────── */

.action-card {
  margin-top: auto;
}

.page-count-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.count-label { font-size: 12px; color: var(--text-secondary); }
.count-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-light);
  font-variant-numeric: tabular-nums;
}

/* ── Status Messages ─────────────────────────────────────── */

.status-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 0;
}

/* ── Spinner ─────────────────────────────────────────────── */

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent-light);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner.large {
  width: 32px; height: 32px;
  border-width: 3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Preview Panel ───────────────────────────────────────── */

#preview {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  background: #0c0c0f;
}

.preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 14px;
  color: var(--text-muted);
}
.placeholder-icon { width: 56px; height: 56px; opacity: 0.3; }
.preview-placeholder p { font-size: 13px; }

.preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 18px;
  overflow-y: auto;
  width: 100%;
  align-content: flex-start;
  justify-content: center;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}
.preview-grid::-webkit-scrollbar { width: 6px; }
.preview-grid::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 10px; }

.page-thumb {
  position: relative;
  background: white;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  transition: transform var(--transition), box-shadow var(--transition);
  cursor: pointer;
}
.page-thumb:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
}
.page-thumb canvas {
  display: block;
  width: 100%;
  height: auto;
}
.page-thumb-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 3px 0;
  font-size: 10.5px;
  font-weight: 600;
  color: white;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
}

/* ── Toast ────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 40000;
  pointer-events: none;
}

.toast {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  color: white;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  animation: toastIn 300ms ease forwards;
  pointer-events: auto;
}
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
.toast.info    { background: #2563eb; }

.toast.fade-out {
  animation: toastOut 250ms ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(8px); }
}

/* ── Lightbox ─────────────────────────────────────────────── */

.lightbox {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: lbFadeIn 200ms ease;
}
.lightbox.hidden { display: none !important; }

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
}

.lightbox-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 94%;
  max-height: 94%;
  z-index: 1;
}

.lightbox-close {
  position: absolute;
  top: -36px;
  right: -4px;
  width: 30px;
  height: 30px;
  border: none;
  background: rgba(255,255,255,0.1);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  z-index: 2;
}
.lightbox-close svg { width: 16px; height: 16px; }
.lightbox-close:hover { background: rgba(255,255,255,0.2); }

.lightbox-page-info {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  margin-bottom: 10px;
  text-align: center;
}

.lightbox-canvas-wrap {
  overflow: auto;
  max-height: calc(100vh - 140px);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  background: white;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}
.lightbox-canvas-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  transform: translateY(-50%);
}

.lightbox-nav-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255,255,255,0.1);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  transition: background var(--transition), transform var(--transition);
}
.lightbox-nav-btn svg { width: 20px; height: 20px; }
.lightbox-nav-btn:hover {
  background: rgba(255,255,255,0.2);
  transform: scale(1.1);
}
.lightbox-nav-btn:disabled { opacity: 0.2; cursor: default; }
.lightbox-nav-btn:disabled:hover { background: rgba(255,255,255,0.1); transform: none; }

@keyframes lbFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Drop Overlay ─────────────────────────────────────────── */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  background: rgba(9, 9, 11, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: lbFadeIn 150ms ease;
}
.drop-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 64px;
  border: 2px dashed var(--accent-light);
  border-radius: 16px;
  color: var(--accent-light);
}
.drop-icon {
  width: 56px;
  height: 56px;
  animation: dropBounce 1s ease infinite;
}
.drop-overlay-content p {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
@keyframes dropBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* ── Upload Overlay ──────────────────────────────────────── */

.upload-overlay {
  position: fixed;
  inset: 0;
  z-index: 20001;
  background: rgba(9, 9, 11, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-secondary);
}
.upload-overlay-content p {
  font-size: 14px;
  font-weight: 500;
}

/* ── Login Overlay ───────────────────────────────────────── */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 30000;
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  animation: lbFadeIn 300ms ease;
}
.login-icon {
  width: 48px;
  height: 48px;
  color: var(--accent-light);
  margin-bottom: 16px;
}
.login-box h2 {
  font-size: 20px;
  margin-bottom: 8px;
}
.login-box p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}
#login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#login-form input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}
#login-form input:focus {
  border-color: var(--accent);
}

/* ── Admin Panel ─────────────────────────────────────────── */

.role-user .admin-only {
  display: none !important;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--bg-card-hover); color: var(--accent-light); }

.admin-panel {
  position: relative;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 10;
  padding: 24px;
}
.admin-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.admin-close:hover { background: var(--bg-input); color: white; }

.admin-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}
.admin-section {
  margin-bottom: 24px;
}
.admin-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.admin-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.4;
}
.admin-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  background: var(--bg-input);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.admin-stats-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 6px;
}
.admin-stats-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.admin-actions {
  display: flex;
  gap: 12px;
}
.admin-password-form {
  display: flex;
  gap: 12px;
}
.admin-password-form input {
  flex: 1;
}
.admin-password-form button {
  width: auto;
}

/* ── Utilities ───────────────────────────────────────────── */

.hidden { display: none !important; }
