/* OFT Law Custom Design System - Document Scanner */
:root {
  /* OFT Brand Colors */
  --oft-navy: #000043;
  --oft-navy-dark: #000028;
  --oft-navy-light: #0f166b;
  --oft-emerald: #15a387;
  --oft-emerald-hover: #0e7d67;
  --oft-emerald-light: #e8f7f4;
  --oft-gold: #ffc800;

  /* Surfaces & Backgrounds */
  --bg-main: #f4f6f8;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f8fafc;
  --bg-surface-active: #edf2f7;
  --bg-stage: #000030; /* Dark navy canvas stage so white paper documents pop */

  /* Borders & Dividers */
  --border-color: #e2e8f0;
  --border-highlight: #cbd5e1;
  --border-dark: #334155;

  /* Typography */
  --text-main: #000043;
  --text-body: #334155;
  --text-muted: #64748b;
  --text-light: #ffffff;

  /* Primary Theme Accents */
  --primary: #15a387;
  --primary-hover: #0e7d67;
  --primary-glow: rgba(21, 163, 135, 0.25);

  --accent-green: #15a387;
  --accent-red: #dc2626;
  --accent-amber: #d97706;

  /* Corner Pins & Editor */
  --corner-color: #15a387;
  --corner-glow: rgba(21, 163, 135, 0.7);

  /* Geometry & Layout */
  --header-height: 70px;
  --sidebar-width: 290px;
  --right-sidebar-width: 330px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 67, 0.06);
  --shadow-md: 0 4px 14px rgba(0, 0, 67, 0.08);
  --shadow-lg: 0 16px 36px rgba(0, 0, 67, 0.15);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-body);
  height: 100vh;
  overflow: hidden;
  user-select: none;
}

h1, h2, h3, .font-serif {
  font-family: 'DM Serif Display', Georgia, serif;
  font-weight: 400;
  color: var(--text-main);
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.app-header {
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 3px solid var(--oft-emerald);
  box-shadow: 0 2px 10px rgba(0, 0, 67, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
}

.brand-link {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.brand-logo-img {
  height: 34px;
  width: auto;
  display: block;
}

.brand-divider {
  width: 1px;
  height: 28px;
  background-color: #cbd5e1;
  margin: 0 16px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brand-title {
  font-family: 'Open Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--oft-navy);
  line-height: 1.2;
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--oft-emerald);
  text-transform: uppercase;
}

.header-center {
  flex: 1;
  max-width: 520px;
  margin: 0 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.doc-title-input {
  flex: 1;
  min-width: 140px;
  background: #ffffff;
  border: 1px solid var(--border-highlight);
  color: var(--oft-navy);
  font-family: 'Open Sans', sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: all 0.2s ease;
}

.doc-title-input:focus {
  border-color: var(--oft-emerald);
  box-shadow: 0 0 0 3px rgba(21, 163, 135, 0.18);
}

.page-size-select {
  background: #ffffff;
  border: 1px solid var(--border-highlight);
  color: var(--oft-navy);
  font-family: 'Open Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.page-size-select:focus {
  border-color: var(--oft-emerald);
  box-shadow: 0 0 0 3px rgba(21, 163, 135, 0.18);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: 'Open Sans', sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

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

.btn-primary {
  background-color: var(--oft-emerald);
  color: white;
  box-shadow: 0 2px 6px rgba(21, 163, 135, 0.25);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--oft-emerald-hover);
  box-shadow: 0 4px 12px rgba(21, 163, 135, 0.4);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background-color: #ffffff;
  color: var(--oft-navy);
  border-color: var(--border-highlight);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-surface-active);
  border-color: #94a3b8;
}

.btn-danger {
  background-color: #fef2f2;
  color: var(--accent-red);
  border-color: #fca5a5;
}

.btn-danger:hover {
  background-color: var(--accent-red);
  color: white;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-large {
  padding: 13px 28px;
  font-size: 1rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 7px;
  background: #ffffff;
  color: var(--oft-navy);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  background: var(--bg-surface-active);
  color: var(--oft-emerald);
}

.btn-badge {
  background: rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

/* Workspace */
.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Dropzone View */
.dropzone-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: radial-gradient(circle at center, #ffffff 0%, #edf2f7 100%);
}

.dropzone-card {
  max-width: 600px;
  width: 100%;
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  padding: 56px 40px;
  text-align: center;
  background: #ffffff;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropzone-card:hover, .dropzone-card.dragover {
  border-color: var(--oft-emerald);
  background: #f0fdf9;
  transform: translateY(-2px);
  box-shadow: 0 20px 40px rgba(0, 0, 67, 0.12);
}

.dropzone-icon {
  width: 76px;
  height: 76px;
  margin: 0 auto 24px;
  background: var(--oft-emerald-light);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--oft-emerald);
}

.dropzone-icon svg {
  width: 38px;
  height: 38px;
}

.dropzone-card h2 {
  font-size: 2.2rem;
  margin-bottom: 12px;
  color: var(--oft-navy);
}

.dropzone-card p {
  color: var(--text-body);
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 30px;
}

.dropzone-buttons {
  margin-bottom: 24px;
}

.dropzone-hint {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Active Editor Layout */
.editor-layout {
  flex: 1;
  display: flex;
  width: 100%;
  height: 100%;
}

/* Left Sidebar: Pages */
.sidebar-pages {
  width: var(--sidebar-width);
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 2px 0 8px rgba(0, 0, 67, 0.03);
}

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

.sidebar-header h3 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.3rem;
  color: var(--oft-navy);
}

.thumbnails-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}

.page-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.page-card:hover {
  border-color: var(--border-highlight);
  box-shadow: var(--shadow-md);
}

.page-card.active {
  border: 2px solid var(--oft-emerald);
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(21, 163, 135, 0.2);
}

.page-thumb-wrapper {
  width: 60px;
  height: 80px;
  background: #f1f5f9;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
}

.page-thumb-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page-info {
  flex: 1;
  min-width: 0;
}

.page-number {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--oft-navy);
  margin-bottom: 2px;
}

.page-card.active .page-number {
  color: var(--oft-emerald);
}

.page-filename {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-card-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.page-card-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.page-card-actions button:hover {
  color: var(--oft-navy);
  background: var(--bg-surface-active);
}

/* Center Stage */
.center-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-stage);
  position: relative;
  overflow: hidden;
}

.stage-toolbar {
  height: 54px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 67, 0.04);
}

