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

:root {
  --bg: #0f172a;
  --card: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #263244;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --warning: #f59e0b;
  --success: #22c55e;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width 0.25s ease, border-color 0.25s ease;
}

#sidebar.collapsed {
  width: 0;
  border-right-color: transparent;
}

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

.sidebar-header h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

#upload-zone {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}

#upload-zone.open {
  max-height: 140px;
}

.drop-area {
  margin: 12px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 13px;
}

.drop-area:hover,
.drop-area.drag-over {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.06);
  color: var(--text);
}

.drop-area span {
  display: block;
  font-size: 22px;
  margin-bottom: 4px;
}

#pdf-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#pdf-list::-webkit-scrollbar {
  width: 5px;
}

#pdf-list::-webkit-scrollbar-track {
  background: transparent;
}

#pdf-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.pdf-item {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  margin-bottom: 6px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.pdf-item:hover {
  border-color: #3d5275;
}

.pdf-item.active {
  border-color: var(--primary);
}

.pdf-item-body {
  padding: 10px 12px 8px;
  cursor: pointer;
}

.pdf-item-title {
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.pdf-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.page-badge {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 5px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 500;
}

.pdf-item-actions {
  display: flex;
  border-top: 1px solid var(--border);
}

.item-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s, color 0.15s;
}

.item-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.item-btn.del:hover {
  background: rgba(220, 38, 38, 0.1);
  color: #fca5a5;
}

.item-btn + .item-btn {
  border-left: 1px solid var(--border);
}

.rename-input {
  width: 100%;
  background: #0b1220;
  border: 1px solid var(--primary);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 7px;
  font-size: 13px;
  outline: none;
}

.empty-list {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 32px 16px;
}

/* ── Reader ── */
#reader {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

#btn-toggle-bar {
  position: absolute;
  top: 7px;
  right: 8px;
  z-index: 20;
}

.reader-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-right: 44px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
  flex-wrap: wrap;
  overflow: hidden;
  max-height: 80px;
  transition: max-height 0.2s ease, padding-top 0.2s ease, padding-bottom 0.2s ease, border-color 0.2s ease;
}

.reader-bar.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-bottom-color: transparent;
}

.reader-bar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-info {
  color: var(--muted);
  font-size: 13px;
  min-width: 70px;
}

#canvas-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
  background: #080e1a;
}

#canvas-wrap::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

#canvas-wrap::-webkit-scrollbar-track {
  background: #080e1a;
}

#canvas-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

#pdf-canvas {
  display: block;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.5);
  max-width: 100%;
}

#reader-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
}

#reader-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost:not(:disabled):hover {
  background: rgba(255, 255, 255, 0.05);
}

.btn-icon {
  padding: 6px 9px;
}

/* ── Bar separator ── */
.bar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}

.page-input {
  width: 52px;
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 13px;
  text-align: center;
  outline: none;
}

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

/* ── Error banner ── */
#error-banner {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(220, 38, 38, 0.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 999;
  max-width: 480px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  transition: opacity 0.3s;
}

/* ── Loading overlay on canvas ── */
#canvas-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  background: #080e1a;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  #sidebar {
    width: 100%;
    height: 42vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .reader-bar {
    gap: 6px;
  }
}
