/* ==========================================================================
   1. Theme and Reset
   ========================================================================== */

:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #687386;
  --line: #e4e9f0;
  --primary: #2457d6;
  --primary-dark: #1d46ae;
  --danger: #b42318;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(18, 33, 61, 0.04);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}


/* ==========================================================================
   2. Typography
   ========================================================================== */

h1,
h2,
p {
  margin-top: 0;
}

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

h2 {
  margin-bottom: 18px;
  font-size: 20px;
  line-height: 1.3;
}

small,
.muted {
  color: var(--muted);
}


/* ==========================================================================
   3. Main Layout and Header
   ========================================================================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 12px 5%;
  background: #101827;
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.brand {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.brand span {
  color: #9eacc2;
  font-weight: 400;
}

.brand.large {
  font-size: 28px;
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px 22px;
}

.topbar nav a {
  color: #dce5f5;
  font-weight: 600;
  white-space: nowrap;
}

.container {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 32px 24px;
}

.footer {
  padding: 30px 20px;
  color: var(--muted);
  text-align: center;
}


/* ==========================================================================
   4. Page Headers, Cards, and Status Elements
   ========================================================================== */

.hero,
.company-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.hero p {
  margin-bottom: 0;
  color: var(--muted);
}

.user-badge {
  flex: 0 0 auto;
  padding: 8px 13px;
  border-radius: 20px;
  background: #e8eefc;
  color: #1d46ae;
  font-weight: 700;
}

.card {
  margin-bottom: 22px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.empty {
  padding: 70px 20px;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius);
  background: #ffffff;
  text-align: center;
}

.empty h2 {
  margin-bottom: 6px;
}

.empty-cell {
  padding: 45px !important;
  color: var(--muted);
  text-align: center;
}

.alert {
  margin: 15px 0;
  padding: 12px;
  border-radius: 8px;
}

.error {
  background: #fef3f2;
  color: var(--danger);
}


/* ==========================================================================
   5. Buttons, Inputs, and Filters
   ========================================================================== */

input,
select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #ccd5e2;
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 87, 214, 0.11);
}

label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 15px;
  border: 1px solid #ccd5e2;
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: #f5f7fa;
  text-decoration: none;
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

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

.btn.small {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 13px;
}

.btn.full {
  width: 100%;
  margin-top: 20px;
}

.searchbar {
  display: flex;
  gap: 10px;
}

.searchbar input {
  flex: 1;
  min-width: 0;
}

.large-search {
  margin-bottom: 25px;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-row label {
  margin: 0;
  white-space: nowrap;
}

.filter-row select {
  width: auto;
  min-width: 170px;
}

.filter-form {
  margin-bottom: 22px;
}


/* ==========================================================================
   6. Statistics and Detail Layouts
   ========================================================================== */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin: 25px 0;
}

.stat {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.stat strong {
  display: block;
  font-size: 30px;
}

.stat span {
  color: var(--muted);
}

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

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

.detail-item {
  padding: 12px;
  border-radius: 8px;
  background: #f8fafc;
}

.detail-item label {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
}

.detail-item div {
  overflow-wrap: anywhere;
}

.relation {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.relation:first-of-type {
  border-top: 0;
}

.relation-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.relation-head small {
  flex: 0 0 auto;
  color: var(--muted);
}

.back {
  margin-bottom: 15px;
}


/* ==========================================================================
   7. Tables and Pagination
   ========================================================================== */

.result-head {
  margin: 10px 0 14px;
  color: var(--muted);
}

.result-head strong {
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

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

th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #fafcff;
}

td small {
  display: block;
  margin-top: 2px;
}

.pill,
.count {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 20px;
  background: #edf2ff;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.pagination a,
.pagination span {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.pagination .active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}


/* ==========================================================================
   8. Login Page
   ========================================================================== */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 12px 35px rgba(18, 33, 61, 0.07);
}


/* ==========================================================================
   9. Mobile and Tablet Layout
   ========================================================================== */

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    gap: 12px;
  }

  .topbar nav {
    gap: 8px 14px;
  }

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

  .filter-row {
    align-items: stretch;
  }

  .filter-row label {
    width: 100%;
  }

  .filter-row select,
  .filter-row .btn {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    padding: 14px 18px;
  }

  .topbar nav {
    justify-content: flex-start;
    width: 100%;
  }

  .container {
    padding: 24px 14px;
  }

  h1 {
    font-size: 26px;
  }

  h2 {
    font-size: 18px;
  }

  .hero,
  .company-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .user-badge {
    align-self: flex-start;
  }

  .card {
    padding: 16px;
  }

  .searchbar {
    flex-direction: column;
  }

  .searchbar .btn {
    width: 100%;
  }

  .detail-grid,
  .detail-grid.compact {
    grid-template-columns: 1fr;
  }

  .relation-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .pagination {
    justify-content: center;
  }

  .login-card {
    padding: 24px;
  }

  .brand.large {
    font-size: 25px;
  }
}

/* Associated-record tabs */

.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.section-heading h2 {
  margin: 0;
}

.record-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 20px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  -webkit-overflow-scrolling: touch;
}

.record-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.record-tab:hover {
  background: #eef3ff;
  color: var(--primary);
}

.record-tab[aria-selected="true"] {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(18, 33, 61, 0.12);
}

.record-tab span {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 20px;
  background: #edf2ff;
  color: var(--primary);
  font-size: 12px;
  text-align: center;
}

.tab-panel[hidden] {
  display: none;
}

.tab-empty {
  padding: 35px 20px;
}

.tab-empty p {
  margin: 0;
}

@media (max-width: 640px) {
  .record-tabs {
    margin-right: -2px;
    margin-left: -2px;
  }

  .record-tab {
    padding: 9px 12px;
    font-size: 13px;
  }
}