/* ========================================
   PDForge — Core Layout & Theme
   ======================================== */

:root {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-elevated: #232733;
  --bg-hover: #2a2e3b;
  --border: #2e3345;
  --border-light: #3a3f52;
  --text: #e4e6ed;
  --text-dim: #8b8fa3;
  --text-muted: #5c6078;
  --accent: #4f8ff7;
  --accent-hover: #6ba0f9;
  --accent-dim: rgba(79, 143, 247, 0.12);
  --sig-accent: #e5a842;
  --sig-dim: rgba(229, 168, 66, 0.12);
  --danger: #e55c5c;
  --danger-dim: rgba(229, 92, 92, 0.12);
  --success: #4caf7d;
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --transition: 150ms ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 140px;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 140px;
  justify-content: flex-end;
}

/* Steps nav */
.steps {
  display: flex;
  gap: 2px;
}

.step {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all var(--transition);
}

.step:hover {
  color: var(--text-dim);
  background: var(--bg-hover);
}

.step.active {
  color: var(--text);
  background: var(--bg-elevated);
}

.step.completed {
  color: var(--success);
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  background: var(--border);
  color: var(--text-dim);
}

.step.active .step-num {
  background: var(--accent);
  color: #fff;
}

.step.completed .step-num {
  background: var(--success);
  color: #fff;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

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

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

.btn-secondary {
  background: transparent;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 32px;
  font-size: 15px;
  border-radius: var(--radius-lg);
}

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 12px;
  font-family: var(--font);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ---- Workspace ---- */
.workspace {
  display: flex;
  height: calc(100vh - 48px - 36px);
  overflow: hidden;
}

/* ---- Page Sidebar ---- */
.page-sidebar {
  width: 120px;
  min-width: 120px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.page-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.page-thumb {
  width: 100%;
  aspect-ratio: 8.5 / 11;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  background: #fff;
}

.page-thumb canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.page-thumb.active {
  border-color: var(--accent);
}

.page-thumb-num {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 0 4px;
  border-radius: 2px;
}

/* ---- Properties Panel ---- */
.props-panel {
  width: 240px;
  min-width: 240px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.props-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.props-empty {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  margin-top: 24px;
}

.prop-group {
  margin-bottom: 16px;
}

.prop-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.prop-input {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
}

.prop-input:focus {
  border-color: var(--accent);
}

.prop-row {
  display: flex;
  gap: 8px;
}

.prop-row .prop-group {
  flex: 1;
}

.prop-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.prop-check input {
  accent-color: var(--accent);
}

select.prop-input {
  cursor: pointer;
}

/* ---- Bottom bar ---- */
.bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 36px;
  padding: 0 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  user-select: none;
}

.bottombar-left,
.bottombar-center,
.bottombar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-label {
  min-width: 40px;
  text-align: center;
}

#pageIndicator {
  min-width: 80px;
  text-align: center;
}

/* ---- Screens ---- */
.editor-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  overflow: hidden;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ---- Upload zone ---- */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 480px;
  max-width: 90%;
  padding: 60px 40px;
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.upload-zone h2 {
  font-size: 18px;
  font-weight: 600;
}

.upload-zone p {
  color: var(--text-dim);
  font-size: 13px;
}

/* ---- Detect screen ---- */
.detect-panel {
  text-align: center;
  max-width: 640px;
  padding: 24px;
}

.detect-panel h2 {
  margin-bottom: 8px;
}

.detect-panel > p {
  color: var(--text-dim);
  margin-bottom: 32px;
}

.detect-options {
  display: flex;
  gap: 16px;
}

.detect-option {
  flex: 1;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  transition: border-color var(--transition);
}

.detect-option:hover {
  border-color: var(--border-light);
}

.detect-icon {
  color: var(--accent);
}

.detect-option h3 {
  font-size: 15px;
}

.detect-option p {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

.api-key-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.api-key-row input {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
}

.api-key-row input:focus {
  border-color: var(--accent);
}

.detect-progress {
  margin-top: 32px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 300ms ease;
}

/* ---- Export screen ---- */
.export-panel {
  text-align: center;
  max-width: 480px;
  padding: 24px;
}

.export-panel h2 {
  margin-bottom: 8px;
}

.export-panel > p {
  color: var(--text-dim);
  margin-bottom: 32px;
}

.export-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.export-opt {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}

.export-opt:hover {
  border-color: var(--border-light);
}

.export-opt input:checked + .export-opt-label {
  color: var(--accent);
}

.export-opt input {
  accent-color: var(--accent);
}

.export-opt-label strong {
  display: block;
  font-size: 14px;
}

.export-opt-label small {
  color: var(--text-dim);
  font-size: 12px;
}

.export-actions {
  margin-bottom: 32px;
}

.export-template {
  text-align: left;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.export-template h3 {
  font-size: 14px;
  margin-bottom: 4px;
}

.export-template p {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.template-row {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.template-row input {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}

.template-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.template-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.template-item-actions {
  display: flex;
  gap: 4px;
}

/* ---- Audit follow-ups: restore row, offline detect, upload hint ---- */
.upload-hint {
  font-size: 12px !important;
  opacity: 0.7;
}

.restore-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.restore-row small {
  color: var(--text-dim);
  font-size: 12px;
}

.detect-all-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.detect-offline {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.detect-offline h3 {
  font-size: 14px;
  margin-bottom: 4px;
}

.detect-offline p {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.detect-offline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#detectCancelBtn {
  margin-top: 10px;
}

/* ---- Sign screen ---- */
.sign-panel {
  text-align: center;
  max-width: 480px;
  padding: 24px;
}

.sign-panel h2 {
  margin-bottom: 8px;
}

.sig-field-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 24px 0;
}

.sig-field-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
}

.sig-field-item.signed {
  border-color: var(--success);
}

.sign-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ---- Modals ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-sm {
  width: 400px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.modal-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  border-bottom: 2px solid transparent;
}

.modal-tab:hover {
  color: var(--text);
}

.modal-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.modal-body {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ---- Context Menu ---- */
.context-menu {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 900;
  min-width: 160px;
}

.context-menu[hidden] {
  display: none !important;
}

.ctx-item {
  display: block;
  width: 100%;
  padding: 6px 12px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.ctx-item:hover {
  background: var(--bg-hover);
}

.ctx-danger {
  color: var(--danger);
}

.ctx-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  bottom: 48px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
  color: var(--text);
  pointer-events: auto;
  animation: toast-in 200ms ease;
  max-width: 320px;
}

.toast.error {
  border-color: var(--danger);
  color: var(--danger);
}

.toast.success {
  border-color: var(--success);
  color: var(--success);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Settings ---- */
.setting-group {
  margin-bottom: 16px;
}

.setting-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.setting-group small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.setting-group select,
.setting-group input[type="number"] {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}
