/* ======================================================
   Contacts & Passengers page
   ====================================================== */

/* ── Page ─────────────────────────────────────────────── */
.contacts-page {
  gap: 1rem;
}

.contacts-page .card { margin-bottom:0; }

/* Page header — compact single bar above the table panel */
.contacts-page-header {
  display:flex; align-items:center; justify-content:space-between;
  gap:12px; padding:24px 28px; flex-wrap:wrap;
  border:1px solid var(--border);
  border-radius:var(--radius-md, 16px);
  background:linear-gradient(180deg, var(--surface-2), var(--surface));
  box-shadow:var(--shadow-card);
}
.contacts-page-header-left { display:grid; gap:2px; }
.contacts-page-header-title { font-size:20px; font-weight:700; margin:0; line-height:1.2; }
.contacts-eyebrow {
  font-size:10px; font-weight:700; color:var(--muted);
  text-transform:uppercase; letter-spacing:.1em; margin:0;
}
.contacts-page-header-meta { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.contacts-scope-badge {
  display:inline-flex; align-items:center; gap:6px;
  font-size:11px; padding:3px 9px; border-radius:99px;
  border:1px solid var(--border);
  background:color-mix(in srgb,var(--surface-2) 80%,transparent);
}
.contacts-access-badge {
  font-size:11px; color:var(--muted);
}
.contacts-duplicate-note {
  padding:10px 14px; border-radius:8px; margin-top:8px;
  border:1px solid color-mix(in srgb,var(--color-warning) 40%,transparent);
  background:color-mix(in srgb,var(--color-warning) 8%,transparent);
  font-size:12px;
}
.contacts-duplicate-list { padding-left:16px; margin:6px 0 0; font-size:12px; line-height:1.6; }

/* ── Table panel ─────────────────────────────────────── */
/* Remove the 16px padding that .card applies globally */
.contacts-table-panel {
  overflow:hidden;
  padding:0 !important;
  min-width:0;
  border:1px solid var(--border);
  border-radius:12px;
  background:color-mix(in srgb,var(--surface) 76%,transparent);
}

.contacts-table-head {
  display:flex; align-items:center; justify-content:space-between;
  gap:10px; padding:10px 14px;
  border-bottom:1px solid var(--border);
}
.contacts-table-head-left { display:flex; align-items:baseline; gap:8px; }
.contacts-table-head-title { font-size:14px; font-weight:700; margin:0; }
.contacts-title-count { font-size:12px; color:var(--muted); }

/* ── Filter bar: single non-wrapping row ──────────────── */
.contacts-filters {
  display:flex;
  flex-wrap:nowrap;          /* ← everything on one line */
  gap:5px;
  padding:7px 10px;
  align-items:center;
  background:color-mix(in srgb,var(--surface-2) 40%,transparent);
  border-bottom:1px solid var(--border);
  overflow-x:auto;
  scrollbar-width:none;
}
.contacts-filters::-webkit-scrollbar { display:none; }
/* Override global .input { width:100% } inside this flex row */
.contacts-filters .input {
  width:auto !important;
  min-height:0 !important;
  height:28px;
  font-size:12px;
  padding-inline:8px;
  flex-shrink:0;
}
/* Search: takes remaining space but won't push others off */
.contacts-filter-search {
  flex:1 1 0;
  min-width:110px;
  max-width:340px;
  flex-shrink:1;
}
.contacts-filter-select { width:auto !important; }
.contacts-filters .btn {
  height:28px;
  font-size:12px;
  padding-inline:9px;
  flex-shrink:0;
  white-space:nowrap;
}

/* ── Table: compact rows ──────────────────────────────── */
.contacts-table-host { overflow-x:auto; }
.contacts-table-host .table td,
.contacts-table-host .table th {
  vertical-align:middle;
  padding:7px 10px;
  font-size:12px;
}
.contacts-table-host .table th {
  font-size:10px; font-weight:700; letter-spacing:.07em;
  text-transform:uppercase; color:var(--muted);
  white-space:nowrap;
}
.contacts-table-host .table td:first-child { font-size:13px; }
.contacts-table-host .table-actions .btn { padding-inline:7px; }

/* Name cell */
.contacts-name-cell { display:grid; gap:3px; }
.contacts-name-cell strong { font-size:13px; font-weight:600; }
.contacts-name-sub { font-size:11px; color:var(--muted); }

@media (max-width:640px) {
  .contacts-table-host { overflow: visible; }
  .contacts-table-host .table { display: block; min-width: 0; }
  .contacts-table-host thead { display: none; }
  .contacts-table-host tbody { display: grid; gap: 8px; padding: 10px; }
  .contacts-table-host tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
  }
  .contacts-table-host .table td,
  .contacts-table-host .table th {
    border: 0;
    padding: 0;
    background: transparent !important;
  }
  .contacts-table-host td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .contacts-table-host td:nth-child(2),
  .contacts-table-host td:nth-child(4),
  .contacts-table-host td:nth-child(5) { display: none; }
  .contacts-table-host td:nth-child(3) {
    grid-column: 1;
    grid-row: 2;
    color: var(--muted);
    overflow-wrap: anywhere;
  }
  .contacts-table-host td.table-actions {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: normal;
  }
  .contacts-table-host .table-actions .btn {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding-inline: 0;
  }
}

