:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #dde3ea;
  --primary: #0f6e6a;
  --primary-dark: #0a524f;
  --primary-soft: #e3f2f1;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warning: #9a6700;
  --warning-soft: #fff5d6;
  --success: #1a7f37;
  --success-soft: #e6f4ea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* Layout */
.topbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.25rem;
  min-height: 56px;
  flex-wrap: wrap;
}
.topbar a { color: #fff; }
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; }
.brand small { font-weight: 400; opacity: .8; margin-left: .4rem; font-size: .85rem; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { padding: .45rem .7rem; border-radius: 6px; opacity: .9; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.15); text-decoration: none; opacity: 1; }
.userbox { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.userbox form { margin: 0; }
.userbox button { background: transparent; border: 1px solid rgba(255,255,255,.5); color: #fff; padding: .3rem .7rem; border-radius: 6px; cursor: pointer; }
.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }
.narrow { max-width: 560px; }

/* Cards & grid */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.kpi .label { color: var(--muted); font-size: .82rem; }
.kpi .value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin-top: .15rem; }
.kpi .hint { color: var(--muted); font-size: .78rem; }
.kpi.danger .value { color: var(--danger); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; background: #fafbfc; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.overdue td { background: var(--danger-soft); }
.empty { color: var(--muted); padding: 1rem 0; }

/* Badges */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef1f4; color: var(--muted); }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.info { background: var(--primary-soft); color: var(--primary); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .5rem .95rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: .92rem; cursor: pointer;
  font-family: inherit; line-height: 1.3; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: #c4ccd6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f0c2bd; }
.btn-sm { padding: .3rem .6rem; font-size: .84rem; }
.btn-lg { padding: .7rem 1.3rem; font-size: 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.inline-form { display: inline; margin: 0; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .9rem 1.1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: .88rem; }
.field .req { color: var(--danger); }
.field .help { color: var(--muted); font-size: .8rem; }
.field .errors { color: var(--danger); font-size: .82rem; margin: 0; padding: 0; list-style: none; }
.field.checkbox { flex-direction: row; align-items: flex-start; gap: .5rem; }
.field.checkbox label { font-weight: 400; }
input[type=text], input[type=password], input[type=date], input[type=email], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid #c9d1db; border-radius: 6px;
  font-size: .95rem; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.radio-list { display: flex; gap: 1rem; flex-wrap: wrap; list-style: none; padding: 0; margin: 0; }
.radio-list label { font-weight: 400; display: flex; gap: .35rem; align-items: center; }
.form-actions { display: flex; gap: .6rem; margin-top: 1.25rem; flex-wrap: wrap; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1.1rem; }
legend { font-weight: 700; padding: 0 .4rem; }

/* Search */
.search-hero { display: flex; gap: .6rem; }
.search-hero input { font-size: 1.1rem; padding: .7rem .9rem; }

/* Alerts */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: .6rem; border: 1px solid transparent; }
.alert.success { background: var(--success-soft); color: var(--success); border-color: #bfe3c9; }
.alert.error, .alert.danger { background: var(--danger-soft); color: var(--danger); border-color: #f5c6c1; }
.alert.warning { background: var(--warning-soft); color: var(--warning); border-color: #f2dc9b; }
.alert.info { background: var(--primary-soft); color: var(--primary); border-color: #bfe0de; }

/* Definition list */
.dl { display: grid; grid-template-columns: 180px 1fr; gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .88rem; }
.dl dd { margin: 0; }

/* Issue rows */
.issue-row { display: grid; grid-template-columns: 2.2fr 1.4fr 1fr .9fr 1.1fr auto; gap: .6rem; align-items: start; padding: .75rem 0; border-bottom: 1px dashed var(--border); }
.issue-row:last-child { border-bottom: none; }
.issue-row .field label { font-size: .8rem; }
.section-hint { font-size: .78rem; color: var(--primary); min-height: 1em; }
.section-hint.bad { color: var(--danger); }
.autocomplete { position: relative; }
.suggestions { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 18px rgba(16,24,40,.12); max-height: 280px; overflow-y: auto; }
.suggestions button { display: block; width: 100%; text-align: left; background: none; border: none; padding: .5rem .7rem; cursor: pointer; font: inherit; }
.suggestions button:hover, .suggestions button.active { background: var(--primary-soft); }
.suggestions .meta { color: var(--muted); font-size: .8rem; }

/* Bars in stats tables */
.bar { height: 8px; background: var(--primary); border-radius: 4px; min-width: 2px; }
.bar-cell { width: 35%; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { color: var(--primary); font-size: 1.6rem; margin-bottom: .25rem; }

.password-box { font-size: 1.6rem; font-weight: 700; letter-spacing: 1px; background: var(--warning-soft); border: 1px dashed var(--warning); padding: .8rem 1rem; border-radius: var(--radius); display: inline-block; margin: .5rem 0 1rem; }

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: .45rem 0; display: flex; gap: .6rem; align-items: center; }

@media (max-width: 860px) {
  .issue-row { grid-template-columns: 1fr 1fr; }
  .dl { grid-template-columns: 1fr; }
  .dl dt { margin-top: .4rem; }
  .search-hero { flex-direction: column; }
}
