:root {
  --bg: #0f0f12;
  --surface: #18181d;
  --border: #2a2a32;
  --text: #e8e8ed;
  --text-muted: #8b8b9a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #22c55e;
  --error: #ef4444;
  --radius: 12px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --page-thumb-zoom: 1;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  /* Wider layout so tools (especially Organize PDF) use full screen width */
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
}
.header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
  text-decoration: none;
}
.tagline {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Main */
.main {
  padding: 2.5rem 0 4rem;
}

.hero {
  text-align: center;
  margin-bottom: 2rem;
}
.hero h1 {
  font-size: 1.875rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.subtitle {
  color: var(--text-muted);
  font-size: 1rem;
}

/* Upload zone */
.upload-section {
  margin-bottom: 2rem;
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
  padding: 0 20px;
  box-sizing: border-box;
}

.upload-zone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  width: 100%;
}
.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}
.upload-zone.error {
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.06);
}

.upload-icon {
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.upload-zone:hover .upload-icon,
.upload-zone.dragover .upload-icon {
  color: var(--accent);
}

.upload-text {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}
.upload-text strong {
  color: var(--accent);
}
.upload-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* File list */
.file-list {
  margin-top: 1rem;
  min-height: 0;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}
.file-item .name {
  flex: 1;
  font-size: 0.9375rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-item .size {
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.file-item .remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 6px;
  line-height: 1;
}
.file-item .remove:hover {
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
}

/* Actions */
.actions {
  margin-top: 1.5rem;
}
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.875rem 1.5rem;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:not(:disabled):hover {
  background: var(--accent-hover);
}
.btn.loading .btn-text {
  visibility: hidden;
}
.btn.loading .btn-loader {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.privacy-note {
  margin-top: 1rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
}

/* Info section */
.info-section {
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.info-section h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.steps {
  padding-left: 1.25rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
}
.steps li {
  margin-bottom: 0.5rem;
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  text-align: center;
}
.footer p {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 500;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.3s, opacity 0.3s, visibility 0.3s;
  z-index: 1000;
  max-width: 90vw;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  visibility: visible;
}
.toast.error {
  background: var(--error);
  color: white;
}
.toast.success {
  background: var(--success);
  color: white;
}

.coming-soon-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 2rem 1rem;
  max-width: 400px;
  margin: 0 auto;
}

/* Edit PDF */
.edit-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0;
}
.edit-toolbar .edit-toolbar-spacer {
  flex: 1;
}
.edit-inline-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.edit-inline-label input[type="number"] {
  width: 56px;
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #111119;
  color: var(--text);
}
.edit-inline-label input[type="color"] {
  width: 32px;
  height: 24px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
}
.edit-toolbar [data-edit-tool].active {
  outline: 2px solid var(--accent);
}
.edit-viewer {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.edit-page-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.edit-page-controls .page-nav {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #1f1f29;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.edit-page-controls .page-nav:hover {
  background: #2a2a3a;
}
.edit-page-controls .page-info {
  min-width: 64px;
  text-align: center;
}
.edit-canvas-wrap {
  background: #111119;
  border-radius: 10px;
  padding: 0.75rem;
  display: inline-block;
  max-width: 100%;
  overflow: auto;
}
#editCanvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Inline text editor over PDF */
.inline-editor {
  position: absolute;
  min-width: 120px;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  resize: both;
  box-sizing: border-box;
  z-index: 50;
}

/* Organize PDF */
.organize-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1rem 0 1.5rem;
  width: 100%;
}
.organize-toolbar .toolbar-left,
.organize-toolbar .toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.btn.btn-secondary {
  background: #272733;
  color: var(--text);
}
.btn.btn-secondary:hover {
  background: #323248;
}
.btn-group {
  position: relative;
}
.btn-group .menu-toggle {
  white-space: nowrap;
}
.menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  min-width: 160px;
  background: #191922;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 12px 30px rgba(0,0,0,0.5);
  padding: 4px 0;
  display: none;
  z-index: 20;
}
.menu.open {
  display: block;
}
.menu-item {
  width: 100%;
  padding: 0.35rem 0.75rem;
  background: none;
  border: none;
  text-align: left;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}
.menu-item:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}
.pages-grid {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.5rem;
  margin-top: 1rem;
}
.page-thumb {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem;
  cursor: grab;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.page-thumb.dragging {
  opacity: 0.6;
}
.page-canvas-wrap {
  background: #111119;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.35rem;
  aspect-ratio: 1 / 1;
  transform: scale(var(--page-thumb-zoom));
  transform-origin: top center;
}
.page-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}
.page-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.page-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
}
.page-remove:hover {
  color: var(--error);
  background: rgba(239, 68, 68, 0.12);
}

.zoom-controls {
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.zoom-label {
  margin-right: 0.25rem;
}
.zoom-btn {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #1f1f29;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}
.zoom-btn:hover {
  background: #2a2a3a;
}
.zoom-value {
  min-width: 44px;
  text-align: center;
}