/* ── Chips ───────────────────────────────────────────── */
.contacts-chip {
  display:inline-flex; align-items:center;
  font-size:11px; font-weight:600;
  padding:2px 7px; border-radius:99px;
  border:1px solid var(--border);
  background:color-mix(in srgb,var(--surface-2) 70%,transparent);
  color:var(--text); gap:4px;
}
.contacts-chip.is-good   { border-color:color-mix(in srgb,var(--color-success) 50%,transparent); background:color-mix(in srgb,var(--color-success) 14%,transparent); color:var(--color-success); }
.contacts-chip.is-warn   { border-color:color-mix(in srgb,var(--color-warning) 50%,transparent); background:color-mix(in srgb,var(--color-warning) 14%,transparent); color:var(--color-warning); }
.contacts-chip.is-danger { border-color:color-mix(in srgb,var(--color-danger)  50%,transparent); background:color-mix(in srgb,var(--color-danger)  14%,transparent); color:var(--color-danger); }
.contacts-chip.is-muted  { color:var(--muted); }
.contacts-chip.is-std   { border-color:color-mix(in srgb,var(--color-primary) 40%,transparent); background:color-mix(in srgb,var(--color-primary) 10%,transparent); color:var(--color-primary); }
.contacts-chip-group { display:flex; flex-wrap:wrap; gap:4px; }
.contacts-linked-user-cell { display:grid; gap:4px; }

/* ======================================================
   Editor modal
   ====================================================== */

/* Narrower modal — 840px is the right form width 
.contacts-editor-card { width:min(840px,calc(100vw - 24px)); }

/* Two-pane: slim sidebar + content */
.contacts-editor-shell {
  display:grid;
  grid-template-columns:176px minmax(0,1fr);
  align-items:start;
  min-height:460px;
}

/* ── Sidebar ─────────────────────────────────────────── */
.contacts-editor-summary {
  padding:12px 10px;
  border-right:1px solid var(--border);
  display:grid; gap:8px; align-content:start;
  background:color-mix(in srgb,var(--surface-2) 40%,transparent);
}

.contacts-editor-avatar {
  width:36px; height:36px; border-radius:50%;
  background:color-mix(in srgb,var(--color-primary) 18%,transparent);
  color:var(--color-primary);
  display:flex; align-items:center; justify-content:center;
  font-size:13px; font-weight:700; flex-shrink:0;
}

