:root {
  color-scheme: light;
  --bg: #eef2f5;
  --paper: #ffffff;
  --ink: #1c2833;
  --muted: #5c6b78;
  --line: #d5dee6;
  --blue: #0b5cab;
  --blue-dark: #084984;
  --danger-bg: #fdecec;
  --danger-ink: #8d1d1d;
  --ok: #0e7a45;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  padding: 28px 32px 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 13px;
  letter-spacing: 0.04em;
}

h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: 0;
}

h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 650;
}

.dispatch {
  margin-top: 36px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.saved-summary {
  margin: 0 0 12px;
  color: var(--muted);
}

.save-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.save-bar select {
  width: auto;
  min-width: 240px;
}

.save-bar .note {
  flex-basis: 100%;
  margin: 0;
}

.modal[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(20, 32, 44, 0.45);
}

.modal-card {
  width: min(640px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  padding: 20px 22px 24px;
  border-radius: 10px;
  background: var(--paper);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-head h2 { margin: 0; }

.agency-list {
  margin: 12px 0;
  padding: 0;
  list-style: none;
}

.agency-list li {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.agency-list input { flex: 1; min-width: 0; }

.agency-empty { color: var(--muted); }

.agency-form {
  display: flex;
  gap: 8px;
}

.agency-form input { flex: 1; min-width: 0; }

tr.filled-from-store { background: #f3f8fc; }

.records { min-width: 1280px; }

.filters {
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px 16px;
}

.filter-grid > label,
.filter-grid > .field,
.edit-form label,
.pager label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.field-caption { line-height: 1.4; }

.name-field,
.date-range { grid-column: span 2; }

.name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.name-row input[type="text"] {
  flex: 1;
  min-width: 0;
}

.date-picker { position: relative; }

.date-picker-label { cursor: pointer; }

.date-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  width: 280px;
  padding: 10px 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 8px 24px rgba(20, 32, 44, 0.12);
}

.date-panel[hidden] { display: none !important; }

.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.date-nav strong {
  font-size: 14px;
  font-weight: 650;
}

.date-nav-btn {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.date-nav-btn:hover { background: #f3f8fc; }

.date-week,
.date-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.date-week span {
  color: var(--muted);
  font-size: 12px;
  line-height: 24px;
  text-align: center;
}

.date-day {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.date-day:hover { background: #f3f8fc; }

.date-day.outside { color: #9aabba; }

.date-day.today { box-shadow: inset 0 0 0 1px var(--blue); }

.date-day.in-range { background: #e7f1fa; }

.date-day.is-edge,
.date-day.is-edge:hover {
  background: var(--blue);
  color: #fff;
}

.filter-grid select {
  width: 100%;
  min-height: 38px;
}

.filter-actions,
.pager,
.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.filters .filter-actions {
  justify-content: flex-end;
  flex-wrap: nowrap;
  margin-top: 14px;
}

.check-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--ink);
  white-space: nowrap;
}

.records input[type="date"] {
  min-width: 0;
}

.pager {
  justify-content: space-between;
  margin-top: 12px;
}

.pager p { margin: 0; }

.pager select { width: auto; min-width: 88px; }

.check-col { width: 42px; }

input[type="checkbox"] {
  width: auto;
  min-width: 0;
}

.edit-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

.edit-form .filter-actions { grid-column: 1 / -1; }

#edit-reg { background: #f7fafc; }

.lead {
  max-width: 760px;
  margin: 8px 0 0;
  color: var(--muted);
}

main {
  padding: 24px 32px 48px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { background: var(--blue-dark); }

.btn:disabled {
  background: #b7c3ce;
  cursor: not-allowed;
}

.btn.ghost {
  background: #fff;
  color: var(--blue);
  border: 1px solid var(--blue);
}

.btn.ghost:hover { background: #f3f8fc; }

.dropzone {
  position: relative;
  padding: 36px 24px;
  border: 1.5px dashed #8eaccc;
  border-radius: 10px;
  background: var(--paper);
  text-align: center;
  cursor: pointer;
}

.dropzone.dragover {
  border-color: var(--blue);
  background: #f3f8fc;
}

.dropzone input {
  display: none;
}

.drop-title {
  margin: 0;
  font-size: 18px;
}

.drop-hint,
.note {
  margin: 6px 0 0;
  color: var(--muted);
}

.status {
  min-height: 1.5em;
  margin: 14px 0 0;
  color: var(--ink);
}

.status.error { color: var(--danger-ink); }

.result { margin-top: 20px; }

.result-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 10px;
}

.result-bar p { margin: 0; }

.result-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

#result table { min-width: 1720px; }

#result th:nth-child(2),
#result td:nth-child(2),
#result th:nth-child(3),
#result td:nth-child(3),
#result th:nth-child(4),
#result td:nth-child(4),
#result th:nth-child(12),
#result td:nth-child(12),
.nowrap {
  white-space: nowrap;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1120px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f7fafc;
  font-weight: 650;
  font-size: 13px;
  color: #314250;
}

tr:last-child td { border-bottom: 0; }

tr.incomplete { background: var(--danger-bg); }

td.filename {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12.5px;
  word-break: break-all;
}

input {
  width: 100%;
  min-width: 120px;
  padding: 7px 8px;
  border: 1px solid #c5d0da;
  border-radius: 5px;
  font: inherit;
  color: inherit;
  background: #fff;
}

tr.incomplete input { border-color: #e3b4b4; }

input:focus {
  outline: 2px solid rgba(11, 92, 171, 0.25);
  border-color: var(--blue);
}

.login-wrap {
  display: flex;
  justify-content: center;
  padding-top: 12vh;
}

.login-card {
  width: min(420px, 100%);
  padding: 28px 28px 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 18px 0 16px;
}

.login-card .btn { width: 100%; }

@media (max-width: 720px) {
  .top,
  main { padding-left: 16px; padding-right: 16px; }
  .top,
  .result-bar { flex-direction: column; align-items: stretch; }
}
