:root {
  --brand-blue: #245EA9;
  --brand-blue-dark: #1A4884;
  --brand-orange: #EA5B19;
  --brand-orange-dark: #C44C11;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --text: #1a2233;
  --muted: #5a6578;
  --border: #e3e8f0;
  --ok: #1e8e3e;
  --warn: #b25b00;
  --danger: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(10, 30, 60, 0.06), 0 4px 12px rgba(10, 30, 60, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }

/* Gate */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-blue-dark) 100%);
}
.gate-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  max-width: 420px;
  width: 100%;
}
.gate-card h1 {
  font-size: 1.4rem;
  color: var(--brand-blue);
  margin-bottom: 6px;
}
.gate-card form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.gate-card label { font-weight: 600; font-size: 0.9rem; }
.gate-card input {
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
.gate-card input:focus { border-color: var(--brand-blue); box-shadow: 0 0 0 3px rgba(10,77,140,0.15); }

/* App layout */
.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-logo {
  height: 44px;
  width: auto;
  display: block;
}
.gate-logo {
  height: 64px;
  width: auto;
  display: block;
  margin: 0 auto 12px;
}
.who {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.who strong {
  min-width: 0;
  overflow-wrap: anywhere;
}
.page-header {
  padding: 4px 4px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.page-header h1 {
  color: var(--brand-blue);
  font-size: 1.55rem;
  line-height: 1.15;
}
.page-header p {
  margin: 4px 0 0;
  font-size: 1rem;
}

/* Toolbar */
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.toolbar input[type="search"] {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 1rem;
}
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  cursor: pointer;
}
.filter.is-active {
  background: var(--brand-blue);
  color: white;
  border-color: var(--brand-blue);
}
.actions { display: flex; gap: 6px; }

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
}
.btn:hover:not(:disabled) { background: #f1f4f9; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--brand-orange);
  border-color: var(--brand-orange);
  color: white;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-orange-dark); }
.btn-link {
  background: transparent;
  border: none;
  color: var(--brand-blue);
  text-decoration: underline;
  padding: 0;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Status bar */
.status-bar {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
  min-height: 1.2em;
}

/* List */
.list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 4px solid var(--brand-blue);
}
.card.is-paid { border-left-color: var(--ok); }
.card.is-exempt { border-left-color: var(--muted); }
.card.is-completed { border-left-color: var(--brand-orange); opacity: 0.75; }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-head .name { font-size: 1.05rem; }
.card-head .meta { margin-top: 2px; }

.badges { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge.hidden { display: none; }
.badge.size {
  background: var(--brand-blue);
  color: white;
}
.badge.status.open    { background: #fff3e0; color: var(--warn); }
.badge.status.paid    { background: #e7f5ec; color: var(--ok); }
.badge.status.exempt  { background: #eef1f6; color: var(--muted); }
.badge.status.completed { background: #fde9d2; color: var(--brand-orange-dark); }

.card-body { display: flex; gap: 12px; align-items: flex-start; }
.qr {
  width: 130px; height: 130px;
  flex: 0 0 130px;
  display: grid; place-items: center;
  background: #fafbfd;
  border: 1px dashed var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.qr.hidden-qr { display: none; }
.qr img, .qr canvas, .qr svg { width: 100%; height: 100%; display: block; }
.info { display: flex; flex-direction: column; gap: 4px; }
.amount { font-weight: 600; }

.card-foot { display: flex; justify-content: flex-end; gap: 8px; }
.action { min-width: 130px; }

/* Empty / error */
.empty, .error {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  margin-top: 16px;
}
.error { border-color: #f4c7c5; background: #fdecea; color: var(--danger); text-align: left; }

.footer { margin: 24px 4px 8px; text-align: center; }

/* Responsive */
@media (max-width: 720px) {
  .app {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
    gap: 10px;
    padding: 6px 2px 8px;
  }

  .brand-logo {
    height: 38px;
  }

  .who {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 2px;
    text-align: right;
  }

  .who .small {
    flex-basis: 100%;
  }

  .page-header {
    padding: 4px 2px 14px;
    margin-bottom: 12px;
  }

  .page-header h1 {
    font-size: 1.35rem;
  }

  .toolbar {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .toolbar input[type="search"],
  .btn,
  .filter {
    min-height: 44px;
  }

  .filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .filter {
    border-radius: 8px;
    padding: 8px 10px;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .list {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 12px;
  }

  .card-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .card-body {
    gap: 10px;
  }

  .qr {
    width: 112px;
    height: 112px;
    flex-basis: 112px;
  }

  .card-foot,
  .action {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .card-head,
  .card-body {
    display: grid;
    grid-template-columns: 1fr;
  }

  .badges {
    align-items: flex-start;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .qr {
    width: 100%;
    max-width: 160px;
    height: auto;
    aspect-ratio: 1;
    flex-basis: auto;
  }
}