.contacts-editor-identity { display:grid; gap:4px; }
.contacts-editor-name  { font-size:13px; font-weight:700; margin:0; word-break:break-word; line-height:1.3; }
.contacts-editor-role-chips { display:flex; flex-wrap:wrap; gap:3px; }

/* Stat tiles — perf-spec style (3 tiles: contact, weight, account) */
.contacts-editor-stats { display:grid; gap:4px; margin-top:2px; }
.contacts-editor-stat {
  display:grid; gap:1px; padding:6px 8px; border-radius:6px;
  border:1px solid color-mix(in srgb,var(--border) 60%,transparent);
  background:color-mix(in srgb,var(--surface-2) 60%,transparent);
}
.contacts-editor-stat-label {
  font-size:9px; font-weight:700; letter-spacing:.09em;
  text-transform:uppercase; color:var(--muted);
}
.contacts-editor-stat-value {
  font-size:11px; color:var(--text);
  overflow-wrap:anywhere; font-weight:500; line-height:1.4;
}

.contacts-editor-banner {
  padding:6px 8px; border-radius:6px; font-size:10px; font-weight:600;
  border:1px solid color-mix(in srgb,var(--color-primary) 30%,transparent);
  background:color-mix(in srgb,var(--color-primary) 8%,transparent);
  color:var(--color-primary); line-height:1.4;
}
.contacts-editor-banner.is-danger {
  border-color:color-mix(in srgb,var(--color-danger) 40%,transparent);
  background:color-mix(in srgb,var(--color-danger) 10%,transparent);
  color:var(--color-danger);
}
.contacts-editor-banner.is-inactive {
  border-color:color-mix(in srgb,var(--color-warning) 40%,transparent);
  background:color-mix(in srgb,var(--color-warning) 10%,transparent);
  color:var(--color-warning);
}

/* ── Tab nav ─────────────────────────────────────────── */
.contacts-editor-main { display:grid; grid-template-rows:auto 1fr; overflow:hidden; }

.contacts-tabs-nav {
  display:flex; gap:1px;
  padding:10px 12px 0;
  border-bottom:1px solid var(--border);
  overflow-x:auto; scrollbar-width:none;
}
.contacts-tabs-nav::-webkit-scrollbar { display:none; }

.contacts-tab-btn {
  padding:6px 12px;
  min-height: 44px;
  border-radius:6px 6px 0 0;
  border:1px solid transparent;
  border-bottom:none;
  font-size:12px; font-weight:600; color:var(--muted);
  background:transparent; cursor:pointer; white-space:nowrap;
  transition:color .14s,background .14s;
  position:relative; bottom:-1px;
}
.contacts-tab-btn:hover { color:var(--text); background:color-mix(in srgb,var(--surface-2) 60%,transparent); }
.contacts-tab-btn.is-active {
  color:var(--text); background:var(--surface);
  border-color:var(--border); border-bottom-color:var(--surface);
}
.contacts-tab-btn.is-disabled { opacity:.35; pointer-events:none; }

/* ── Tab panels ──────────────────────────────────────── */
.contacts-tab-panels { overflow:hidden; }
.contacts-tab-panel {
  display:none;
  padding:12px;
  overflow-y:auto;
  max-height:calc(var(--app-vh, 1vh) * 100 - 220px);
  min-height:420px;
}
.contacts-tab-panel.is-active { display:grid; gap:8px; align-content:start; }

/* ======================================================
   Form standard (forms wave 3)
   ======================================================
   Each tab panel holds an .ap-form of section cards (forms.css); the old
   contacts-form-card / contacts-field / role-pill / type-toggle rules are
   gone. The card takes the page background so the section cards keep their
   contrast (form-standard.md, "Modals"); the body was an inline style. */
.contacts-editor-card { background:var(--color-bg, var(--bg)); }
.contacts-editor-body--tabs { display:block; max-height:none; padding:0; overflow:hidden; }

