:root {
  --ink: #1b2b36;
  --brand: #26404f;
  --brand-2: #355a6e;
  --bg: #f3f5f7;
  --card: #ffffff;
  --line: #d9dfe4;
  --muted: #5f6f7a;
  --ok: #1f7a4d;
  --warn: #9a6200;
  --alert: #b3261e;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--brand-2); }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  padding: .5rem 1rem; background: #fff; border-bottom: 3px solid var(--brand);
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); font-weight: 600; }
.brand img { height: 36px; width: auto; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .9rem; flex: 1; }
.nav a { text-decoration: none; color: var(--ink); }
.nav a:hover { text-decoration: underline; }
.tools { display: flex; align-items: center; gap: .6rem; margin-left: auto; }
.tools form { margin: 0; }
.who { color: var(--muted); font-size: .9rem; }
.lang select { padding: .2rem .3rem; min-height: 0; width: auto; }

.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 1rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  padding: .5rem .9rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--ink); text-decoration: none; font: inherit; cursor: pointer;
  min-height: 42px;
}
.btn:hover { border-color: var(--brand-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff !important; }
.btn-primary:hover { background: var(--brand-2); }
.btn-lg { padding: .7rem 1.3rem; font-size: 1.05rem; font-weight: 600; }
.btn-sm { padding: .25rem .6rem; min-height: 32px; font-size: .875rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
button.link { background: none; border: 0; padding: 0; color: var(--brand-2); text-decoration: underline; cursor: pointer; font: inherit; }

/* Cards, messages */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.narrow { max-width: 440px; margin: 2rem auto; }
.msg { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.msg-success { background: #e8f5ee; border-color: #a9d8bd; color: #14532d; }
.msg-info { background: #e8f1f8; border-color: #b0cce3; }
.msg-error, .msg-danger { background: #fdecea; border-color: #f2b8b5; color: #7a1c16; }
.msg-warning { background: #fff5e0; border-color: #f0d29a; }
.callout { background: #fff8e6; border: 1px solid #f0d29a; border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; }
.callout .quote { margin-top: .4rem; color: var(--muted); }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: .75rem; }
.page-head h1 { margin: 0; }
.empty { color: var(--muted); padding: 1rem 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .8rem; }
.field label { font-weight: 600; font-size: .92rem; }
.req { color: var(--alert); }
input[type=text], input[type=password], input[type=date], input[type=datetime-local], input[type=number], select, textarea {
  width: 100%; padding: .55rem .6rem; border: 1px solid #b9c3cb; border-radius: 6px;
  font: inherit; background: #fff; color: var(--ink); min-height: 44px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 1px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--alert); }
.err { color: var(--alert); font-size: .875rem; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: .5rem 0 1rem; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
.search-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 1rem; margin-top: .8rem; }
.search-grid .actions { grid-column: 1 / -1; }
.review-grid { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
.review-grid .actions { grid-column: 1 / -1; }
details.search summary { cursor: pointer; font-weight: 600; }
@media (min-width: 720px) {
  .form-grid { grid-template-columns: repeat(3, 1fr); }
  .form-grid .f-details, .form-grid .f-action_taken, .form-grid .f-correction_reason { grid-column: 1 / -1; }
  .form-grid .f-occurred_at, .form-grid .f-related_party, .form-grid .f-reported_by { grid-column: span 1; }
  .review-grid { grid-template-columns: 1fr 1fr; }
  .review-grid .f-comment { grid-column: 1 / -1; }
}

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--brand); border-radius: var(--radius); padding: .8rem 1rem; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; }
.stat.warn { border-left-color: var(--warn); }
.stat.alert { border-left-color: var(--alert); }
.stat-n { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat-l { color: var(--muted); font-size: .9rem; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #eef2f5; font-size: .85rem; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); }
td.num { white-space: nowrap; font-weight: 600; }
td.details { max-width: 420px; }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.history td { font-size: .9rem; }
@media (max-width: 719px) {
  table.entries, table.entries tbody, table.entries tr, table.entries td { display: block; width: 100%; }
  table.entries { border: 0; background: none; }
  table.entries thead { display: none; }
  table.entries tr { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .6rem; padding: .3rem 0; }
  table.entries td { border: 0; padding: .2rem .8rem; }
  table.entries td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--muted); text-transform: uppercase; }
  .history thead { display: none; }
  .history td { display: block; border: 0; padding: .15rem .6rem; }
  .history tr { display: block; border-bottom: 1px solid var(--line); padding: .4rem 0; }
}

/* Badges */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e6ebef; white-space: nowrap; }
.s-open { background: #e3f1fb; color: #0f4c75; }
.s-closed { background: #e8f5ee; color: var(--ok); }
.s-pending_review { background: #fff1d6; color: var(--warn); }
.s-correction_required { background: #fdecea; color: var(--alert); }
.s-archived { background: #ececec; color: #555; }
.r-reviewed { background: #e8f5ee; color: var(--ok); }
.r-escalated { background: #fdecea; color: var(--alert); }
.r-corrected { background: #efe9fb; color: #5b3a9a; }
.tag { display: inline-block; margin-left: .3rem; font-size: .7rem; padding: 0 .4rem; border-radius: 4px; background: #efe9fb; color: #5b3a9a; font-weight: 600; }

/* Login */
.btn-ms { gap: .6rem; font-weight: 600; border-color: #8c8c8c; color: #1b1b1b; }
.small { font-size: .85rem; margin: .5rem 0 0; }
.divider { display: flex; align-items: center; gap: .6rem; margin: 1.2rem 0 1rem; color: var(--muted); font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* Reports & archive */
.month-pick { display: flex; align-items: center; gap: .4rem; margin: 0; }
.month-pick input[type=month] { width: auto; min-height: 36px; padding: .3rem .5rem; border: 1px solid #b9c3cb; border-radius: 6px; font: inherit; }
.archive-box .actions { margin-bottom: 0; }
.archive-box form { margin: 0; }
.count-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem; }
.count-grid .card { margin-bottom: 0; }
.count-grid h3 { margin-top: 0; }
table.counts { border: 0; }
table.counts td { padding: .3rem .2rem; }
table.counts td.n { text-align: right; font-weight: 700; width: 3rem; }
table.counts tr.zero td { color: #9aa6ae; }
.hash { font-family: ui-monospace, Consolas, monospace; font-size: .75rem; }
.signoff { display: flex; flex-direction: column; gap: .35rem; min-width: 180px; }
.signoff textarea { min-height: 0; font-size: .875rem; }

/* Detail */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.text { white-space: normal; }
.lock { font-size: 1rem; vertical-align: middle; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .3rem 0; border-bottom: 1px solid var(--line); }
@media (max-width: 480px) {
  .facts { grid-template-columns: 1fr; }
  .facts dd { margin-bottom: .4rem; }
  .brand span { display: none; }
}
