/* CycleWright Calendar and contacts (round 21): the address book and the people picker (contacts.js) - a list with the
   contact's card beside it on a wide screen; cards and a pull-up sheet on a phone. Light and dark from ui.css's
   tokens. */

:root { --ct-cust: #3b82f6; --ct-sup: #a78bfa; --ct-col: #22c55e; --ct-own: #94a3b8; }
:root[data-theme="light"] { --ct-cust: #2563eb; --ct-sup: #7c3aed; --ct-col: #16a34a; --ct-own: #64748b; }

/* ---------------------------------------------------------------- the page */
.ct-page { display: flex; flex-direction: column; gap: 10px; }
.ct-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ct-top .spacer { flex: 1; }
.ct-search { flex: 1 1 280px; max-width: 560px; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px;
  background: var(--input-bg); border: 1px solid var(--border-2); border-radius: 10px; color: var(--text-3); cursor: text; }
.ct-search:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.ct-page .ct-search input { flex: 1; min-width: 0; height: 36px; padding: 0; border: 0; background: transparent; box-shadow: none; font-size: 14px; }
.ct-page .ct-search input:focus { box-shadow: none; }
.ct-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ct-chip { height: 30px; padding: 0 12px; border-radius: 99px; font-size: 13px; font-weight: 550; white-space: nowrap; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); box-shadow: none; }
.ct-chip.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 650; }
.ct-n { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text-3); }
.ct-chip.on .ct-n { color: var(--accent); }
.ct-note:empty { display: none; }
.ct-note p { margin: 0; }
.ct-note .callout { margin: 0; }
.ct-sync svg, .ct-recent > svg { vertical-align: -2px; color: var(--text-3); }
.ct-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); gap: 14px; align-items: start; }
.ct-pad { padding: 10px 14px; margin: 0; }

