* { box-sizing: border-box; }
/* Ensure the HTML `hidden` attribute always wins over display:flex/grid below */
[hidden] { display: none !important; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  background: #f4f6f9;
  color: #1f2937;
}
header {
  background: #1e3a5f;
  color: #fff;
  padding: 18px 24px;
}
header h1 { margin: 0; font-size: 22px; }
.subtitle { margin: 4px 0 0; opacity: 0.8; font-size: 14px; }
main { max-width: 1200px; margin: 20px auto; padding: 0 16px; }

.card {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.key-card label { display: block; margin-bottom: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { color: #6b7280; font-size: 13px; }

.filters { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.filters label { display: block; font-size: 13px; color: #6b7280; margin-bottom: 4px; }
.filters-actions { margin-left: auto; display: flex; gap: 8px; align-items: flex-end; }

input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  min-width: 140px;
}
textarea { width: 100%; min-width: 0; resize: vertical; }

.btn {
  font: inherit;
  padding: 8px 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
.btn:hover { background: #f3f4f6; }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-light { background: #f3f4f6; }
.btn-confirm { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn-confirm:hover { background: #15803d; }
.btn-small { padding: 4px 8px; font-size: 13px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #eef0f3; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.03em; }
td.fact-cell { max-width: 380px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.verified     { background: #dcfce7; color: #166534; }
.badge.needs_review { background: #fef9c3; color: #854d0e; }
.badge.outdated     { background: #fee2e2; color: #991b1b; }

.actions-cell { white-space: nowrap; display: flex; gap: 6px; }

.message { padding: 10px 12px; border-radius: 6px; margin-bottom: 10px; font-size: 14px; }
.message:empty { display: none; }
.message.error { background: #fee2e2; color: #991b1b; }
.message.success { background: #dcfce7; color: #166534; }

/* modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 30px 16px; overflow-y: auto; z-index: 50;
}
.modal-box {
  background: #fff; border-radius: 12px; padding: 22px;
  width: 100%; max-width: 700px;
}
.modal-box h2 { margin-top: 0; }
.modal-box label { display: block; font-size: 13px; color: #374151; margin: 10px 0 4px; }
.modal-box input, .modal-box select { width: 100%; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; }
.checkbox-field { display: flex; align-items: flex-end; }
.checkbox-field label { display: flex; align-items: center; gap: 6px; }
.checkbox-field input { width: auto; min-width: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* wide table can scroll sideways on medium screens instead of breaking layout */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ============================================================
   Mobile: turn the facts table into a card-per-row layout,
   stack filters and form fields into a single column.
   ============================================================ */
@media (max-width: 720px) {
  header { padding: 14px 16px; }
  header h1 { font-size: 18px; }
  .subtitle { font-size: 12px; }
  main { padding: 0 10px; margin: 12px auto; }
  .card { padding: 12px; }

  /* filters & rows full width */
  .filters { gap: 10px; }
  .filters > div { width: 100%; }
  .filters-actions { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .filters-actions .btn { flex: 1 1 auto; }
  input, select, textarea { min-width: 0; width: 100%; }
  .row { width: 100%; }

  /* table -> stacked cards */
  .table-wrap { overflow: visible; }
  #factsTable thead { display: none; }
  #factsTable, #factsTable tbody, #factsTable tr, #factsTable td { display: block; width: 100%; }
  #factsTable tr {
    border: 1px solid #e5e7eb; border-radius: 10px;
    padding: 8px 12px; margin-bottom: 12px; background: #fff;
  }
  #factsTable td {
    border: none; padding: 6px 0;
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
  }
  #factsTable td::before {
    content: attr(data-label);
    font-weight: 600; color: #6b7280; font-size: 12px;
    text-transform: uppercase; flex: 0 0 42%;
  }
  #factsTable td.fact-cell { display: block; max-width: none; }
  #factsTable td.fact-cell::before { display: block; margin-bottom: 4px; }
  #factsTable td.actions-cell { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 8px; }
  #factsTable td.actions-cell::before { content: ""; flex: 0; }
  #factsTable td.actions-cell .btn { flex: 1 1 auto; min-width: 110px; }

  /* modal full width, single column */
  .modal { padding: 12px; }
  .modal-box { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
}
