:root {
  --brand: #0f6e6e;
  --brand-dark: #0a5252;
  --bg: #f4f7f7;
  --card: #ffffff;
  --text: #1c2b2b;
  --muted: #5d6f6f;
  --line: #dbe4e4;
  --missing-bg: #eceff1; --missing-fg: #455a64;
  --uploaded-bg: #fff4d6; --uploaded-fg: #8a5a00;
  --checked-bg: #ddf3e4; --checked-fg: #1d6b39;
  --expired-bg: #fde2e1; --expired-fg: #a12622;
  --radius: 10px;
}

* { box-sizing: border-box; }
/* Anything marked hidden must stay hidden, whatever other styles say. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.2rem; margin: 0 0 1rem; }
code { background: #eef3f3; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .sub { display: block; font-size: .8rem; opacity: .85; }
.logo {
  width: 36px; height: 36px; border-radius: 8px; background: #fff; color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 1.2rem;
}
.logo img { width: 30px; height: 30px; object-fit: contain; }
.user-box { display: flex; align-items: center; gap: 10px; }
.user-box .muted { color: #d6eeee; font-size: .9rem; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.6); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 18px;
}
.card.narrow { max-width: 440px; margin: 40px auto; }

label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 600; }
input, select {
  font: inherit; font-weight: 400; padding: 9px 10px; border: 1px solid #b9c7c7;
  border-radius: 7px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
input:disabled { background: #f0f3f3; color: var(--muted); }
input[type="file"] { padding: 6px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span2 { grid-column: span 2; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 7px;
  padding: 9px 16px; border: 1px solid var(--line); background: #fff; color: var(--text);
}
.btn:hover { background: #f1f5f5; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--expired-fg); border-color: #f0b9b6; }
.btn.small { padding: 5px 11px; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: wait; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; align-self: flex-start; }

.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: 0; padding: 10px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 500; }
.flash.info { background: #e3f1f8; color: #134a66; }
.flash.success { background: var(--checked-bg); color: var(--checked-fg); }
.flash.error { background: var(--expired-bg); color: var(--expired-fg); }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem;
  font-weight: 700; white-space: nowrap;
}
.badge.missing { background: var(--missing-bg); color: var(--missing-fg); }
.badge.uploaded { background: var(--uploaded-bg); color: var(--uploaded-fg); }
.badge.checked { background: var(--checked-bg); color: var(--checked-fg); }
.badge.expired { background: var(--expired-bg); color: var(--expired-fg); }
.badge.action { background: var(--expired-bg); color: var(--expired-fg); }
.badge.review { background: var(--uploaded-bg); color: var(--uploaded-fg); }
.badge.ok { background: var(--checked-bg); color: var(--checked-fg); }
.exp { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.exp.warn { color: var(--uploaded-fg); font-weight: 700; }
.exp.bad { color: var(--expired-fg); font-weight: 700; }

/* Admin two-step login */
.steps { padding-left: 20px; margin: 0 0 10px; }
.steps li { margin-bottom: 6px; }
.qr-box { display: flex; justify-content: center; padding: 12px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.secret { display: block; margin: 8px 0; padding: 8px; word-break: break-all; font-size: .95rem; letter-spacing: .05em; }
.mfa-form { margin-top: 14px; }
.mfa-form input[name="code"] { font-size: 1.4rem; letter-spacing: .3em; text-align: center; }

/* Worker */
.progress-card { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.progress { min-width: 180px; text-align: right; }
.progress-num { font-size: 1.6rem; font-weight: 800; color: var(--brand); }
.progress-bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 4px 0; }
.progress-bar span { display: block; height: 100%; background: var(--brand); width: 0; transition: width .3s; }

.doc-list { display: flex; flex-direction: column; gap: 14px; }
.doc { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.doc-head h3 { margin: 0; font-size: 1rem; }
.doc-hint { margin: 4px 0 10px; }
.doc-file { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; background: #f7fafa; border-radius: 7px; margin-bottom: 8px; font-size: .9rem; }
.doc-file .name { font-weight: 600; word-break: break-all; }
.admin-note { background: #fff4d6; color: #6b4600; padding: 6px 10px; border-radius: 7px; font-size: .85rem; width: 100%; }
.upload-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.upload-row label { flex: 1 1 200px; }
.upload-row .btn { flex: 0 0 auto; }

.consent { font-weight: 400; background: #f1f7f7; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.consent-row { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; }
.consent-row input { width: 20px; height: 20px; flex: 0 0 auto; margin-top: 2px; }
.photo-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.photo-row form { flex: 1 1 260px; }
.photo-frame { width: 105px; height: 135px; border: 1px dashed #b9c7c7; border-radius: 8px; display: grid; place-items: center; overflow: hidden; background: #f7fafa; text-align: center; }
.photo-frame img { width: 100%; height: 100%; object-fit: cover; }

.req { color: var(--expired-fg); font-weight: 700; }
textarea { font: inherit; font-weight: 400; padding: 9px 10px; border: 1px solid #b9c7c7; border-radius: 7px; width: 100%; resize: vertical; }
.gaps-form { margin-top: 16px; }
#job-list { margin-bottom: 12px; }
.job-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: #f7fafa; border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; font-size: .9rem; }
.job-row .grow { flex: 1; }
.referee-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.referee-box h3 { margin: 0 0 10px; font-size: 1rem; display: flex; gap: 8px; align-items: center; }
.bank-summary { background: #f7fafa; border-radius: 8px; padding: 8px 12px; font-size: .9rem; }
.doc-group-title { margin: 8px 0 0; font-size: 1.05rem; }
.doc-group-note { margin: 0 0 4px; }
.doc-note { background: #eef6f6; border-left: 3px solid var(--brand); padding: 6px 10px; border-radius: 4px; margin: 0 0 10px; font-size: .85rem; }
.route-choice { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; font-weight: 400; }
.route-choice label { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.route-choice input { width: auto; }
.inline-check { flex-direction: row !important; align-items: center; gap: 8px; font-weight: 500; }
.inline-check input { width: 18px; height: 18px; }
.bank-show { font-family: ui-monospace, Consolas, monospace; }

/* Admin */
.admin-head { flex-wrap: wrap; gap: 10px; }
.admin-name { display: flex; gap: 8px; align-items: flex-end; margin-left: auto; }
.admin-name label { font-size: .8rem; }
.admin-name input { padding: 6px 8px; min-width: 200px; }
.adm-section { border-top: 2px solid var(--line); padding: 14px 0 6px; }
.adm-section h3 { margin: 0 0 10px; font-size: 1.05rem; }
.mini-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; align-items: end; }
.mini-grid label { font-size: .8rem; }
.mini-grid input, .mini-grid select { padding: 6px 8px; font-size: .9rem; }
.ref-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: #f7fafa; border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; font-size: .9rem; }
.ref-row .grow { flex: 1; }
.pdf-box { background: #f1f7f7; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.pdf-box ul { margin: 6px 0 10px; padding-left: 20px; color: var(--expired-fg); font-size: .9rem; }
.dlg-photo { float: right; width: 90px; height: 115px; border-radius: 8px; overflow: hidden; margin: 0 0 10px 14px; background: #f7fafa; border: 1px solid var(--line); }
.dlg-photo img { width: 100%; height: 100%; object-fit: cover; }
.admin-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .n { font-size: 1.7rem; font-weight: 800; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.red .n { color: var(--expired-fg); }
.stat.amber .n { color: var(--uploaded-fg); }
.stat.green .n { color: var(--checked-fg); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.toolbar input { flex: 1 1 240px; }
.toolbar select { flex: 0 1 320px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; color: var(--muted); margin-bottom: 12px; }
.legend .badge { margin-left: 6px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody td { white-space: nowrap; }
tbody td:first-child { white-space: normal; min-width: 160px; }
tbody tr:hover { background: #f1f7f7; }
td .who { font-weight: 600; }
td .email { color: var(--muted); font-size: .8rem; }

dialog {
  width: min(900px, calc(100vw - 32px)); max-height: calc(100vh - 40px);
  border: 0; border-radius: var(--radius); padding: 0; color: var(--text);
}
dialog::backdrop { background: rgba(10, 30, 30, .45); }
.dlg-head {
  position: sticky; top: 0; background: #fff; z-index: 1;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.dlg-head h2 { margin: 0; }
#dlg-body { padding: 16px 20px 24px; }
.details { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; margin: 0 0 20px; font-size: .92rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.adm-doc { border-top: 1px solid var(--line); padding: 12px 0; }
.adm-doc-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.adm-file { background: #f7fafa; border-radius: 8px; padding: 10px 12px; margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.adm-file-info { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .9rem; }
.adm-file-actions, .adm-file-edit { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.adm-file-edit label { font-size: .8rem; }
.adm-file-edit label.grow { flex: 1 1 220px; }
.adm-file-edit input { padding: 6px 8px; font-size: .9rem; }

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .progress-card { flex-direction: column; align-items: stretch; }
  .progress { text-align: left; }
  .details { grid-template-columns: 1fr; gap: 0; }
  .details dd { margin-bottom: 8px; }
  .user-box #user-email { display: none; }
}
