/* ── Reset & Variables ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:        #1a3272;
  --navy-mid:    #243d8a;
  --navy-light:  #e8ecf7;
  --cyan:        #00aeef;
  --cyan-dark:   #0090cc;
  --cyan-light:  #e0f6fd;
  --slate:       #4a5568;
  --slate-light: #718096;
  --off-white:   #f7f9fc;
  --white:       #ffffff;
  --border:      #d8e0ee;
  --text:        #111827;
  --amber:       #f59e0b;
  --amber-light: #fef3c7;
  --success:     #10b981;
  --error:       #ef4444;
  --radius:      10px;
  --shadow:      0 4px 24px rgba(26,50,114,.08);
  --shadow-md:   0 8px 32px rgba(26,50,114,.12);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', Calibri, sans-serif;
  color: var(--text);
  background: var(--off-white);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1,h2,h3,h4 { font-family: 'Syne', sans-serif; }

main { flex: 1; }

/* ── Nav ────────────────────────────────────────────────────────────────────── */
.site-nav {
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  padding: 0 5%;
}
.nav-inner {
  max-width: 1140px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  height: 64px;
}
.nav-logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--navy);
}
.nav-logo-img { height: 36px; width: auto; display: block; }
body.auth-page .nav-logo-img { filter: brightness(0) invert(1) opacity(0.9); }
.nav-right { display: flex; align-items: center; gap: 12px; }
.nav-label { font-size: 12px; color: var(--slate-light); text-transform: uppercase; letter-spacing: 0.8px; }
.nav-label--admin {
  background: var(--navy); color: #fff;
  padding: 3px 10px; border-radius: 100px; font-size: 11px;
}

/* ── Flash Messages ─────────────────────────────────────────────────────────── */
.flash-container {
  position: sticky; top: 64px; z-index: 90;
  padding: 0 5%;
}
.flash {
  max-width: 1140px; margin: 12px auto 0;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  display: flex; align-items: flex-start; gap: 12px;
  position: relative;
}
.flash-success {
  background: #ecfdf5; border: 1px solid #6ee7b7; color: #065f46;
}
.flash-error {
  background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b;
}
.flash-link {
  background: var(--navy-light); border: 1px solid var(--navy);
  color: var(--navy); flex-direction: column; gap: 8px;
}
.magic-link-code {
  display: block;
  background: #fff; border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 6px;
  font-size: 12px; word-break: break-all;
  color: var(--slate);
}
.copy-btn {
  background: var(--navy); color: #fff; border: none;
  padding: 6px 14px; border-radius: 6px; cursor: pointer;
  font-size: 13px; font-family: inherit;
  transition: background .15s;
  align-self: flex-start;
}
.copy-btn:hover { background: var(--navy-mid); }
.flash-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; cursor: pointer;
  font-size: 18px; color: inherit; opacity: .5;
  line-height: 1; padding: 2px 6px;
}
.flash-close:hover { opacity: 1; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 20px; border-radius: 7px;
  font-size: 14px; font-weight: 500; font-family: inherit;
  text-decoration: none; cursor: pointer; border: none;
  transition: background .15s, color .15s, border-color .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary   { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-mid); }
