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

:root {
  --primary: #1a365d;
  --primary-light: #2a5298;
  --accent: #e53e3e;
  --bg: #f7f8fc;
  --card-bg: #ffffff;
  --text: #1a202c;
  --text-muted: #718096;
  --border: #e2e8f0;
  --success: #38a169;
  --warning: #d69e2e;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

.breadcrumb {
  margin-bottom: 1rem;
}

.breadcrumb a {
  color: var(--primary-light);
  text-decoration: none;
  font-size: 0.85rem;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

header h1 {
  color: var(--primary);
  font-size: 1.8rem;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
}

.card h2 {
  font-size: 1.1rem;
  color: var(--primary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary-light);
  background: rgba(42, 82, 152, 0.03);
}

.dropzone-content svg {
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.dropzone-content p {
  color: var(--text-muted);
}

.dropzone-content .small {
  font-size: 0.8rem;
}

.file-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-weight: 600;
  color: var(--success);
}

#file-pages {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.btn-small {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
}

/* Progress */
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary-light);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

/* Summary stats */
.summary-stats {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

.stat {
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--accent); }

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  background: var(--primary);
  color: white;
  padding: 0.5rem 0.6rem;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

tr:hover td {
  background: rgba(42, 82, 152, 0.03);
}

.badge {
  background: var(--primary-light);
  color: white;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-weight: 600;
}

.status-matched {
  color: var(--success);
  font-weight: 600;
}

.status-unmatched {
  color: var(--accent);
  font-weight: 600;
}

/* Unmatched card */
.unmatched-card {
  border-color: var(--accent);
  background: #fef2f2;
}

.unmatched-card h2 {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.hint {
  font-size: 0.8rem;
  color: #991b1b;
  margin-bottom: 0.75rem;
}

footer {
  text-align: center;
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
}

footer a {
  color: var(--primary-light);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Buttons */
.btn-primary {
  background: var(--primary-light);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

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

/* Inline form (new project) */
.inline-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.inline-form input[type="text"] {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
}

.inline-form input[type="text"]:focus {
  outline: none;
  border-color: var(--primary-light);
}

/* Project list */
#projects-table tbody tr {
  cursor: pointer;
}

.standalone-link {
  text-align: center;
  margin: 1rem 0;
  font-size: 0.85rem;
}

.standalone-link a {
  color: var(--text-muted);
  text-decoration: none;
}

.standalone-link a:hover {
  color: var(--primary-light);
  text-decoration: underline;
}

/* Project uploads table */
#project-uploads-table tbody tr {
  cursor: pointer;
}

/* Page classification layout */
.page-classify-layout {
  display: grid;
  grid-template-columns: 1fr 350px;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 800px) {
  .page-classify-layout {
    grid-template-columns: 1fr;
  }
}

/* Thumbnail grid */
.thumbnail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}

.thumbnail {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: white;
}

.thumbnail:hover {
  border-color: var(--primary-light);
}

.thumbnail.selected {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 2px rgba(42, 82, 152, 0.3);
}

.thumbnail canvas {
  display: block;
  width: 100%;
  height: auto;
}

.thumbnail-label {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  text-align: center;
  background: var(--bg);
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.thumbnail-label .classification-tag {
  font-size: 0.65rem;
  background: var(--primary-light);
  color: white;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}

/* Page detail panel */
.page-detail-panel .card {
  position: sticky;
  top: 1rem;
}

.form-group {
  margin-bottom: 0.75rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.form-group select,
.form-group input[type="text"] {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
}

.form-group select:focus,
.form-group input[type="text"]:focus {
  outline: none;
  border-color: var(--primary-light);
}

#page-callouts-list {
  margin-top: 0.75rem;
}

#page-callouts-list h3 {
  font-size: 0.85rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.callout-chip {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  margin: 0.15rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.callout-chip.matched {
  background: #c6f6d5;
  color: #22543d;
}

.callout-chip.unmatched {
  background: #fed7d7;
  color: #742a2a;
}

/* Breadcrumb links */
.breadcrumb span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.hint {
  color: var(--text-muted);
}

.unmatched-card .hint {
  color: #991b1b;
}
