:root {
  --bg: #f5f6f8;
  --panel-bg: #ffffff;
  --text: #1a1d23;
  --muted-text: #6b7280;
  --border: #e2e5ea;
  --accent: #2563eb;
  --accent-text: #ffffff;

  --success-bg: #dcfce7;
  --success-text: #166534;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --info-bg: #dbeafe;
  --info-text: #1e40af;
  --muted-bg: #e5e7eb;
  --muted-text-badge: #374151;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel-bg: #1c1f26;
    --text: #e6e8eb;
    --muted-text: #9aa1ac;
    --border: #2d323c;
    --accent: #3b82f6;
    --accent-text: #ffffff;

    --success-bg: #14321f;
    --success-text: #4ade80;
    --warn-bg: #3a2a08;
    --warn-text: #fbbf24;
    --error-bg: #3a1414;
    --error-text: #f87171;
    --info-bg: #122a4a;
    --info-text: #60a5fa;
    --muted-bg: #2a2e37;
    --muted-text-badge: #b3b9c4;
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted-text);
  font-size: 0.9rem;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.panel h2 {
  margin-top: 0;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.panel h3 {
  font-size: 0.95rem;
  color: var(--muted-text);
  margin-bottom: 0.5rem;
}

.hidden {
  display: none !important;
}

.hint {
  color: var(--muted-text);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

.authority-banner {
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0.5rem 0;
}

.row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.settings-row label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted-text);
}

select,
input[type='file'],
input[type='text'],
input[type='date'],
input[type='search'] {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  font: inherit;
  padding: 0.5rem 1.1rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 600;
  transition: background-color 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

a {
  color: var(--accent);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background: var(--success-bg);
  color: var(--success-text);
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.badge-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.badge-info {
  background: var(--info-bg);
  color: var(--info-text);
}

.badge-muted {
  background: var(--muted-bg);
  color: var(--muted-text-badge);
}

#statusTable {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

#statusTable th,
#statusTable td {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

#statusTable th {
  color: var(--muted-text);
  font-weight: 600;
  font-size: 0.8rem;
}

.log-panel {
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.8rem;
}

.log-line {
  white-space: pre-wrap;
  word-break: break-word;
  padding: 0.1rem 0;
}

.log-info {
  color: var(--text);
}

.log-step {
  color: var(--info-text);
}

.log-success {
  color: var(--success-text);
}

.log-warn {
  color: var(--warn-text);
}

.log-error {
  color: var(--error-text);
}

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

.history-item {
  padding: 0.6rem 0.5rem;
  margin: 0 -0.5rem;
  border-bottom: 1px solid var(--border);
  border-radius: 6px;
  transition: background-color 0.1s ease;
}

.history-item:hover {
  background: var(--bg);
}

.history-item:last-child {
  border-bottom: none;
}

.efos-queue-row {
  cursor: pointer;
  padding: 0.4rem 0.5rem;
  margin: 0 -0.5rem;
  border-bottom: 1px solid var(--border);
}

.efos-queue-row:last-of-type {
  border-bottom: none;
}

.queue-status-panel {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.history-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

.history-links {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal {
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 1.5rem;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

.modal-message {
  font-weight: 600;
  margin-top: 0;
}

.modal-detail {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

.modal-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.prompt-btn {
  text-align: left;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.prompt-btn:hover {
  background: var(--accent);
  color: var(--accent-text);
}

/* Complaint Entry module */

.header-nav {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.header-nav a,
.header-nav span.active {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
}

.header-nav a {
  text-decoration: none;
  color: var(--muted-text);
}

.header-nav a:hover {
  background: var(--bg);
  color: var(--text);
}

/* The current page -- shown as a plain non-clickable label, not a link. */
.header-nav span.active {
  background: var(--info-bg);
  color: var(--info-text);
}

.field-group {
  margin-bottom: 1rem;
}

.field-group label,
.field-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted-text);
}

.field-group input,
.field-grid input,
textarea {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

textarea {
  width: 100%;
  resize: vertical;
  font-family: inherit;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.flagged {
  border-color: var(--warn-text) !important;
  box-shadow: 0 0 0 1px var(--warn-text);
}

.respondent-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}

.respondent-row-header {
  align-items: flex-end;
  margin-bottom: 0.5rem;
}

.respondent-row-header label {
  flex: 1;
}

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

.action-row {
  margin-top: 1.25rem;
}

.offence-types {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.4rem 1rem;
  margin-bottom: 0.5rem;
}

.offence-type-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  font-weight: normal;
  color: var(--text);
}

.offence-type-option input[type='checkbox'] {
  width: auto;
}

.match-hint {
  margin-top: -0.25rem;
  font-style: italic;
  grid-column: 1 / -1;
}

.full-width-label {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
}

/* Step badges on the numbered "1. Upload" / "2. Review" panel headers */
.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Review panel toolbar: quick-nav + attention counter */
.review-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0.75rem 0 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.quick-nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.quick-nav a {
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.quick-nav a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.attention-counter {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: none;
  background: var(--warn-bg);
  color: var(--warn-text);
  cursor: pointer;
}

.anchor-target {
  scroll-margin-top: 1rem;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.count-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted-text-badge);
  background: var(--muted-bg);
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
}

/* Collapsible Complainant/Respondent/Offence blocks */
.block-header-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.collapse-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--muted-text);
  padding: 0.2rem 0.4rem;
  line-height: 1;
  flex-shrink: 0;
  align-self: center;
}

.collapse-toggle:hover {
  color: var(--text);
}

.block-summary {
  color: var(--muted-text);
  font-size: 0.85rem;
  font-style: italic;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  align-self: center;
}

.block-body.hidden {
  display: none;
}

/* Danger buttons -- Remove/Delete */
.danger-btn {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid transparent;
}

.danger-btn:hover {
  background: var(--error-text);
  color: var(--accent-text);
}

/* Status banner -- replaces plain hint text for key save/error feedback */
.status-banner {
  margin-top: 0.75rem;
  padding: 0.55rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-banner.status-success {
  background: var(--success-bg);
  color: var(--success-text);
}

.status-banner.status-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.status-banner.status-info {
  background: var(--info-bg);
  color: var(--info-text);
}

/* Search page pagination */
#paginationControls {
  justify-content: center;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

#pageIndicator {
  color: var(--muted-text);
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 6rem;
  text-align: center;
}

/* Cost Report page */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 0.75rem;
}

.stat-card {
  background: var(--panel-bg);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.stat-label {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-text);
  font-weight: 600;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-value .unit {
  font-size: 0.85rem;
  color: var(--muted-text);
  font-weight: 500;
  margin-left: 0.15rem;
}

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

@media (max-width: 720px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--muted-text);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: var(--bg);
}

.data-table td.num,
.data-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table td.ref {
  white-space: normal;
  max-width: 240px;
}

.data-table tfoot td {
  font-weight: 700;
  background: var(--bg);
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: var(--bg);
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.table-scroll .data-table {
  min-width: 760px;
}

.table-scroll .data-table th:first-child,
.table-scroll .data-table td:first-child {
  padding-left: 1rem;
}
