/* ===== CSS Custom Properties ===== */
:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-bg: #f9fafb;
  --color-surface: #ffffff;
  --color-text: #111827;
  --color-text-secondary: #6b7280;
  --color-border: #e5e7eb;
  --color-border-hover: #d1d5db;
  --color-error: #ef4444;
  --color-success: #22c55e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== App Header ===== */
.app-header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}

.app-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

.app-header .tagline {
  color: var(--color-text-secondary);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

/* ===== Main Container ===== */
.app-main {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
}

.section {
  margin-top: 1.5rem;
}

.section h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--color-text);
}

/* ===== Dropzone ===== */
.dropzone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition-normal), background var(--transition-normal), box-shadow var(--transition-normal);
  outline: none;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: var(--shadow-md);
}

.dropzone.dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: var(--shadow-lg);
  transform: scale(1.01);
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.dropzone-icon {
  font-size: 2.5rem;
  line-height: 1;
}

.dropzone-content p {
  font-size: 1rem;
  color: var(--color-text);
}

.dropzone-hint {
  font-size: 0.85rem !important;
  color: var(--color-text-secondary) !important;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: var(--font-sans);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-bg);
  border-color: var(--color-border-hover);
}

/* ===== Document List ===== */
.document-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  margin-bottom: 1rem;
}

.document-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast);
}

.document-card:hover {
  box-shadow: var(--shadow-md);
}

.doc-thumb {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  overflow: hidden;
  font-size: 1.5rem;
}

.doc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.doc-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.doc-name {
  font-size: 0.9rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-size {
  font-size: 0.78rem;
  color: var(--color-text-secondary);
}

.doc-type {
  flex-shrink: 0;
}

.type-select {
  font-size: 0.82rem;
  padding: 0.3rem 0.5rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.type-select:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* Type Badge Colors */
.type-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
}

.type-badge--syllabus   { background: #3b82f6; }
.type-badge--assignment  { background: #22c55e; }
.type-badge--rubric      { background: #f59e0b; color: #111827; }
.type-badge--submission  { background: #a855f7; }
.type-badge--filledout   { background: #14b8a6; }

.doc-remove {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: 1rem;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.doc-remove:hover {
  background: #fee2e2;
  color: var(--color-error);
  border-color: #fecaca;
}

/* ===== Modal (Camera & Editor) ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
}

/* Camera */
.camera-container {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
}

.camera-container video {
  display: block;
  width: 100%;
  height: auto;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.camera-controls {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  justify-content: center;
}

/* Image Editor */
.editor-canvas-wrapper {
  position: relative;
  width: 100%;
  background: #111;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
}

.editor-canvas {
  display: block;
  width: 100%;
  max-height: 50vh;
  object-fit: contain;
}

.editor-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.editor-hint {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  text-align: center;
  margin: 0;
}

.editor-controls {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.editor-controls label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.88rem;
  color: var(--color-text-secondary);
}

.editor-controls input[type="range"] {
  flex: 1;
  accent-color: var(--color-primary);
}

.editor-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

/* ===== Grading Results ===== */
.grading-results {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.loading,
.placeholder {
  text-align: center;
  color: var(--color-text-secondary);
  padding: 2rem 0;
}

.error {
  text-align: center;
  color: var(--color-error);
  padding: 2rem 0;
}

.score-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.score-circle {
  display: flex;
  align-items: baseline;
  gap: 0.2rem;
}

.score-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
}

.score-max {
  font-size: 1.1rem;
  color: var(--color-text-secondary);
}

.letter-grade {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-success);
  padding: 0.25rem 0.75rem;
  border: 2px solid var(--color-success);
  border-radius: var(--radius-sm);
  line-height: 1;
}

.result-summary {
  color: var(--color-text-secondary);
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

/* Rubric Table */
.rubric-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.rubric-table th,
.rubric-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.rubric-table th {
  background: var(--color-bg);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-secondary);
}

.section-feedback {
  margin-bottom: 1rem;
}

.section-feedback h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.section-feedback p {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

.suggestions {
  margin-top: 1rem;
  padding: 1rem;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
}

.suggestions h4 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.suggestions ul {
  padding-left: 1.25rem;
}

.suggestions li {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.3rem;
}

/* ===== Responsive ===== */
@media (min-width: 640px) {
  .app-header {
    padding: 3rem 1rem 1.5rem;
  }

  .app-header h1 {
    font-size: 2.25rem;
  }

  .dropzone {
    padding: 3.5rem 2rem;
  }

  .dropzone-icon {
    font-size: 3rem;
  }

  .modal-content {
    max-width: 720px;
  }
}

@media (min-width: 1024px) {
  .app-main {
    padding: 0 2rem 4rem;
  }

  .document-card {
    padding: 1rem;
  }
}

/* ===== Document Builder Modal ===== */
.builder-modal-content {
  padding: 1.5rem;
  max-width: 640px;
}

.builder-name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.builder-name-row label {
  font-weight: 500;
  white-space: nowrap;
}

.builder-name-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--font-sans);
}

.builder-name-input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.builder-page-count {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.75rem;
}

.builder-pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
  min-height: 80px;
}

.builder-page-card {
  position: relative;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: grab;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
  background: var(--color-surface);
}

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

.builder-page-card.dragging {
  opacity: 0.4;
}

.builder-page-card.drag-over {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary-light);
}

.builder-page-thumb {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.builder-page-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background: var(--color-bg);
}

.builder-page-num {
  font-weight: 600;
  color: var(--color-text-secondary);
}

.builder-page-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--color-error);
  padding: 0 0.25rem;
  line-height: 1;
}

.builder-page-delete:hover {
  transform: scale(1.3);
}

.builder-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ===== Document Preview Modal ===== */
.preview-modal-content {
  max-width: 800px;
  display: flex;
  flex-direction: column;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.preview-title {
  font-weight: 600;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 0.5rem;
}

.preview-close-btn {
  flex-shrink: 0;
  padding: 0.25rem 0.75rem;
  font-size: 1.2rem;
  line-height: 1;
}

.preview-image-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  min-height: 200px;
  max-height: 65vh;
  overflow: auto;
  background: #111;
}

.preview-image {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
}

.preview-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--color-border);
}

.preview-page-info {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  min-width: 4rem;
  text-align: center;
}

/* ===== Camera Page Badge ===== */
.camera-page-badge {
  background: var(--color-primary);
  color: white;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* ===== PDF Preview in iframe ===== */
.preview-pdf {
  width: 100%;
  height: 65vh;
  border: none;
}

/* ===== Quota Display ===== */
.quota-display {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
  text-align: center;
}
