:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #f0f3f6;
  --text: #18202b;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #0f766e;
  --accent-strong: #0b5d57;
  --blue: #2563eb;
  --amber: #b45309;
  --amber-bg: #fff7ed;
  --red: #c92828;
  --red-bg: #fff1f2;
  --green-bg: #ecfdf5;
  --shadow: 0 18px 45px rgba(24, 32, 43, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, #ffffff 0, var(--bg) 360px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar,
main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 0 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

.top-actions,
.button-row,
.section-heading,
.filter-box,
.chip,
.summary-card,
.summary-title,
.date-row,
.ghost-button,
.primary-button,
.secondary-button {
  display: flex;
  align-items: center;
}

.top-actions,
.button-row {
  gap: 10px;
  flex-wrap: wrap;
}

.section-heading {
  justify-content: space-between;
  gap: 14px;
  min-height: 40px;
}

.ghost-button,
.primary-button,
.secondary-button,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
  letter-spacing: 0;
}

.ghost-button,
.secondary-button {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.ghost-button {
  gap: 7px;
}

.ghost-button.compact {
  min-height: 34px;
  padding: 0 10px;
  font-size: 14px;
}

.primary-button {
  gap: 8px;
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent-strong);
}

.secondary-button {
  gap: 8px;
}

.icon-button {
  width: 40px;
  padding: 0;
  color: var(--muted);
  background: var(--surface-strong);
  border-color: var(--line);
  font-size: 24px;
  line-height: 1;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 10px 0 18px;
}

.stat {
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.stat.alert {
  border-color: #f2c48a;
  background: var(--amber-bg);
}

.stat.danger {
  border-color: #fecdd3;
  background: var(--red-bg);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, 0.95fr);
  gap: 18px;
  align-items: stretch;
}

.input-pane,
.result-pane,
.records-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.input-pane,
.result-pane {
  padding: 18px;
}

.records-section {
  margin: 18px 0 36px;
  padding: 18px;
}

#dateInput {
  width: 154px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
}

textarea {
  display: block;
  width: 100%;
  min-height: 330px;
  margin: 16px 0 12px;
  padding: 14px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfd;
  outline: none;
}

textarea:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.extracted {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.chip {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: #0f3f3b;
  background: var(--green-bg);
  border: 1px solid #99f6e4;
  font-weight: 800;
  white-space: nowrap;
}

.result-pane {
  min-height: 100%;
}

.summary-empty {
  margin-top: 18px;
  padding: 26px 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: #fbfcfd;
}

.summary-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.summary-card {
  align-items: flex-start;
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.summary-card.warn {
  border-color: #f2c48a;
  background: var(--amber-bg);
}

.summary-card.danger {
  border-color: #fecdd3;
  background: var(--red-bg);
}

.summary-card.ok {
  border-color: #bbf7d0;
  background: var(--green-bg);
}

.summary-marker {
  display: grid;
  place-items: center;
  width: 34px;
  min-width: 34px;
  height: 34px;
  border-radius: 8px;
  color: white;
  background: var(--accent);
  font-weight: 900;
}

.summary-card.warn .summary-marker {
  background: var(--amber);
}

.summary-card.danger .summary-marker {
  background: var(--red);
}

.summary-main {
  min-width: 0;
  flex: 1;
}

.summary-title {
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
}

.summary-title span:first-child {
  word-break: break-all;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--muted);
  background: #eef2f7;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.summary-card.warn .badge {
  color: #7c2d12;
  background: #fed7aa;
}

.summary-card.danger .badge {
  color: #7f1d1d;
  background: #fecdd3;
}

.detail {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.similar-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  padding: 0;
  list-style: none;
}

.similar-list li {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  color: #3f2a08;
  font-size: 14px;
}

.filter-box {
  width: min(280px, 100%);
  min-height: 38px;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.filter-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.records-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.45fr);
  gap: 16px;
  margin-top: 14px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
  background: var(--surface);
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 13px;
  font-weight: 900;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.plate-text {
  font-weight: 900;
  letter-spacing: 0;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--text);
  background: #eef2f7;
  font-weight: 900;
}

.count-pill.repeat {
  color: #7c2d12;
  background: #fed7aa;
}

.count-pill.critical {
  color: #7f1d1d;
  background: #fecdd3;
}

.date-list {
  color: var(--muted);
  font-size: 14px;
}

.timeline {
  display: grid;
  align-content: start;
  gap: 10px;
}

.date-row {
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.date-row strong {
  display: block;
  white-space: nowrap;
}

.date-records {
  display: grid;
  justify-items: end;
  gap: 8px;
  min-width: 0;
}

.date-count {
  color: var(--muted);
  text-align: right;
  font-size: 14px;
}

.record-chip-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.record-edit-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  max-width: 100%;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
  font-weight: 800;
}

.record-edit-button:hover,
.record-edit-button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.record-plate {
  word-break: break-all;
}

.record-action {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  max-width: min(360px, calc(100% - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: white;
  background: var(--text);
  box-shadow: var(--shadow);
  font-weight: 800;
}

.toast.error {
  background: var(--red);
}

.edit-dialog {
  width: min(420px, calc(100% - 28px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
}

.edit-dialog::backdrop {
  background: rgba(24, 32, 43, 0.32);
}

.edit-dialog-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.edit-context {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.edit-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.edit-field input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfd;
  font-size: 18px;
  font-weight: 900;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-row,
  .workspace,
  .records-grid {
    grid-template-columns: 1fr;
  }

  .stat {
    min-height: 82px;
  }

  textarea {
    min-height: 280px;
  }
}

@media (max-width: 560px) {
  .topbar,
  main {
    width: min(100% - 20px, 1180px);
  }

  h1 {
    font-size: 24px;
  }

  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  #dateInput,
  .filter-box {
    width: 100%;
  }

  .primary-button,
  .secondary-button {
    flex: 1 1 138px;
    justify-content: center;
  }

  .summary-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .date-row {
    align-items: stretch;
    flex-direction: column;
  }

  .date-records,
  .record-chip-list {
    justify-items: start;
    justify-content: flex-start;
  }
}
