:root {
  --orange: #E8821C;
  --orange-dark: #C96B0F;
  --cream: #F5EFE9;
  --text-dark: #1a1a1a;
  --white: #ffffff;
  --border: #ddd0c2;

  --status-active: #2f8f4e;
  --status-onboarding: #2f6f8f;
  --status-sunset: #b8860b;
  --status-inactive: #888888;
  --status-furlough: #8f6f2f;
  --status-declined: #b03030;
}

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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-dark);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  color: var(--orange-dark);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ---- header ---- */

header {
  background-color: var(--orange);
  padding: 1.25rem 1.5rem;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.site-title {
  color: var(--text-dark);
  font-size: 1.4rem;
  font-weight: 600;
}
.site-title:hover {
  text-decoration: none;
}

header nav a {
  color: var(--text-dark);
  margin-left: 1.25rem;
  font-weight: 500;
}
header nav a:first-child {
  margin-left: 0;
}

/* ---- main ---- */

main {
  background-color: var(--cream);
  flex: 1;
  padding: clamp(1.5rem, 5vw, 3rem);
}

.page-title {
  max-width: 1100px;
  margin: 0 auto 1.5rem;
  font-size: 1.6rem;
  font-weight: 600;
}

.page-content {
  max-width: 1100px;
  margin: 0 auto;
}

/* ---- footer ---- */

footer {
  background-color: var(--orange);
  padding: 1.25rem 1.5rem;
  text-align: center;
  font-size: 0.85rem;
}

/* ---- filter bar ---- */

.filter-bar {
  max-width: 1100px;
  margin: 0 auto 1.5rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: end;
}

.filter-bar .field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.filter-bar label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
}

.filter-bar select,
.filter-bar input[type="text"] {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  min-width: 160px;
}

.filter-bar .actions {
  display: flex;
  gap: 0.5rem;
}

.result-count {
  max-width: 1100px;
  margin: 0 auto 0.75rem;
  color: #666;
  font-size: 0.9rem;
}

.default-view-note {
  color: #999;
  font-style: italic;
}

/* ---- table ---- */

.roster-table-wrap {
  max-width: 1100px;
  margin: 0 auto;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

table.roster {
  width: 100%;
  border-collapse: collapse;
}

table.roster th,
table.roster td {
  padding: 0.7rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

/* Headers are short, fixed labels ("CARD NUMBER") — fine to keep on one
   line. Data cells default to wrapping: any column can end up holding a
   long value (an email as a username, a long note), and forcing every
   column onto one line is what made these tables wider than their card
   even on a full desktop screen. table-layout:fixed makes the browser
   actually respect the table's own width instead of growing columns to
   fit unbroken content — the pairing of the two is what stops the overflow. */
table.roster {
  table-layout: fixed;
}

table.roster td {
  white-space: normal;
  word-break: break-word;
}

table.roster th {
  white-space: nowrap;
  background: var(--cream);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #555;
}

table.roster .sortable-header {
  color: inherit;
  text-decoration: none;
}
table.roster .sortable-header:hover {
  color: var(--orange-dark);
  text-decoration: underline;
}

table.roster tbody tr:hover {
  background: #fbf7f2;
}

table.roster tbody tr.row-sunset {
  background: #fde2e7;
}
table.roster tbody tr.row-sunset:hover {
  background: #fbd2da;
}

table.roster td.name a {
  font-weight: 600;
  color: var(--text-dark);
}

.empty-state {
  padding: 2.5rem 1rem;
  text-align: center;
  color: #888;
}

/* ---- badges ---- */

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--white);
  white-space: nowrap;
}

.badge-status-active     { background: var(--status-active); }
.badge-status-onboarding { background: var(--status-onboarding); }
.badge-status-sunset     { background: var(--status-sunset); }
.badge-status-inactive   { background: var(--status-inactive); }
.badge-status-furlough   { background: var(--status-furlough); }
.badge-status-declined   { background: var(--status-declined); }

.badge-category {
  background: var(--orange-dark);
}

/* ---- pill filters (subtenants.php) ---- */

.pill-group {
  max-width: 1100px;
  margin: 0 auto 1.1rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.pill-group-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #666;
  margin-right: 0.25rem;
}

