:root {
  --ink: #0f1b2d;
  --paper: #f6f8fb;
  --card: #ffffff;
  --line: #dfe6f0;
  --brand: #1d5fd6;
  --brand-dark: #123f96;
  --ok: #1a8a5f;
  --ok-bg: #e4f6ee;
  --warn: #b3781c;
  --warn-bg: #fdf1de;
  --danger: #c5342f;
  --danger-bg: #fbe8e7;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
}

.app-header {
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #fff;
  padding: 2rem 1.5rem 2.4rem;
  text-align: center;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.brand-mark {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 6px;
  background: #fff;
  clip-path: polygon(0 0, 100% 0, 100% 60%, 60% 60%, 60% 100%, 0 100%);
}

.app-header h1 {
  margin: 0;
  font-size: 1.9rem;
  letter-spacing: -0.02em;
}

.tagline {
  max-width: 40rem;
  margin: 0.6rem auto 0;
  opacity: 0.92;
  font-size: 1.02rem;
}

main {
  max-width: 1080px;
  margin: -1.6rem auto 0;
  padding: 0 1.5rem 3rem;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.summary-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  box-shadow: 0 6px 20px rgba(15, 27, 45, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.summary-label {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5a6b83;
}

.summary-value {
  font-size: 1.7rem;
  font-weight: 700;
}

.summary-card--warn .summary-value { color: var(--warn); }
.summary-card--danger .summary-value { color: var(--danger); }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.2rem;
  padding: 0.9rem 1.1rem;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(15, 27, 45, 0.06);
}

.toggle, .sort {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.sort select {
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
  background: #fff;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: 0 4px 14px rgba(15, 27, 45, 0.06);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(15, 27, 45, 0.12);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.card h3 {
  margin: 0;
  font-size: 1.05rem;
}

.card .category {
  font-size: 0.78rem;
  color: #5a6b83;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}

.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--violation { background: var(--danger-bg); color: var(--danger); }

.card .cost {
  font-size: 1.3rem;
  font-weight: 700;
}

.card .refund-line {
  font-size: 0.86rem;
  color: var(--danger);
  font-weight: 600;
}

.card .status-line {
  font-size: 0.82rem;
  color: #5a6b83;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 27, 45, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 10;
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: #fff;
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  padding: 1.6rem;
  position: relative;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.modal-close {
  position: absolute;
  top: 0.8rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: #5a6b83;
  line-height: 1;
}

.rule-item {
  display: flex;
  gap: 0.6rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

.rule-item:last-child { border-bottom: none; }

.rule-item .icon { flex-shrink: 0; font-size: 1.1rem; }
.rule-item.pass .icon { color: var(--ok); }
.rule-item.fail .icon { color: var(--danger); }
.rule-item .citation { display: block; color: #5a6b83; font-size: 0.82rem; margin-top: 0.15rem; }

.letter-btn {
  margin-top: 1rem;
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
}

.letter-btn:hover { background: var(--brand-dark); }

.letter-box {
  margin-top: 1rem;
  background: #f5f7fb;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem;
  white-space: pre-wrap;
  font-family: "Courier New", monospace;
  font-size: 0.85rem;
  line-height: 1.5;
}

.app-footer {
  text-align: center;
  padding: 1.5rem;
  color: #7a8aa3;
  font-size: 0.85rem;
}

@media (max-width: 560px) {
  .app-header { padding: 1.6rem 1rem 2rem; }
  main { margin-top: -1.2rem; padding: 0 1rem 2rem; }
  .controls { flex-direction: column; align-items: stretch; }
}
