/* ── Reset & variables ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #2D6A4F;
  --primary-l: #52B788;
  --accent:    #74C69D;
  --bg:        #F8FAF9;
  --surface:   #FFFFFF;
  --text:      #1B2D24;
  --muted:     #6B7B74;
  --danger:    #C0392B;
  --warning:   #E67E22;
  --info:      #2980B9;
  --radius:    8px;
  --shadow:    0 1px 4px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Nav ── */
nav {
  background: var(--surface);
  border-bottom: 1px solid #e0e8e4;
  padding: 0 2rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

nav .logo img { height: 36px; display: block; }

nav .nav-links { display: flex; gap: 1.5rem; list-style: none; }
nav .nav-links a {
  text-decoration: none;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 500;
  padding: .25rem 0;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
nav .nav-links a:hover,
nav .nav-links a.active { color: var(--primary); border-color: var(--primary); }

/* ── Page container ── */
.page { max-width: 960px; margin: 0 auto; padding: 2.5rem 1.5rem; }

/* ── Headings ── */
h1 { font-size: 1.6rem; font-weight: 700; color: var(--text); margin-bottom: .4rem; }
h2 { font-size: 1.2rem; font-weight: 600; color: var(--text); margin-bottom: 1rem; }
p.sub { color: var(--muted); font-size: .9rem; margin-bottom: 2rem; }

/* ── Drop zone ── */
.dropzone {
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 4rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.dropzone.drag-over { background: #edf7f1; border-color: var(--primary); }
.dropzone .dz-icon { font-size: 3rem; margin-bottom: 1rem; color: var(--accent); }
.dropzone p { color: var(--muted); margin-bottom: 1rem; }
.dropzone input[type=file] { display: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: opacity .15s, background .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover:not(:disabled) { background: #235540; }
.btn-secondary { background: var(--surface);   color: var(--primary); border: 1.5px solid var(--primary); }
.btn-secondary:hover:not(:disabled) { background: #edf7f1; }
.btn-danger    { background: var(--danger);    color: #fff; }
.btn-sm        { padding: .35rem .8rem; font-size: .82rem; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-pending     { background: #FEF3E2; color: var(--warning); }
.badge-processing  { background: #D6EAF8; color: var(--info); }
.badge-completed   { background: #D5F5E3; color: #1E8449; }
.badge-failed      { background: #FADBD8; color: var(--danger); }
.badge-unreviewed  { background: #EAECEE; color: #5D6D7E; }
.badge-reviewed    { background: #D6EAF8; color: var(--info); }
.badge-approved    { background: #D5F5E3; color: #1E8449; }

/* ── File chip ── */
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: #edf7f1;
  border: 1px solid var(--accent);
  border-radius: 99px;
  padding: .3rem .9rem;
  font-size: .85rem;
  color: var(--primary);
  margin-top: 1rem;
}

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--accent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Status area (upload page) ── */
#status-area { margin-top: 1.5rem; }
.status-msg { color: var(--muted); font-size: .9rem; display: flex; align-items: center; gap: .5rem; }
.error-msg  { color: var(--danger); font-size: .9rem; }

/* ── Result card ── */
.result-card {
  background: var(--surface);
  border: 1px solid #d0e8dc;
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1.5rem;
  box-shadow: var(--shadow);
}
.result-card h3 { font-size: 1rem; margin-bottom: 1rem; color: var(--primary); }
.result-card .meta-row { display: flex; gap: 2rem; margin-bottom: .75rem; flex-wrap: wrap; }
.result-card .meta-item { font-size: .88rem; }
.result-card .meta-item label { display: block; color: var(--muted); font-size: .78rem; margin-bottom: .15rem; }
.result-card .actions { margin-top: 1.25rem; display: flex; gap: .75rem; flex-wrap: wrap; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
thead { background: #edf7f1; }
th {
  text-align: left;
  padding: .75rem 1rem;
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid #d0e8dc;
}
td {
  padding: .75rem 1rem;
  font-size: .88rem;
  border-bottom: 1px solid #f0f4f2;
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: #f3faf6; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--muted);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { margin-bottom: 1.5rem; }

/* ── Review layout ── */
.review-layout {
  display: grid;
  grid-template-columns: 60fr 40fr;
  gap: 1.5rem;
  height: calc(100vh - 60px);
}

.preview-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.preview-panel iframe {
  flex: 1;
  border: none;
  width: 100%;
  height: 100%;
}
.preview-fallback {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .9rem;
  padding: 2rem;
  text-align: center;
}

.detail-panel {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 1rem;
}

/* ── Document header ── */
.doc-header {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.doc-header h2 { font-size: 1rem; margin-bottom: .5rem; word-break: break-word; }
.doc-header .badges { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.doc-header .meta { font-size: .8rem; color: var(--muted); }

/* ── Category card ── */
.cat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.cat-card h3 { font-size: .9rem; color: var(--muted); margin-bottom: .75rem; font-weight: 600; }

.field-group { margin-bottom: .75rem; }
.field-group label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: .25rem; font-weight: 500; }
.field-group input,
.field-group select,
.field-group textarea {
  width: 100%;
  border: 1px solid #d0e8dc;
  border-radius: 6px;
  padding: .5rem .75rem;
  font-size: .88rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus {
  outline: none;
  border-color: var(--primary-l);
}
.field-group textarea { resize: vertical; min-height: 80px; }

.cat-card .card-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }
.save-msg { font-size: .78rem; color: var(--primary); }

/* ── Raw text collapsible ── */
.collapsible {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.collapsible summary {
  padding: 1rem 1.25rem;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.collapsible summary::-webkit-details-marker { display: none; }
.collapsible summary::before { content: "▶"; font-size: .7rem; transition: transform .2s; }
.collapsible[open] summary::before { transform: rotate(90deg); }
.collapsible pre {
  padding: 1rem 1.25rem;
  font-size: .78rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  border-top: 1px solid #f0f4f2;
  max-height: 200px;
  overflow-y: auto;
}

/* ── Action bar ── */
.action-bar {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  gap: .75rem;
  align-items: center;
}

/* ── Alert ── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .88rem;
  margin-bottom: 1rem;
}
.alert-error { background: #FADBD8; color: var(--danger); }

/* ── Upload form validation ── */
.required-star { color: var(--danger); }
.field-error {
  color: var(--danger);
  font-size: .78rem;
  margin-top: .25rem;
}
.field-group input.input-error {
  border-color: var(--danger);
}
.field-group input.input-error:focus {
  border-color: var(--danger);
}

/* ── Utilities ── */
.hidden { display: none !important; }
.mt-1  { margin-top: .5rem; }
.mt-2  { margin-top: 1rem; }
