*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; font-family: inherit; }
select, input { font-family: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Shell ---------- */
#mainApp {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: .75rem;
  gap: .75rem;
  overflow: hidden;
}
@media (min-width: 768px) { #mainApp { padding: 1.25rem 1.5rem; gap: 1rem; } }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  flex-shrink: 0;
  position: relative;
}
/* the one memorable detail: a thin tricolor edge echoing the BJMP seal */
.app-header::before {
  content: "";
  position: absolute;
  left: 1rem; right: 1rem; top: -1px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--primary);
}

.header-brand { display: flex; align-items: center; gap: .875rem; min-width: 0; }
.header-logo { width: 44px; height: 44px; object-fit: contain; flex-shrink: 0; }
@media (min-width: 640px) { .header-logo { width: 52px; height: 52px; } }

.header-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (min-width: 640px) { .header-title { font-size: 1.2rem; } }

.header-subtitle {
  font-size: .75rem;
  color: var(--muted);
  margin-top: 1px;
  display: none;
}
@media (min-width: 640px) { .header-subtitle { display: block; } }

.header-actions { display: flex; align-items: center; gap: .625rem; flex-shrink: 0; }

.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 .75rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--bad);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
}
.btn-logout:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-logout span { display: none; }
@media (min-width: 640px) { .btn-logout span { display: inline; } }

/* ---------- Search ---------- */
.search-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: .875rem 1rem;
  flex-shrink: 0;
}

#searchForm {
  display: grid;
  grid-template-columns: 1fr;
  gap: .75rem;
  align-items: end;
}
@media (min-width: 560px) { #searchForm { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { #searchForm { grid-template-columns: 1.1fr 2.6fr .9fr auto; } }

.form-label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 5px;
}

.form-control {
  width: 100%;
  height: 40px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 0 .75rem;
  font-size: .9rem;
  color: var(--ink);
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
}
.form-control::placeholder { color: var(--faint); }
.form-control:hover { border-color: var(--faint); }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); background: var(--surface); }

.btn-search {
  height: 40px;
  width: 100%;
  padding: 0 1.25rem;
  background: var(--primary);
  color: var(--primary-ink);
  border: 0;
  border-radius: var(--r-sm);
  font-size: .9rem;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color var(--ease), transform var(--ease);
}
@media (min-width: 900px) { .btn-search { width: auto; } }
.btn-search:hover { background: var(--primary-hover); }
.btn-search:active { transform: translateY(1px); }
.btn-search:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Data ---------- */
.data-container {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.table-wrap { display: none; flex: 1 1 auto; overflow: auto; min-height: 0; }
@media (min-width: 768px) { .table-wrap { display: block; } }

table { width: 100%; border-collapse: separate; border-spacing: 0; }

thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-strong);
  padding: .7rem 1rem;
  font-size: .75rem;
  font-weight: 650;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
}

tbody td {
  padding: .65rem 1rem;
  font-size: .85rem;
  color: var(--ink-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td:nth-child(1) { font-family: var(--font-num); font-size: .8rem; color: var(--ink); }
tbody td:nth-child(3) { font-weight: 650; color: var(--ink); }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

.placeholder-cell { padding: 3.5rem 1rem; text-align: center; color: var(--muted); white-space: normal; }
.placeholder-cell svg { margin: 0 auto .5rem; display: block; }

/* ---------- Mobile cards ---------- */
#mobileCardsContainer { display: block; flex: 1 1 auto; overflow-y: auto; min-height: 0; }
@media (min-width: 768px) { #mobileCardsContainer { display: none; } }

.mobile-card { padding: .875rem 1rem; border-bottom: 1px solid var(--line); }
.mobile-card:last-child { border-bottom: 0; }
.card-row { display: flex; align-items: flex-start; gap: .5rem; font-size: .85rem; padding: 2px 0; }
.card-label { width: 112px; flex-shrink: 0; font-size: .72rem; font-weight: 600; color: var(--muted); padding-top: 1px; }
.card-value { color: var(--ink); min-width: 0; overflow-wrap: anywhere; }

/* ---------- Status badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 2px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 650;
  text-transform: capitalize;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-active   { background: var(--ok-soft);  color: var(--ok); }
.badge-inactive { background: var(--bad-soft); color: var(--bad); }

/* ---------- Loading ---------- */
.spinner-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem; padding: 3rem 1rem; color: var(--muted); text-align: center; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--primary); animation: spin .8s linear infinite; }
.spinner-text { font-size: .85rem; font-weight: 500; color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pagination ---------- */
#tableFooter {
  display: none;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  padding: .6rem 1rem;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}
#tableFooter.visible { display: flex; }
.pagination-info { font-size: .78rem; color: var(--muted); }
.pagination-info strong { color: var(--ink); font-weight: 650; }
.pagination-controls { display: flex; align-items: center; gap: .5rem; }

.btn-page {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 .75rem;
  font-size: .78rem;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  transition: background-color var(--ease), border-color var(--ease);
}
.btn-page:hover:not(:disabled) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.btn-page:disabled { opacity: .4; cursor: not-allowed; }
.page-label { font-size: .78rem; color: var(--muted); min-width: 92px; text-align: center; }
.page-label strong { color: var(--ink); }

/* ---------- Footer ---------- */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  padding: 0 .25rem;
  flex-shrink: 0;
}
.footer-copy { font-size: .75rem; color: var(--muted); }
.footer-dev { display: inline-flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--muted); }
.footer-dev .accent { color: var(--brass); font-weight: 650; }

/* ---------- Icons ---------- */
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 32px; height: 32px; }
.icon-slate { color: var(--faint); }
.icon-emerald { color: var(--ok); }