/* Summary box and Save row, below the tabs so they serve every tab. The bar
   sits outside the scrolling panels: keep the phone row layout of --sticky
   without its own frame (passengers.css loads before forms.css, hence the
   extra .ap-form). */
.contacts-editor-footer { padding:10px 14px; border-top:1px solid var(--border); gap:8px; }
.contacts-editor-footer.ap-form .ap-form-actions--sticky { padding:0; border-top:0; background:none; }

/* Collapsible section cards (address, weight history, standard weight
   rules): the title is a button that shows or hides the body. */
.contacts-section-toggle {
  display:inline-flex; align-items:center; gap:8px;
  padding:0; border:0; background:none; cursor:pointer;
  color:inherit; font:inherit; text-align:left;
}
.contacts-section-toggle i { font-size:10px; color:var(--muted); transition:transform .2s; }
.contacts-section-toggle.is-open i { transform:rotate(90deg); }
.contacts-section-toggle:focus-visible {
  outline:none; border-radius:4px;
  box-shadow:0 0 0 3px var(--focus-ring-color, rgba(11, 91, 255, 0.28));
}
/* Folded, the head is the whole card: no divider under it, and its own
   bottom corners rounded */
.contacts-collapsible .ap-form-section__head:has(+ .ap-form-section__body[hidden]) {
  border-bottom:0;
  border-radius:calc(var(--form-card-radius, 12px) - 1px);
}

/* Flat key-value list for read-only data (Linked Account tab) */
.contacts-kv-list { display:grid; gap:0; }
.contacts-kv-row {
  display:grid; grid-template-columns:90px 1fr;
  align-items:baseline; gap:8px;
  padding:6px 0;
  border-bottom:1px solid color-mix(in srgb,var(--border) 40%,transparent);
}
.contacts-kv-row:last-child { border-bottom:none; }
.contacts-kv-label {
  font-size:9px; font-weight:700; letter-spacing:.09em;
  text-transform:uppercase; color:var(--muted);
}
.contacts-kv-value { font-size:12px; color:var(--text); font-weight:500; overflow-wrap:anywhere; }

/* Text buttons in the form: "Customise display name", "+ Add a second
   number", "Reset to automatic" */
.contacts-link-btn {
  align-self:flex-start;
  font-size:12px; color:var(--color-primary);
  background:none; border:none; padding:0;
  cursor:pointer; text-decoration:underline;
  text-align:left;
}
.contacts-link-btn:hover { opacity:.75; }
.contacts-link-btn:focus-visible {
  outline:none; border-radius:4px;
  box-shadow:0 0 0 3px var(--focus-ring-color, rgba(11, 91, 255, 0.28));
}
@media (pointer:coarse) {
  .contacts-link-btn { min-height:44px; font-size:15px; }
}

/* Weight required warning in tab */
.contacts-weight-required {
  padding:8px 10px; border-radius:6px; font-size:12px;
  border:1px solid color-mix(in srgb,var(--color-warning) 40%,transparent);
  background:color-mix(in srgb,var(--color-warning) 8%,transparent);
  color:var(--text); line-height:1.5;
}

/* ── Passenger: effective weight block ───────────────── */
.contacts-weight-chip {
  display:grid;
  grid-template-columns:1fr auto;
  align-items:center; gap:10px;
  padding:10px 12px; border-radius:8px;
  border:1px solid var(--border);
  background:color-mix(in srgb,var(--surface-2) 80%,transparent);
}
.contacts-weight-chip-value { font-size:22px; font-weight:700; color:var(--text); line-height:1; }
.contacts-weight-chip-label { font-size:11px; color:var(--muted); margin-top:2px; }
.contacts-weight-chip-source {
  font-size:10px; font-weight:700; letter-spacing:.06em; text-transform:uppercase;
  padding:3px 8px; border-radius:99px; white-space:nowrap;
}
.contacts-weight-chip-source.is-actual  { background:color-mix(in srgb,var(--color-success) 14%,transparent); color:var(--color-success);  border:1px solid color-mix(in srgb,var(--color-success) 40%,transparent); }
.contacts-weight-chip-source.is-override{ background:color-mix(in srgb,var(--color-warning) 14%,transparent); color:var(--color-warning); border:1px solid color-mix(in srgb,var(--color-warning) 40%,transparent); }
.contacts-weight-chip-source.is-standard,
.contacts-weight-chip-source.is-std { background:color-mix(in srgb,var(--color-primary) 10%,transparent); color:var(--color-primary); border:1px solid color-mix(in srgb,var(--color-primary) 35%,transparent); }
.contacts-weight-chip-source.is-none    { background:color-mix(in srgb,var(--color-danger) 10%,transparent); color:var(--color-danger); border:1px solid color-mix(in srgb,var(--color-danger) 30%,transparent); }