.view-switch {
  display: flex;
  background: #f1f5f9;
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'Open Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn svg {
  width: 15px;
  height: 15px;
}

.tab-btn.active {
  background: var(--oft-emerald);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(21, 163, 135, 0.3);
}

.stage-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Viewport and Canvas */
.canvas-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  padding: 24px;
  background: radial-gradient(circle at center, #00004d 0%, #000024 100%);
}

.editor-canvas-wrapper {
  position: relative;
  display: inline-block;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.7);
  border-radius: 4px;
  overflow: visible;
}

#editorCanvas {
  display: block;
  cursor: crosshair;
  background-color: #000000;
  border-radius: 4px;
}

/* Magnifier Loupe */
.magnifier-loupe {
  position: absolute;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  border: 3px solid var(--oft-emerald);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.8), 0 0 16px var(--corner-glow);
  pointer-events: none;
  overflow: hidden;
  display: none;
  background: #000;
  z-index: 100;
  transform: translate(-50%, -100%) translateY(-25px);
}

#loupeCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Preview Image */
.preview-wrapper {
  max-width: 90%;
  max-height: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: transparent;
}

#previewImage {
  max-width: 100%;
  max-height: calc(100vh - 190px);
  object-fit: contain;
  display: block;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.8);
  background: white;
  border-radius: 4px;
}

.preview-loading {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 67, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: white;
  font-weight: 600;
  border-radius: 4px;
}

.stage-footer {
  height: 38px;
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 20px;
}

.tip-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tip-text svg {
  width: 15px;
  height: 15px;
  color: var(--oft-emerald);
}

/* Right Sidebar: Controls */
.sidebar-controls {
  width: var(--right-sidebar-width);
  background: #ffffff;
  border-left: 1px solid var(--border-color);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  box-shadow: -2px 0 8px rgba(0, 0, 67, 0.03);
}

.control-group h3 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.25rem;
  color: var(--oft-navy);
  margin-bottom: 12px;
}

.filter-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filter-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-card:hover {
  border-color: var(--border-highlight);
  background: #ffffff;
}

.filter-card input[type="radio"] {
  margin-top: 3px;
  accent-color: var(--oft-emerald);
}

.filter-card:has(input:checked) {
  border: 2px solid var(--oft-emerald);
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(21, 163, 135, 0.15);
}

.filter-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--oft-navy);
  margin-bottom: 3px;
}

.filter-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--oft-navy);
  margin-bottom: 10px;
}

#sensitivityValue {
  color: var(--oft-emerald);
  font-size: 0.8rem;
}

.slider {
  width: 100%;
  accent-color: var(--oft-emerald);
  height: 6px;
  background: #cbd5e1;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.button-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.page-manage-group {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--border-color);
}

/* Spinner & Modals */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(21, 163, 135, 0.2);
  border-top-color: var(--oft-emerald);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner.large {
  width: 48px;
  height: 48px;
  border-width: 4px;
  margin: 0 auto 18px;
}

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

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 67, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 40px 48px;
  text-align: center;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
}

.modal-card h3 {
  font-size: 1.6rem;
  color: var(--oft-navy);
  margin-bottom: 10px;
}

.modal-card p {
  color: var(--text-body);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
  .sidebar-pages { width: 230px; }
  .sidebar-controls { width: 270px; }
}

@media (max-width: 768px) {
  .editor-layout { flex-direction: column; }
  .sidebar-pages { width: 100%; height: 120px; flex-direction: row; }
  .thumbnails-list { flex-direction: row; }
  .sidebar-controls { width: 100%; height: auto; }
}