.btn-outline   { background: transparent; color: var(--navy); border: 1.5px solid var(--navy); }
.btn-outline:hover { background: var(--navy-light); }
.btn-ghost     { background: transparent; color: var(--slate); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: #fff; border-color: var(--slate-light); }
.btn-sm        { padding: 7px 14px; font-size: 13px; }
.btn-lg        { padding: 14px 28px; font-size: 16px; }
.btn-full      { width: 100%; justify-content: center; }

/* ── Auth Pages ─────────────────────────────────────────────────────────────── */
.auth-page body, .auth-page { background: var(--navy); }
body.auth-page { background: var(--navy); }

.auth-wrap {
  min-height: calc(100vh - 64px - 60px);
  display: flex; align-items: center; justify-content: center;
  padding: 40px 20px;
}
.auth-card {
  background: #fff; border-radius: 16px;
  padding: 48px 44px; width: 100%; max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-brand-logo { height: 52px; width: auto; margin: 0 auto 20px; display: block; }
.auth-brand h1 {
  font-size: 26px; font-weight: 700; color: var(--navy);
  margin-bottom: 10px;
}
.auth-brand p { color: var(--slate); font-size: 15px; line-height: 1.6; }
.auth-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 28px 0;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.auth-divider span { font-size: 13px; color: var(--slate-light); }
.auth-contact p { color: var(--slate); font-size: 14px; margin-bottom: 16px; }
.auth-form .field { margin-bottom: 20px; }
.auth-form .btn { margin-top: 8px; }

/* ── Form Fields ────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, label {
  font-size: 13px; font-weight: 500; color: var(--navy);
  letter-spacing: 0.1px;
}
input[type="text"], input[type="email"], input[type="tel"],
input[type="password"], input[type="date"], select, textarea {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: 7px;
  font-size: 15px; font-family: inherit; color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(0,174,239,.12);
}
input::placeholder { color: var(--slate-light); }
select { cursor: pointer; }

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 5%;
  background: #fff; margin-top: auto;
}
.footer-inner {
  max-width: 1140px; margin: 0 auto;
  font-size: 12px; color: var(--slate-light); line-height: 1.8;
}

/* ── Portal Hero ────────────────────────────────────────────────────────────── */
.portal-wrap { max-width: 1140px; margin: 0 auto; padding: 0 5% 60px; }

.portal-hero {
  background: var(--navy);
  margin: 0 -5%; padding: 32px 5% 28px;
  position: relative; overflow: hidden;
}
.portal-hero-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
}
.portal-hero::before {
  content: '';
  position: absolute; top: -80px; right: -80px;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(0,174,239,.15) 0%, transparent 70%);
  pointer-events: none;
}
.portal-hero-inner { max-width: 1140px; margin: 0 auto; position: relative; z-index: 1; }
.portal-hero-badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(0,174,239,.15); border: 1px solid rgba(0,174,239,.3);
  border-radius: 100px; padding: 4px 12px; margin-bottom: 12px;
  font-size: 12px; color: #7de4ff; font-weight: 500; letter-spacing: 0.3px;
}
.badge-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--cyan); display: block;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; } 50% { opacity: .4; }
}
.portal-hero h1 {
  font-size: clamp(22px,3vw,34px); font-weight: 700;
  color: #fff; line-height: 1.1; margin-bottom: 10px;
}
.portal-hero-sub {
  font-size: 14px; color: rgba(255,255,255,.65);
  max-width: 580px; line-height: 1.65; font-weight: 300;
}

/* ── Portal Sections ────────────────────────────────────────────────────────── */
.portal-sections { display: flex; flex-direction: column; gap: 24px; padding-top: 32px; }

.portal-section {
  background: #fff; border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow .2s;
}
.portal-section:hover { box-shadow: var(--shadow-md); }

.section-head {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 28px 28px 0;
}
.section-head h2 {
  font-size: 18px; font-weight: 700; color: var(--navy);
  margin-bottom: 4px;
}
.section-head p { font-size: 13px; color: var(--slate-light); font-weight: 300; }

.section-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
}
.section-icon--navy  { background: var(--navy-light); color: var(--navy); }
.section-icon--cyan  { background: var(--cyan-light); color: var(--cyan-dark); }
.section-icon--amber { background: var(--amber-light); color: var(--amber); }

.field-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px; padding: 24px 28px 28px;
}
.field--full { grid-column: 1 / -1; }

/* ── Portal Submit Bar ──────────────────────────────────────────────────────── */
.portal-submit {
  position: sticky; bottom: 0; z-index: 50;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 16px 0;
  margin: 0 -5%;
}
.portal-submit-inner {
  max-width: 1140px; margin: 0 auto; padding: 0 5%;
  display: flex; align-items: center; justify-content: flex-end; gap: 16px;
}
.submit-note { font-size: 13px; color: var(--slate-light); font-weight: 300; }

/* ── Admin Pages ────────────────────────────────────────────────────────────── */
.admin-wrap { max-width: 1140px; margin: 0 auto; padding: 0 5% 60px; }

.admin-hero {
  background: var(--navy);
  margin: 0 -5%; padding: 48px 5% 44px;
  position: relative; overflow: hidden;
}
.admin-hero::before {
  content: '';
  position: absolute; top: -60px; right: -60px;
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(0,174,239,.12) 0%, transparent 70%);
  pointer-events: none;
}
.admin-hero-inner { max-width: 1140px; margin: 0 auto; position: relative; z-index: 1; }
.admin-hero h1 {
  font-size: clamp(24px,3.5vw,40px); font-weight: 700;
  color: #fff; line-height: 1.15; margin: 12px 0 10px;
}
.admin-hero p { font-size: 15px; color: rgba(255,255,255,.6); font-weight: 300; }
.back-link { font-size: 13px; color: rgba(255,255,255,.5); text-decoration: none; }
.back-link:hover { color: #fff; }

.admin-body { padding-top: 32px; }

/* Search bar */
.admin-search-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 28px;
}
.search-field {
  position: relative; flex: 1;
}
.search-field svg {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--slate-light);
}
.search-field input {
  padding-left: 42px;
}