/* ── Weight history ──────────────────────────────────── */
.contacts-weight-history-list { display:grid; gap:5px; }
.contacts-weight-history-item {
  display:grid; grid-template-columns:auto 1fr auto;
  gap:8px; align-items:center;
  padding:7px 10px; border-radius:6px;
  border:1px solid color-mix(in srgb,var(--border) 70%,transparent);
  background:color-mix(in srgb,var(--surface-2) 70%,transparent);
  font-size:12px;
}
.contacts-weight-history-weight { font-size:14px; font-weight:700; color:var(--text); font-variant-numeric:tabular-nums; }
.contacts-weight-history-meta { color:var(--muted); }

/* ── Standard weights reference ──────────────────────── */
.contacts-std-weights-table { width:100%; font-size:12px; border-collapse:collapse; }
.contacts-std-weights-table th {
  text-align:left; padding:5px 8px;
  border-bottom:1px solid var(--border);
  font-size:9px; font-weight:700; letter-spacing:.09em;
  text-transform:uppercase; color:var(--muted);
}
.contacts-std-weights-table td {
  padding:5px 8px;
  border-bottom:1px solid color-mix(in srgb,var(--border) 40%,transparent);
  font-size:12px;
}

/* ── Linked account ──────────────────────────────────── */
.contacts-linked-account-block {
  padding:12px; border-radius:8px;
  border:1px solid var(--border);
  background:color-mix(in srgb,var(--surface-2) 80%,transparent);
  display:grid; gap:10px;
}
.contacts-linked-notice {
  padding:9px 11px; border-radius:6px; font-size:12px;
  border:1px solid color-mix(in srgb,var(--color-primary) 30%,transparent);
  background:color-mix(in srgb,var(--color-primary) 8%,transparent);
  color:var(--text); line-height:1.5;
}

/* ── Linked list (owner aircraft) ────────────────────── */
.contacts-linked-list { display:grid; gap:5px; }
.contacts-linked-item {
  display:flex; align-items:center; gap:8px;
  padding:7px 11px; border-radius:6px;
  border:1px solid color-mix(in srgb,var(--border) 70%,transparent);
  font-size:13px; font-weight:600; color:var(--text);
  text-decoration:none;
  background:color-mix(in srgb,var(--surface-2) 70%,transparent);
  transition:background .14s;
}
.contacts-linked-item:hover { background:color-mix(in srgb,var(--color-primary) 10%,transparent); }
.contacts-linked-item span { color:var(--muted); font-weight:400; }

/* ── Standard passenger weights modal (form standard) ── */
/* Page background for the card contrast; a flex column whose body scrolls,
   so the sticky Save bar stays on screen. */
