:root {
  --primary: #4DCA77;
  --primary-dark: #35aa5d;
  --primary-soft: #eaf9ef;
  --ink: #172033;
  --muted: #657085;
  --line: #e4e9f0;
  --canvas: #f3f6f9;
  --white: #ffffff;
  --danger: #c73843;
  --danger-soft: #fff0f1;
  --warning: #9a6500;
  --warning-soft: #fff7df;
  --shadow: 0 18px 48px rgba(18, 32, 51, .09);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font: 16px/1.5 "Segoe UI", Arial, sans-serif;
}

.topbar {
  height: 104px;
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100% - 1060px) / 2));
  color: var(--ink);
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; color: var(--ink); text-decoration: none; }
.brand-logo { display: block; width: 142px; height: auto; object-fit: contain; }
.system-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 17px;
  color: white;
  background: #455166;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  transition: background .2s;
}
.system-link:hover { background: #354052; }

.page-shell { width: min(100% - 32px, 1060px); margin: 0 auto; padding: 52px 0 48px; }
.intro { max-width: 670px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 6px; color: var(--primary-dark); font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(31px, 5vw, 46px); line-height: 1.1; letter-spacing: -.035em; }
.intro > p:last-child { color: var(--muted); font-size: 17px; }

.card { background: var(--white); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.search-card { padding: 28px; }
.card-heading { display: flex; gap: 14px; align-items: flex-start; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.card-heading h2 { margin-bottom: 3px; font-size: 20px; }
.card-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.step { flex: 0 0 auto; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; color: white; background: var(--primary); font-weight: 800; }

form { padding-top: 24px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 7px; font-size: 14px; font-weight: 700; }
.field input { width: 100%; min-height: 48px; padding: 0 14px; color: var(--ink); background: white; border: 1px solid #cbd3de; border-radius: 9px; outline: none; font: inherit; transition: border-color .2s, box-shadow .2s; }
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(77, 202, 119, .18); }
.field input.invalid { border-color: var(--danger); }
.field small { min-height: 18px; color: var(--danger); font-size: 12px; font-weight: 500; }
.turnstile-wrap { margin-top: 10px; }
.local-note { margin-top: 10px; padding: 9px 12px; border-radius: 8px; color: #5e6675; background: #f4f6f8; font-size: 13px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.button { min-height: 46px; padding: 0 20px; border: 0; border-radius: 9px; cursor: pointer; font: inherit; font-weight: 700; transition: background .2s, transform .1s; }
.button:active { transform: translateY(1px); }
.button:disabled { cursor: wait; opacity: .65; }
.primary { color: white; background: var(--primary); }
.primary:hover:not(:disabled) { background: var(--primary-dark); }
.secondary { color: #455166; background: #edf1f5; }
.secondary:hover { background: #e1e7ed; }

.feedback { margin-top: 18px; padding: 15px 17px; border: 1px solid; border-radius: 11px; font-weight: 600; }
.feedback.error { color: var(--danger); background: var(--danger-soft); border-color: #facdd1; }
.feedback-message { display: block; }
.feedback-help { display: block; margin-top: 7px; color: #7a3137; font-size: 14px; font-weight: 500; }
.feedback-help a { color: #176c39; font-weight: 750; text-decoration: underline; text-underline-offset: 2px; }
.feedback-help a:hover { color: #10552c; }
.feedback.info { color: #315276; background: #eef6ff; border-color: #cfe4fa; }
.feedback.success { color: var(--primary-dark); background: var(--primary-soft); border-color: #bce4dd; }

.results-card { margin-top: 22px; overflow: hidden; }
.result-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 25px 28px; border-bottom: 1px solid var(--line); }
.result-header h2 { margin-bottom: 2px; font-size: 22px; }
.result-header p { margin-bottom: 0; color: var(--muted); }
.summary { min-width: 140px; padding: 12px 16px; border-radius: 10px; text-align: center; background: var(--primary-soft); }
.summary strong { display: block; color: var(--primary-dark); font-size: 25px; line-height: 1; }
.summary span { color: #54716d; font-size: 12px; }
.invoice-list { padding: 12px 28px 24px; }
.invoice { display: grid; grid-template-columns: 1.1fr .9fr .8fr .8fr auto; gap: 18px; align-items: center; padding: 18px 0; border-bottom: 1px solid var(--line); }
.invoice:last-child { border-bottom: 0; }
.datum { min-width: 0; }
.datum-label { display: block; margin-bottom: 3px; color: var(--muted); font-size: 12px; }
.datum-value { font-weight: 700; }
.status { display: inline-flex; padding: 5px 9px; border-radius: 999px; font-size: 13px; font-weight: 800; }
.status.overdue { color: var(--danger); background: var(--danger-soft); }
.status.pending { color: var(--warning); background: var(--warning-soft); }
.invoice-action { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.open-link { display: inline-flex; align-items: center; justify-content: center; min-width: 92px; min-height: 42px; padding: 0 15px; border-radius: 8px; color: white; background: var(--primary); font-size: 14px; font-weight: 750; text-decoration: none; white-space: nowrap; }
.open-link:hover { background: var(--primary-dark); }
.report-link { color: white; background: #455166; }
.report-link:hover { background: #354052; }
.no-link { color: var(--muted); font-size: 13px; }
.invoice-note {
  margin-top: 16px;
  padding: 13px 15px;
  color: #506077;
  background: #f3f7f5;
  border-left: 4px solid var(--primary);
  border-radius: 7px;
  font-size: 14px;
}
.invoice-note p { margin: 4px 0 0; }
.empty { padding: 32px 0 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; margin-bottom: 5px; color: var(--primary-dark); font-size: 19px; }

.admin-shell { width: min(100% - 32px, 1320px); }
.admin-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.admin-heading h1 { margin-bottom: 4px; }
.admin-heading p:last-child { margin-bottom: 0; color: var(--muted); }
.download-link { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 17px; border-radius: 7px; color: white; background: var(--primary-dark); font-weight: 700; text-decoration: none; white-space: nowrap; }
.download-link:hover { background: #268b4a; }
.admin-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
.access-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.access-table th, .access-table td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.access-table th { color: #455166; background: #f7f9fb; font-size: 13px; white-space: nowrap; }
.access-table tbody tr:last-child td { border-bottom: 0; }
.log-status { display: inline-flex; padding: 4px 8px; border-radius: 999px; color: #344054; background: #e9eef3; font-size: 12px; font-weight: 700; white-space: nowrap; text-transform: capitalize; }
.admin-session { margin: 14px 0 0; color: var(--muted); font-size: 13px; text-align: right; }

footer { display: flex; justify-content: center; width: min(100% - 32px, 1060px); margin: 0 auto; padding: 0 0 28px; color: #7a8495; font-size: 13px; text-align: center; }
[hidden] { display: none !important; }

@media (max-width: 800px) {
  .page-shell { padding-top: 34px; }
  .form-grid { grid-template-columns: 1fr; gap: 7px; }
  .invoice { grid-template-columns: 1fr 1fr; }
  .invoice-action { grid-column: 1 / -1; }
  .open-link { flex: 1; }
  .admin-heading { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 520px) {
  .topbar { height: 88px; padding: 0 16px; }
  .brand-logo { width: 124px; }
  .system-link { min-height: 40px; padding: 0 12px; font-size: 12px; }
  .search-card { padding: 21px 18px; }
  .form-actions { flex-direction: column; }
  .result-header { align-items: flex-start; padding: 21px 18px; }
  .summary { min-width: 108px; }
  .invoice-list { padding: 8px 18px 20px; }
  .invoice { grid-template-columns: 1fr; gap: 10px; }
  .invoice-action { grid-column: auto; }
  footer { flex-direction: column; gap: 3px; }
}