/* Stats */
.admin-stats {
  display: flex; gap: 20px; margin-bottom: 24px;
}
.admin-stat {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 22px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-num {
  font-family: 'Syne', sans-serif; font-size: 28px; font-weight: 700;
  color: var(--navy); line-height: 1;
}
.stat-label { font-size: 12px; color: var(--slate-light); }

/* Admin Table */
.table-wrap {
  background: #fff; border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
}
.admin-table {
  width: 100%; border-collapse: collapse;
}
.admin-table th {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--slate-light); font-weight: 600;
  padding: 14px 18px; text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--off-white);
}
.admin-table td {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-size: 14px; vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--off-white); }
.td-company strong { font-weight: 600; color: var(--navy); }
.td-muted { color: var(--slate); font-weight: 300; }
.td-action { text-align: right; }

/* Pagination */
.pagination {
  display: flex; align-items: center; gap: 12px;
  padding-top: 24px; justify-content: center;
}
.page-info { font-size: 13px; color: var(--slate-light); }

/* Company card */
.company-card {
  background: #fff; border: 1px solid var(--border);
  border-radius: 14px; padding: 24px 28px;
  margin-bottom: 32px; box-shadow: var(--shadow);
}
.company-card-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}
.field-label {
  display: block;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--slate-light); font-weight: 600; margin-bottom: 4px;
}
.company-card p { font-size: 14px; color: var(--slate); }

/* Contacts */
.contacts-heading {
  font-size: 20px; font-weight: 700; color: var(--navy);
  margin-bottom: 16px; display: flex; align-items: center; gap: 10px;
}
.contacts-count {
  background: var(--cyan-light); color: var(--cyan-dark);
  font-size: 13px; font-weight: 600; font-family: 'DM Sans', sans-serif;
  padding: 2px 10px; border-radius: 100px;
}
.contacts-grid { display: flex; flex-direction: column; gap: 12px; }

.contact-card {
  background: #fff; border: 1px solid var(--border);
  border-radius: 12px; padding: 20px 24px;
  display: flex; align-items: center; gap: 18px;
  box-shadow: var(--shadow);
  transition: border-color .2s, box-shadow .2s;
}
.contact-card:hover { border-color: var(--cyan); box-shadow: var(--shadow-md); }
.contact-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif; font-size: 18px; font-weight: 700;
  flex-shrink: 0;
}
.contact-info {
  flex: 1; display: flex; flex-direction: column; gap: 2px;
}
.contact-info strong { font-size: 16px; font-weight: 600; color: var(--navy); }
.contact-info span   { font-size: 13px; color: var(--slate-light); }
.contact-title {
  font-size: 12px !important; color: var(--cyan-dark) !important;
  font-weight: 500;
}
.contact-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* Empty state */
.empty-state {
  text-align: center; padding: 64px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.empty-state h3 { font-size: 20px; color: var(--navy); }
.empty-state p  { font-size: 14px; color: var(--slate-light); }

/* Auth page – override nav bg on navy background */
body.auth-page .site-nav {
  background: rgba(26,50,114,.95);
  border-bottom-color: rgba(255,255,255,.1);
}
body.auth-page .nav-logo-img { filter: brightness(0) invert(1); }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .admin-table th:nth-child(2),
  .admin-table td:nth-child(2),
  .admin-table th:nth-child(3),
  .admin-table td:nth-child(3),
  .admin-table th:nth-child(4),
  .admin-table td:nth-child(4) { display: none; }

  .contact-card { flex-wrap: wrap; }
  .contact-actions { width: 100%; }
  .portal-submit-inner { flex-direction: column; align-items: stretch; }
  .submit-note { text-align: center; }
  .auth-card { padding: 36px 28px; }
  .section-head { padding: 20px 20px 0; }
  .field-grid { padding: 18px 20px 20px; }
}

/* ── Contact table (admin customer page) ─────────────────────────────────── */
.contacts-table-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.bulk-actions {
  display: flex; align-items: center; gap: 12px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity:0; transform:translateY(-4px); } to { opacity:1; transform:none; } }
