:root {
  --border: #e2e5eb;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --accent: #3457d5;
  --accent-hover: #2943ad;
  --accent-soft: #eef1ff;
  --text: #1c2430;
  --muted: #6b7280;
  --error: #c02b28;
  --error-soft: #fdecec;
  --success: #1a8754;
  --success-soft: #e8f7ef;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  transition: padding-right 0.2s ease;
}

body.preview-open {
  padding-right: min(45vw, 640px);
}

/* --- Topbar (index.html / admin.html) ------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-logo {
  height: 32px;
  width: auto;
  display: block;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 18px;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 2px;
  border-bottom: 2px solid transparent;
}

.nav-link:hover { color: var(--text); }
.nav-link.current { color: var(--accent); border-bottom-color: var(--accent); }

.current-user {
  font-size: 13px;
  color: var(--muted);
  padding-left: 6px;
  border-left: 1px solid var(--border);
}

.page-intro {
  padding: 16px 32px 0;
  margin: 0;
}

main {
  padding: 20px 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1200px;
}

/* --- Cards & forms ---------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
}

.card.hidden { display: none; }

.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
}

.subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 14px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.field-row label {
  font-weight: 600;
  font-size: 14px;
}

.field-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field-stack label {
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
}

.field-row-form {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.field-row-form .field-stack { margin-bottom: 0; min-width: 180px; }
.field-row-form button { margin-top: 0; }

select, input[type="text"], input[type="password"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}

select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-error {
  color: var(--error);
  font-size: 13px;
  min-height: 1em;
  margin: 8px 0 0;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  position: relative;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

#pending-files {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* --- Buttons ------------------------------------------------------------ */

button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  border: none;
  padding: 9px 18px;
}

.primary-btn, #extract-btn, #export-btn {
  background: var(--accent);
  color: #fff;
  margin-top: 14px;
  transition: background 0.15s ease;
}

.primary-btn:hover, #extract-btn:hover, #export-btn:hover { background: var(--accent-hover); }

button:disabled {
  background: #c3cae0 !important;
  cursor: not-allowed;
}

.secondary-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  padding: 0;
  font-size: 13px;
}

.text-btn:hover { text-decoration: underline; }

.full-width { width: 100%; }

.status {
  margin-left: 12px;
  font-size: 13px;
  color: var(--muted);
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.results-header button { margin-top: 0; }

/* --- Table -------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  margin-top: 16px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th, td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f7f8fa;
  font-weight: 600;
  position: sticky;
  top: 0;
}

tbody tr:hover { background: #fafbfd; }

td input {
  border: 1px solid transparent;
  background: transparent;
  width: 130px;
  font-size: 13px;
  padding: 4px;
  border-radius: 4px;
}

td input:focus {
  border-color: var(--accent);
  background: #fff;
  outline: none;
  box-shadow: none;
}

/* A document with several line items produces several consecutive rows --
   a heavier top border marks where a new document's rows start so they
   don't read as one continuous, undifferentiated block. */
tr.doc-start td {
  border-top: 2px solid var(--accent);
}

#errors-list, #errors-section h2 { color: var(--error); }
#errors-list { font-size: 13px; margin: 0; padding-left: 18px; }

#results-table a, #results-table button.link-btn {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
  cursor: pointer;
}
#results-table a:hover, #results-table button.link-btn:hover { text-decoration: underline; }
#results-table button.link-btn:disabled {
  background: none !important;
  color: var(--muted);
  cursor: not-allowed;
  font-style: italic;
}

/* --- Status badges (admin users table) ---------------------------------- */

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status-active { background: var(--success-soft); color: var(--success); }
.status-inactive { background: var(--error-soft); color: var(--error); }

.hidden { display: none !important; }

/* --- Preview panel -------------------------------------------------------- */

#preview-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(45vw, 640px);
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease;
}

#preview-panel.hidden {
  transform: translateX(100%);
  display: flex; /* keep transition working instead of display:none snapping */
  pointer-events: none;
}

.preview-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

#preview-panel-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 6px;
}
#preview-panel-close:hover { color: var(--text); }

#preview-frame {
  flex: 1;
  border: none;
  width: 100%;
}

/* --- Auth pages (login) --------------------------------------------------- */

.auth-body {
  background: linear-gradient(180deg, #eef1ff 0%, var(--bg) 320px);
}

/* .auth-wrap is a <main>, and the generic `main` selector above sets
   flex-direction: column + max-width: 1200px -- both need overriding here
   or the box ends up capped at 1200px and pinned left instead of truly
   centered on the page. */
.auth-wrap {
  width: 100%;
  max-width: none;
  min-height: 100vh;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  padding: 24px;
  margin: 0;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 32px 28px;
}

.auth-logo {
  display: block;
  margin: 0 auto 18px;
  max-width: 180px;
  width: 100%;
  height: auto;
}

.auth-card h1 {
  font-size: 19px;
  margin: 0 0 4px;
  text-align: center;
}

.auth-card .subtitle { margin-bottom: 20px; text-align: center; }

/* --- Dialogs (change password) -------------------------------------------- */

dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: min(90vw, 380px);
}

dialog::backdrop {
  background: rgba(16, 24, 40, 0.45);
}

dialog h2 {
  margin: 0 0 16px;
  font-size: 16px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.dialog-actions button { margin-top: 0; }