.pill-filter {
  display: inline-block;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  /* A visibly darker border + subtle shadow than the plain outline this
     replaced — on the cream page background, a near-invisible border made
     unselected pills blend into one long run instead of reading as
     distinct buttons. */
  border: 1px solid #d9c6ad;
  background: var(--white);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
  color: var(--text-dark);
  font-size: 0.85rem;
  text-decoration: none;
}
.pill-filter:hover {
  border-color: var(--orange-dark);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  text-decoration: none;
}
.pill-filter.active {
  background: var(--orange);
  border-color: var(--orange-dark);
  font-weight: 600;
}

/* ---- buttons ---- */

.btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  border: 1px solid var(--orange-dark);
  background: var(--orange);
  color: var(--text-dark);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn:hover {
  background: var(--orange-dark);
  text-decoration: none;
}

.btn-secondary {
  background: var(--white);
  color: var(--text-dark);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--cream);
}

.btn-danger {
  background: var(--white);
  color: var(--status-declined);
  border-color: var(--status-declined);
}
.btn-danger:hover {
  background: var(--status-declined);
  color: var(--white);
}

/* ---- forms ---- */

.card {
  max-width: 900px;
  margin: 0 auto;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.75rem;
}

fieldset {
  border: none;
  margin-bottom: 1.5rem;
}

fieldset legend {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--orange);
  width: 100%;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #444;
}

.form-field input,
.form-field select,
.form-field textarea {
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.alert {
  max-width: 900px;
  margin: 0 auto 1.25rem;
  padding: 0.9rem 1.1rem;
  border-radius: 6px;
  font-size: 0.9rem;
}
.alert-error {
  background: #fdecea;
  border: 1px solid var(--status-declined);
  color: #7a1f1f;
}

/* ---- detail view ---- */

.detail-grid {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  gap: 1.25rem;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}

.detail-header-main {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.profile-thumb {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--cream);
  flex-shrink: 0;
}

/* Roster/subtenants list rows (index.php, subtenants.php) — small enough,
   with vertical-align:middle, to sit inside the existing row padding
   instead of growing the row's height. */
.row-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 0.5rem;
  background: var(--cream);
}

.detail-header h2 {
  font-size: 1.3rem;
  margin-bottom: 0.4rem;
}

.detail-header .badges {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.detail-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  /* Grid items default to a min-width equal to their content's intrinsic
     size, so a wide table (e.g. the 21-column onboarding checklist) would
     otherwise force this — and the whole page — wider than max-width:900px
     instead of scrolling inside its own .roster-table-wrap. */
  min-width: 0;
}

.detail-section h3 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #666;
  margin-bottom: 1rem;
}

dl.detail-list {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.6rem 1rem;
}

dl.detail-list dt {
  font-weight: 600;
  color: #555;
}

dl.detail-list dd {
  word-break: break-word;
}

/* ---- related-record sections (person detail page) ---- */

.empty-state-inline {
  color: #888;
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--orange-dark);
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
.link-btn:hover {
  text-decoration: underline;
}

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

.thumb-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  text-align: center;
}

.thumb-item img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--cream);
}

.thumb-caption {
  font-size: 0.8rem;
  margin-top: 0.4rem;
  word-break: break-word;
}

.thumb-actions {
  margin-top: 0.4rem;
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  font-size: 0.8rem;
}

.thumb-actions form {
  display: inline;
}

/* ---- login ---- */

.login-wrap {
  max-width: 400px;
  margin: 3rem auto 0;
}

.login-card .form-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.login-card label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #444;
}

.login-card input {
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
}

.user-info {
  color: var(--text-dark);
  font-size: 0.9rem;
  margin-left: 1.25rem;
}

/* ---- responsive ---- */

@media (max-width: 700px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  dl.detail-list {
    grid-template-columns: 1fr;
  }
  dl.detail-list dt {
    margin-top: 0.5rem;
  }
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-bar select,
  .filter-bar input[type="text"] {
    min-width: 0;
  }
}

@media (max-width: 480px) {
  header {
    padding: 1rem;
  }
  main {
    padding: 1.25rem;
  }
  footer {
    padding: 1rem;
  }
  table.roster th,
  table.roster td {
    padding: 0.55rem 0.6rem;
  }
}