.contacts-standard-weights-card {
  width:min(640px, calc(100vw - 24px));
  max-height:calc(var(--app-vh, 1vh) * 100 - 32px);
  display:flex; flex-direction:column;
  background:var(--color-bg, var(--bg));
}
.contacts-standard-weights-card .modal-body {
  flex:1 1 auto; min-height:0;
  overflow-y:auto;
  padding-bottom:0;
}
@media (max-width:640px) {
  .contacts-standard-weights-card {
    width:calc(100vw - 20px);
    max-height:calc(var(--app-vh, 1vh) * 100 - 20px);
  }
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width:800px) {
  .contacts-editor-shell    { grid-template-columns:1fr; }
  .contacts-editor-summary  { border-right:none; border-bottom:1px solid var(--border); }
  .contacts-hero             { grid-template-columns:1fr; }
  .contacts-hero-note        { max-width:none; }

  /* Single column: the card is a flex column whose tab panel scrolls, so
     the Save row stays on screen. As blocks, the sidebar, tabs and panel
     ran past the bottom of a phone and Save could not be reached (the same
     fault the profile modal had; found in forms wave 3). */
  .contacts-editor-card {
    max-height:calc(var(--app-vh, 1vh) * 100 - 16px);
    display:flex; flex-direction:column;
  }
  #contactEditorModal .modal-body {
    display:flex; flex-direction:column;
    flex:1 1 auto; min-height:0;
  }
  .contacts-editor-shell {
    flex:1 1 auto; min-height:0;
    display:flex; flex-direction:column; align-items:stretch;
  }
  .contacts-editor-summary { flex:0 0 auto; }
  .contacts-editor-main {
    flex:1 1 auto; min-height:0;
    grid-template-rows:auto minmax(0, 1fr);
  }
  .contacts-tab-panels { min-height:0; display:grid; }
  .contacts-tab-panel { min-height:0; max-height:none; }
  .contacts-editor-footer { flex:0 0 auto; }
}

@media (max-width:640px) {
  /* The sidebar's three tiles repeat what the tabs show (phone and email,
     the Weight tab, the Linked account tab); on a phone they pushed the form
     below half the screen. Name, role chips and the Inactive / identity
     locked banners stay. */
  .contacts-editor-summary { padding:8px 12px; gap:6px; }
  .contacts-editor-stats { display:none; }
  .contacts-editor-identity {
    grid-template-columns:auto minmax(0, 1fr);
    align-items:center; column-gap:10px;
  }
  .contacts-editor-identity .contacts-editor-avatar { grid-row:span 2; }
}

/* Mobile contacts keep filters reachable and prevent table columns from crushing into each other. */
@media (max-width:640px) {
  .contacts-page {
    padding:0;
  }

  .contacts-page-header {
    padding:14px;
    border-radius:12px;
  }

  .contacts-table-head {
    align-items:stretch;
  }

  .contacts-table-head-left,
  .contacts-table-tools {
    width:100%;
    justify-content:center;
    flex-wrap:wrap;
  }

  .contacts-filters {
    padding:8px;
  }

  .contacts-filter-search {
    min-width:180px;
  }

  .contacts-table-host {
    max-width:100%;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
  }

  .contacts-table-host .table {
    min-width:720px;
  }

  .contacts-editor-card {
    width:calc(100vw - 16px);
    max-height:calc((var(--app-vh, 1vh) * 100) - 16px);
  }

  .contacts-tab-panels {
    overflow-y:auto;
  }

  }

/* ── Very narrow phones: drop secondary columns so Name+Contact+Actions fit ── */
@media (max-width:480px) {
  /* Override the 640px min-width so the table shrinks to fit */
  .contacts-table-host .table { min-width:0; }

  /* Hide Roles (col 2), Weight (col 4), Updated (col 5) */
  .contacts-table-host .table thead th:nth-child(2),
  .contacts-table-host .table thead th:nth-child(4),
  .contacts-table-host .table thead th:nth-child(5),
  .contacts-table-host .table tbody td:nth-child(2),
  .contacts-table-host .table tbody td:nth-child(4),
  .contacts-table-host .table tbody td:nth-child(5) {
    display:none;
  }
}
.contacts-table-head-actions { display:flex; gap:6px; align-items:center; flex-shrink:0; }