/* ---------------------------------------------------------------- the list */
.ct-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden; min-width: 0; }
.ct-list > .empty, .ct-list > .loading, .ct-list > .callout { margin: 14px; }
.ct-head, .ct-row { display: grid; grid-template-columns: 36px minmax(0, 1.4fr) minmax(0, 1.2fr) minmax(0, .8fr); gap: 12px; align-items: center; padding: 0 14px; }
.ct-head { height: 34px; font-size: 12px; font-weight: 600; color: var(--text-3); border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.ct-row { min-height: 54px; padding-top: 6px; padding-bottom: 6px; border-bottom: 1px solid var(--border); cursor: pointer; scroll-margin-top: 80px; }
.ct-row:last-child { border-bottom: 0; }
.ct-row:hover { background: var(--hover); }
.ct-row.on { background: var(--accent-soft); }
.ct-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ct-row.inactive { opacity: .7; }
.ct-name { display: flex; flex-direction: column; min-width: 0; }
.ct-name b { font-weight: 620; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-sub, .ct-mail, .ct-phone { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-mail { color: var(--text-2); }
.ct-star { margin-left: 6px; color: var(--warn); }
.ct-star svg { fill: currentColor; vertical-align: -1px; }
.ct-fav.on .ct-star-ic { fill: currentColor; }
.ct-az { display: flex; flex-wrap: wrap; gap: 2px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.ct-az button { min-width: 28px; height: 28px; padding: 0 6px; font-size: 12.5px; font-weight: 650; background: transparent; border: 0; box-shadow: none; color: var(--accent); }
.ct-az button:hover { background: var(--hover); }

/* initials: the colour says which kind of contact */
.ct-av { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
  color: #fff; background: var(--ct-own); letter-spacing: .02em; }
.ct-av.big { width: 52px; height: 52px; font-size: 18px; }
.ct-av.k-customer { background: var(--ct-cust); }
.ct-av.k-supplier { background: var(--ct-sup); }
.ct-av.k-colleague { background: var(--ct-col); }
.ct-av.k-mail, .ct-av.k- { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border-2); }

/* ---------------------------------------------------------------- a contact's card */
.ct-card { position: sticky; top: 72px; min-width: 0; }
.ct-card:empty { display: none; }
.ct-card > .loading, .ct-card > .callout, .ct-cardin { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 16px; }
.ct-cardin { display: flex; flex-direction: column; gap: 12px; }
.ct-card-head { display: flex; gap: 12px; align-items: flex-start; }
.ct-card-t { flex: 1; min-width: 0; }
.ct-card-t h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.ct-card-t .muted { font-size: 13.5px; }
.ct-kind { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.ct-fav svg { color: var(--text-3); }
.ct-fav.on svg { color: var(--warn); fill: currentColor; }
.ct-acts, .ct-edits { display: flex; flex-wrap: wrap; gap: 6px; }
.ct-edits { padding-top: 10px; border-top: 1px solid var(--border); }
.ct-dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.ct-dl dt { color: var(--text-3); }
.ct-dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.ct-addr { height: auto; min-height: 0; padding: 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
.ct-pre { white-space: pre-wrap; }
.ct-recent { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 13.5px; }
.ct-recent .link { height: auto; min-height: 0; padding: 0; white-space: normal; text-align: left; }
.ct-recent > div { flex-basis: 100%; }
.ct-cardin > p { margin: 0; }

/* ---------------------------------------------------------------- the dialogs and the type-ahead */
.ct-form { display: flex; flex-direction: column; gap: 12px; }
.ct-form > label.f, .ct-form > div > label.f { margin: 0; }
.ct-form > div:empty { display: none; }
.ct-form > div { display: flex; flex-direction: column; gap: 10px; }
.ct-form .ct-who { margin: -6px 0 0; }
.ct-wf { position: relative; }
.ct-wf input { width: 100%; }
.ct-wf-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5; }
.ct-ac, .ct-wf-list { max-height: 300px; overflow-y: auto; padding: 4px; background: var(--surface); border: 1px solid var(--border-2);
  border-radius: 10px; box-shadow: var(--shadow-lg, 0 10px 30px rgba(0, 0, 0, .25)); }
.ct-ac { position: fixed; z-index: 200; }
.ct-ac-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; min-height: 44px; }
.ct-ac-item > svg { color: var(--text-3); flex: none; }
.ct-ac-item.on, .ct-ac-item:hover { background: var(--accent-soft); }
.ct-ac-item .ct-av { width: 30px; height: 30px; font-size: 11.5px; }
.ct-ac-t { min-width: 0; flex: 1; }
.ct-ac-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-ac-sub { font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-tag { margin-left: 6px; font-size: 11px; font-weight: 600; color: var(--ct-col); }
.ct-tag.ct-tag-mail { font-weight: 500; color: var(--text-3); }
.ct-ac-none { padding: 10px 8px; }
.ct-pick { display: flex; flex-direction: column; gap: 8px; }
.ct-pick-list { display: flex; flex-direction: column; max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.ct-pick-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; min-height: 48px; border: 0; border-bottom: 1px solid var(--border);
  background: transparent; box-shadow: none; border-radius: 0; text-align: left; justify-content: flex-start; cursor: pointer; height: auto; }
.ct-pick-row:last-child { border-bottom: 0; }
.ct-pick-row:hover { background: var(--hover); }
.ct-pick-t { display: flex; flex-direction: column; min-width: 0; }
.ct-pick-t .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-howto { padding-left: 18px; margin: 8px 0 0; color: var(--text-2); }
.ct-howto li { margin: 4px 0; }

/* ---------------------------------------------------------------- the phone: cards, the card as a pull-up sheet */
.ct-sheet-bg { position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; }
.ct-sheet { width: 100%; max-height: 88vh; display: flex; flex-direction: column; background: var(--bg, var(--surface));
  border-radius: 16px 16px 0 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, .3); animation: ct-up .18s ease-out; }
.ct-sheet-bar { position: relative; display: flex; justify-content: flex-end; padding: 6px 6px 0; }
.ct-grip { position: absolute; left: 50%; top: 8px; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: var(--border-2); }
.ct-sheet-body { overflow-y: auto; padding: 0 10px calc(16px + env(safe-area-inset-bottom, 0px)); }
.ct-sheet-body .ct-cardin { border: 0; box-shadow: none; padding: 6px 6px 10px; }
@keyframes ct-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }

@media (max-width: 1100px) { .ct-body { grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); } .ct-head, .ct-row { grid-template-columns: 36px minmax(0, 1.4fr) minmax(0, 1.3fr); } .ct-phone, .ct-head span:last-child { display: none; } }
@media (max-width: 760px) {
  .ct-body { grid-template-columns: 1fr; }
  .ct-card { display: none; }
  .ct-head { display: none; }
  .ct-row { grid-template-columns: 40px minmax(0, 1fr); min-height: 60px; gap: 10px; }
  .ct-row .ct-av { width: 38px; height: 38px; }
  .ct-mail { grid-column: 2; margin-top: -6px; }
  .ct-top .btn, .ct-top button:not(.htip) { min-height: 44px; }
  .ct-search { order: -1; }
  .ct-top .spacer, .ct-top .htip { display: none; }     /* help stays in the top bar's ? */
  .ct-search { flex-basis: 100%; max-width: none; height: 44px; }
  .ct-page .ct-search input, .ct-form input, .ct-form select, .ct-form textarea, .ct-pick input, .ct-wf input { font-size: 16px; }
  .ct-chip { height: 36px; }
  .ct-az button { min-width: 34px; height: 34px; }
  .ct-acts .btn, .ct-acts button, .ct-edits button, .ct-fav { min-height: 44px; }
  .ct-acts > * { flex: 1 1 auto; justify-content: center; }
}