.bulk-label { font-size: 13px; color: var(--slate); font-weight: 500; }

.contacts-table .th-check,
.contacts-table .td-check { width: 44px; padding-right: 0; }
.contacts-table input[type="checkbox"] {
  width: 17px; height: 17px; cursor: pointer;
  accent-color: var(--navy); border-radius: 4px;
}
.contacts-table input[type="checkbox"]:disabled { opacity: .35; cursor: not-allowed; }

.contact-name-cell {
  display: flex; align-items: center; gap: 10px;
}
.contact-avatar-sm {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--navy-light); color: var(--navy);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif; font-size: 14px; font-weight: 700;
  flex-shrink: 0;
}
.contact-row { cursor: pointer; }
.contact-row:hover td { background: #f0f4ff; }
.contact-row:has(.contact-check:checked) td { background: var(--navy-light); }

.no-email       { color: var(--border); font-style: italic; font-size: 13px; }
.no-email-badge {
  font-size: 11px; color: var(--slate-light);
  background: var(--off-white); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 4px;
}
.inline-form { display: inline; }

/* ── Phone rows ──────────────────────────────────────────────────────────── */
.phones-section {
  padding: 0 28px 28px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 20px;
}
.phones-label {
  font-size: 13px; font-weight: 500; color: var(--navy);
  margin-bottom: 12px;
}
.phones-list { display: flex; flex-direction: column; gap: 10px; }
.phone-row {
  display: grid;
  grid-template-columns: 130px 1fr 80px;
  gap: 8px; align-items: center;
}
.phone-type-sel { width: 100%; }
.phone-num      { width: 100%; }
.phone-ext      { width: 100%; }

@media (max-width: 500px) {
  .phone-row { grid-template-columns: 1fr 1fr; }
  .phone-ext { display: none; }
}

/* ── Contacts Role Table ──────────────────────────────────────────────────── */
.contacts-table-wrap {
  margin: 0;
}

.contacts-role-table {
  width: 100%; border-collapse: collapse;
  font-size: 14px;
}

.contacts-role-table thead th {
  padding: 12px 16px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px;
  color: var(--slate-light); font-weight: 600;
  background: var(--off-white);
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.th-role { text-align: center !important; width: 100px; }
.th-phones { width: 320px; }

.role-header {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  font-size: 11px; line-height: 1.3; text-align: center;
}
.role-header svg { flex-shrink: 0; }
.role-header--amber { color: var(--amber); }
.role-header--navy  { color: var(--navy); }
.role-header--cyan  { color: var(--cyan-dark); }

/* Rows */
.contact-role-row td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.contact-role-row:last-child td { border-bottom: none; }
.contact-role-row { transition: background .15s; }
.contact-role-row:hover { background: var(--off-white); }

/* Role highlight states */
/* Multi-role: blend highlights with left border stripe */
.contact-role-row.role-selected--emergency  { background: #fffbeb; }
.contact-role-row.role-selected--approver   { background: #eef1fb; }
.contact-role-row.role-selected--security_audit { background: #e0f6fd; }
/* Two roles */
.contact-role-row.role-selected--emergency.role-selected--approver { background: linear-gradient(90deg,#fffbeb 50%,#eef1fb 50%); }
.contact-role-row.role-selected--emergency.role-selected--security_audit { background: linear-gradient(90deg,#fffbeb 50%,#e0f6fd 50%); }
.contact-role-row.role-selected--approver.role-selected--security_audit  { background: linear-gradient(90deg,#eef1fb 50%,#e0f6fd 50%); }
/* All three */
.contact-role-row.role-selected--emergency.role-selected--approver.role-selected--security_audit {
  background: linear-gradient(90deg,#fffbeb 33%,#eef1fb 33% 66%,#e0f6fd 66%);
}

/* Contact identity cell */
.td-contact-id { min-width: 180px; }
.cid-wrap { display: flex; align-items: center; gap: 10px; }
.cid-text { display: flex; flex-direction: column; gap: 1px; }
.cid-text strong { font-size: 14px; font-weight: 600; color: var(--navy); }
.cid-text span   { font-size: 12px; color: var(--slate-light); }
.cid-text .contact-title { color: var(--cyan-dark); font-weight: 500; }

/* Phone editing inline */
.td-phones-edit { min-width: 300px; }
.phone-rows-inline { display: flex; flex-direction: column; gap: 6px; }
.phone-row-inline {
  display: grid; grid-template-columns: 90px 1fr 52px; gap: 5px;
  align-items: center;
}
.phone-row--faded .phone-type-sel-sm,
.phone-row--faded .phone-num-sm,
.phone-row--faded .phone-ext-sm {
  opacity: .55;
}
.phone-type-sel-sm {
  font-size: 12px; padding: 6px 6px; border-radius: 6px;
  border: 1.5px solid var(--border); background: #fff; color: var(--slate);
  font-family: inherit;
}
.phone-num-sm {
  font-size: 13px; padding: 6px 10px; border-radius: 6px;
  border: 1.5px solid var(--border); background: #fff;
  font-family: inherit; width: 100%;
}
.phone-ext-sm {
  font-size: 12px; padding: 6px 6px; border-radius: 6px;
  border: 1.5px solid var(--border); background: #fff;
  font-family: inherit; width: 100%; text-align: center; color: var(--slate);
}
.phone-type-sel-sm:focus, .phone-num-sm:focus, .phone-ext-sm:focus {
  border-color: var(--cyan); outline: none;
  box-shadow: 0 0 0 3px rgba(0,174,239,.1);
}

/* Role radio cells */
.td-role { text-align: center; width: 100px; }
.role-radio-wrap {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
  transition: background .15s;
}
.role-radio-wrap:hover { background: var(--off-white); }
.role-radio { display: none; } /* hide native input, style the dot below */
.role-radio-dot {
  width: 24px; height: 24px; border-radius: 6px;
  border: 2px solid var(--border); background: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .15s, background .15s;
  position: relative;
}
.role-radio-dot::after {
  content: '';
  width: 6px; height: 11px;
  border: 2.5px solid transparent;
  border-top: none; border-left: none;
  transform: rotate(45deg) translate(-1px, -1px);
  transition: border-color .15s;
}
.role-radio--amber:checked ~ .role-radio-dot { border-color: var(--amber); background: var(--amber-light); }
.role-radio--amber:checked ~ .role-radio-dot::after { border-color: var(--amber); }
.role-radio--navy:checked  ~ .role-radio-dot { border-color: var(--navy);  background: var(--navy-light); }
.role-radio--navy:checked  ~ .role-radio-dot::after { border-color: var(--navy); }
.role-radio--cyan:checked  ~ .role-radio-dot { border-color: var(--cyan-dark); background: var(--cyan-light); }
.role-radio--cyan:checked  ~ .role-radio-dot::after { border-color: var(--cyan-dark); }

.role-na { color: var(--border); font-size: 16px; }

/* Legend */
.role-legend {
  display: flex; flex-wrap: wrap; gap: 20px;
  padding: 16px 28px 24px; border-top: 1px solid var(--border);
}
.legend-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--slate-light);
}
.legend-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.legend-item--amber .legend-dot { background: var(--amber); }
.legend-item--navy  .legend-dot { background: var(--navy); }
.legend-item--cyan  .legend-dot { background: var(--cyan-dark); }

.empty-contacts {
  text-align: center; padding: 40px; color: var(--slate-light); font-size: 14px;
}

@media (max-width: 768px) {
  .contacts-role-table { font-size: 13px; }
  .phone-row-inline { grid-template-columns: 80px 1fr; }
  .phone-ext-sm { display: none; }
  .th-role, .td-role { width: 70px; }
  .role-header span { display: none; }
  .th-phones { width: 160px; }
  .phone-rows-inline { gap: 4px; }
}

/* ── Inline phone inputs (portal contact table) ──────────────────────────── */
.th-phone { width: 160px; font-size: 11px; }
.td-phone-edit { width: 160px; }
.phone-input-inline {
  width: 100%; padding: 7px 10px;
  border: 1.5px solid var(--border); border-radius: 6px;
  font-size: 13px; font-family: inherit; color: var(--text);
  background: #fff; transition: border-color .15s, box-shadow .15s;
}
.phone-input-inline:focus {
  border-color: var(--cyan); outline: none;
  box-shadow: 0 0 0 3px rgba(0,174,239,.1);
}
.phone-input-inline::placeholder { color: var(--slate-light); }

@media (max-width: 768px) {
  .th-phone, .td-phone-edit { width: 120px; }
  .phone-input-inline { font-size: 12px; padding: 6px 8px; }
}

/* ── Slate checkboxes (notification prefs) ───────────────────────────────── */
.role-header--slate  { color: var(--slate); }
.role-radio--slate:checked ~ .role-radio-dot { border-color: var(--slate); background: var(--off-white); }
.role-radio--slate:checked ~ .role-radio-dot::after { border-color: var(--slate); }
.role-radio-dot--slate { }  /* inherits base styles */

/* ── Contact cell with inline phones ─────────────────────────────────────── */
.contact-phones-inline {
  display: flex; flex-direction: column; gap: 5px;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--border);
}
.contact-phone-row {
  display: flex; align-items: center; gap: 6px;
}
.phone-type-label {
  font-size: 11px; color: var(--slate-light); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.4px;
  width: 40px; flex-shrink: 0;
}
.phone-input-compact {
  flex: 1; padding: 5px 9px;
  border: 1.5px solid var(--border); border-radius: 5px;
  font-size: 13px; font-family: inherit; color: var(--text);
  background: #fff; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.phone-input-compact:focus {
  border-color: var(--cyan); outline: none;
  box-shadow: 0 0 0 3px rgba(0,174,239,.1);
}
.phone-input-compact::placeholder { color: var(--slate-light); }

/* Widen the contact column now it contains phones */
.th-contact { min-width: 240px; }
.td-contact-id { min-width: 240px; }

/* ── Read-only field display ─────────────────────────────────────────────── */
.field-readonly {
  padding: 10px 14px;
  background: var(--off-white); border: 1.5px solid var(--border);
  border-radius: 7px; font-size: 15px; color: var(--slate);
}
.field-hint {
  font-size: 12px; color: var(--slate-light); margin-top: 4px; display: block;
}

/* ── Sticky table header ──────────────────────────────────────────────────── */
.contacts-table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 70vh;          /* scroll after this height */
  position: relative;
}

.contacts-role-table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--off-white);
  box-shadow: 0 1px 0 var(--border); /* replaces border-bottom when sticky */
}

/* ── Mobile: card-based layout ───────────────────────────────────────────── */
@media (max-width: 640px) {

  /* Hide the table header entirely on mobile */
  .contacts-role-table thead { display: none; }

  /* Stack each row as a card */
  .contacts-role-table,
  .contacts-role-table tbody,
  .contact-role-row { display: block; width: 100%; }

  .contact-role-row {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin: 0 0 12px;
    padding: 14px;
    background: #fff;
    box-shadow: var(--shadow);
  }
  .contact-role-row td { display: block; padding: 0; border: none; }

  /* Contact name/email stays at top */
  .td-contact-id { margin-bottom: 12px; padding-bottom: 12px !important;
    border-bottom: 1px solid var(--border) !important; }

  /* Role checkboxes arranged in a row with labels */
  .td-role {
    display: inline-flex !important;
    flex-direction: column;
    align-items: center;
    width: calc(100% / 6) !important;
    text-align: center;
    padding: 4px 0 !important;
  }

  /* Show role name above each checkbox on mobile */
  .td-role::before {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--slate-light);
    font-weight: 600;
    margin-bottom: 4px;
  }
  .td-role:nth-of-type(2)::before { content: 'Emerg.'; color: var(--amber); }
  .td-role:nth-of-type(3)::before { content: 'Approver'; color: var(--navy); }
  .td-role:nth-of-type(4)::before { content: 'Security'; color: var(--cyan-dark); }
  .td-role:nth-of-type(5)::before { content: 'Billing'; color: var(--slate); }
  .td-role:nth-of-type(6)::before { content: 'Reports'; color: var(--slate); }

  /* Wrap all role cells in a flex row */
  .contact-role-row { position: relative; }
  .td-contact-id ~ .td-role:first-of-type,
  .contact-role-row .td-role { float: left; }
  .contact-role-row::after { content: ''; display: table; clear: both; }

  /* Phone inputs full width */
  .contact-phones-inline { margin-top: 10px; padding-top: 10px; }
  .phone-input-compact { font-size: 14px; padding: 8px 10px; }

  /* Role legend wraps tighter */
  .role-legend { gap: 10px; padding: 14px 16px 20px; }
  .legend-item { font-size: 11px; }

  /* Section head stacks */
  .section-head { flex-direction: column; gap: 10px; }

  /* Submit bar */
  .portal-submit-inner { flex-direction: column; gap: 12px; text-align: center; }
  .btn-lg { width: 100%; justify-content: center; }
}
