/* Contact Book — large, high-contrast, mobile-first */
:root {
  --bg: #F4F1EC;
  --card: #FFFFFF;
  --ink: #1B1B1B;
  --muted: #555049;
  --line: #D6D0C6;
  --accent: #1D4ED8;
  --accent-dark: #1E3A8A;
  --danger: #B91C1C;
  --ok-bg: #E7F5E8;
  --ok-line: #2E7D32;
  --err-bg: #FDECEC;
  --radius: 14px;
  --tap: 52px;
}
* { box-sizing: border-box; }
html { font-size: 20px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
}
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-dark); }
h1 { font-size: 1.75rem; line-height: 1.2; margin: .4rem 0 1rem; }
h1.tight { margin-top: 0; margin-bottom: .25rem; }
h2 { font-size: 1.2rem; margin: 0 0 .25rem; }
main { max-width: 1400px; margin: 0 auto; padding: 1rem 16px 4rem; }
:focus-visible { outline: 3px solid #F59E0B; outline-offset: 2px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.big { font-size: 1.15rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.inline { display: inline; margin: 0; }

/* Top bar */
.topbar {
  background: #1F2937; color: #fff; padding: .5rem 16px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .25rem 1rem;
}
.brand { color: #fff; font-weight: 700; font-size: 1.15rem; text-decoration: none; padding: .4rem 0; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; }
.topbar nav a, .topbar .linklike {
  color: #fff; text-decoration: none; padding: .5rem .8rem; border-radius: 10px; min-height: 44px;
  display: inline-flex; align-items: center; font-size: 1rem;
}
.topbar nav a.active { background: #fff; color: #1F2937; font-weight: 600; }
.topbar nav a:hover:not(.active), .topbar .linklike:hover { background: #374151; color: #fff; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.stack > * + * { margin-top: 1rem; }
.stack { display: block; }
.stack > input[type=hidden]:first-child + * { margin-top: 0; }
section.card { margin: 0; }
form.stack > section + section { margin-top: 1rem; }
.narrow { max-width: 560px; margin: 0 auto; }
.narrow-left { max-width: 560px; }
.pagehead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; }
.pagehead h1 { margin-bottom: .5rem; }
.count { font-weight: 400; color: var(--muted); font-size: 1.1rem; }
.empty { text-align: center; padding: 2rem 1rem; font-size: 1.1rem; }
.back { display: inline-block; padding: .4rem 0; font-size: 1.05rem; }

/* Forms */
label { display: block; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=search], select {
  display: block; width: 100%; margin-top: .3rem; font: inherit; font-weight: 400; color: var(--ink);
  min-height: var(--tap); padding: .55rem .75rem; border: 2px solid #8A8378; border-radius: 10px; background: #fff;
}
input:focus, select:focus { border-color: var(--accent); outline: 3px solid #BFDBFE; outline-offset: 0; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: .5rem; }
.two, .three { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .two { grid-template-columns: 1fr 1fr; }
  .three { grid-template-columns: 2fr 1fr 1fr; }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: .5rem 1.1rem; border-radius: 12px; border: 2px solid #8A8378;
  background: #fff; color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  text-align: center;
}
.btn:hover { background: #EEE9E1; color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.danger.big { background: var(--danger); color: #fff; }
.btn.big { min-height: 60px; font-size: 1.1rem; padding: .6rem 1.6rem; }
.actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-top: 1rem; }
.actions.sticky {
  position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; margin-top: 1rem;
  border-top: 1px solid var(--line);
}

/* Messages */
.flash { background: var(--ok-bg); border: 2px solid var(--ok-line); border-radius: 12px; padding: .75rem 1rem; margin-bottom: 1rem; font-weight: 600; }
.error { background: var(--err-bg); border: 2px solid var(--danger); border-radius: 12px; padding: .75rem 1rem; color: #7F1D1D; font-weight: 600; }

/* Tags */
.tag {
  display: inline-block; padding: .2rem .7rem; border-radius: 999px; font-size: .85rem; font-weight: 600;
  line-height: 1.4; text-decoration: none; white-space: nowrap;
}
.tag.big { font-size: 1rem; padding: .35rem .95rem; }
a.tag:hover { filter: brightness(.92); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip-toggle { position: relative; font-weight: 400; cursor: pointer; }
.chip-toggle input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip-toggle .tag {
  font-size: 1rem; padding: .45rem 1rem; min-height: 44px; display: inline-flex; align-items: center;
  background: #fff; color: var(--ink); border: 3px solid var(--c);
}
.chip-toggle input:checked + .tag { background: var(--c); color: var(--f); box-shadow: 0 0 0 2px #1B1B1B; }
.chip-toggle input:checked + .tag::before { content: "✓ "; white-space: pre; }
.chip-toggle input:focus-visible + .tag { outline: 3px solid #F59E0B; outline-offset: 2px; }

/* Swatches */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .5rem; }
.swatch { position: relative; font-weight: 600; }
.swatch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.swatch span {
  display: flex; align-items: center; justify-content: center; min-height: 52px; border-radius: 12px;
  border: 3px solid transparent; font-size: .95rem; cursor: pointer;
}
.swatch input:checked + span { border-color: #1B1B1B; box-shadow: 0 0 0 3px #fff inset; }
.swatch input:checked + span::before { content: "✓ "; white-space: pre; }
.swatch input:focus-visible + span { outline: 3px solid #F59E0B; outline-offset: 2px; }

/* Filters */
.filters { margin-bottom: 1rem; }
.filters > * + * { margin-top: 1rem; }
.searchrow { display: flex; gap: .5rem; }
.searchrow input { margin-top: 0; flex: 1; min-width: 0; }
.matchrow { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin-top: .75rem; }
.matchrow label, .sortrow label { font-weight: 400; }
.matchrow label { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; }
input[type=radio], input[type=checkbox] { width: 1.3rem; height: 1.3rem; accent-color: var(--accent); }
.sortrow { display: grid; grid-template-columns: 1fr; gap: .75rem; }
@media (min-width: 560px) { .sortrow { grid-template-columns: 1fr 1fr; } }
.filters .actions { margin-top: 1rem; }

/* Contact list: cards on phones */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.contact-card {
  display: flex; flex-direction: column; gap: .15rem; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .85rem 1rem; text-decoration: none; color: var(--ink);
}
.contact-card:hover { border-color: var(--accent); color: var(--ink); }
.contact-card .name { font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.contact-card .company { font-weight: 600; }
.contact-card .chips { margin-top: .35rem; }
.company { color: #3B3632; }

/* Contact list: table on wide screens */
.tablewrap { display: none; }
@media (min-width: 1000px) {
  .cards { display: none; }
  .tablewrap { display: block; overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
  .sortrow { display: none; }
}
table.grid { border-collapse: collapse; width: 100%; font-size: .9rem; }
.grid th, .grid td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid thead th { background: #EDE8E0; position: sticky; top: 0; }
.grid tbody tr:nth-child(even) { background: #FAF8F5; }
.grid tbody tr:hover { background: #EEF4FF; }
.grid .chips { gap: .25rem; }
.grid .tag { font-size: .75rem; }
a.sort { color: var(--ink); text-decoration: none; font-weight: 700; white-space: nowrap; display: inline-block; padding: .2rem 0; }
a.sort:hover { text-decoration: underline; }
a.sort.on { color: var(--accent); }
.arrow { font-size: .75em; margin-left: .25rem; }

/* Contact detail */
.details { margin: 1rem 0; display: grid; grid-template-columns: 1fr; gap: .1rem; }
.details dt { color: var(--muted); font-size: .9rem; margin-top: .6rem; }
.details dd { margin: 0; font-size: 1.15rem; }
.details dd a { font-weight: 600; }
@media (min-width: 640px) {
  .details { grid-template-columns: 11rem 1fr; gap: .6rem 1rem; }
  .details dt { margin-top: .15rem; }
}
.notes { background: #FBFAF7; border: 1px solid var(--line); border-radius: 10px; padding: .25rem 1rem; margin-bottom: 1rem; }
.notes p { margin: .6rem 0; }

/* Simple lists (tags, accounts) */
ul.list { list-style: none; padding: 0; margin: 0 0 1.5rem; }
ul.list li {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .85rem 0;
  border-bottom: 1px solid var(--line);
}
ul.list li:last-child { border-bottom: 0; }
.rowactions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

/* Rich-text editor */
.editor { background: #fff; font-size: 1.05rem; min-height: 220px; }
.ql-toolbar.ql-snow { border: 2px solid #8A8378; border-bottom-width: 1px; border-radius: 10px 10px 0 0; padding: .4rem; }
.ql-container.ql-snow { border: 2px solid #8A8378; border-top: 0; border-radius: 0 0 10px 10px; font: inherit; font-size: 1.05rem; }
.ql-editor { min-height: 220px; line-height: 1.5; }
.ql-snow.ql-toolbar button { width: 44px; height: 44px; padding: 8px; }
.ql-snow .ql-formats { margin-right: 8px !important; }

/* Bulk selection */
.selectall-mobile {
  display: inline-flex; align-items: center; gap: .6rem; font-weight: 600; min-height: 48px;
  margin-bottom: .4rem; cursor: pointer;
}
.cards li { display: flex; align-items: stretch; gap: .5rem; }
.cards .contact-card { flex: 1; min-width: 0; }
.pick {
  display: flex; align-items: flex-start; justify-content: center; padding-top: .9rem; width: 56px; flex: none; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.pick input, .pickcol input, .selectall-mobile input { width: 1.6rem; height: 1.6rem; cursor: pointer; }
.cards li.picked .pick, .cards li.picked .contact-card { border-color: var(--accent); background: #EEF4FF; }
.grid .pickcol { width: 1%; text-align: center; vertical-align: top; }
.grid td.pickcol input { margin-top: 0; }
.grid tbody tr.picked { background: #DCE8FF; }
@media (min-width: 1000px) { .selectall-mobile { display: none; } }

.bulkbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: none;
  background: #1F2937; color: #fff; padding: .6rem 16px calc(.6rem + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(0,0,0,.2);
  flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
}
.bulkbar.show { display: flex; }
body.bulk-active main { padding-bottom: 10rem; }
.bulkcount { font-size: 1.1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: 100%; }
.bulkbuttons { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; width: 100%; }
@media (min-width: 700px) {
  .bulkcount, .bulkbuttons { width: auto; }
  .bulkbuttons { display: flex; flex-wrap: wrap; }
}
.bulkbar .btn { min-height: 48px; padding: .4rem .5rem; white-space: nowrap; }
.bulkbar .btn.danger { background: #fff; }
.bulkbar .linkbtn { background: transparent; color: #fff; border-color: #6B7280; }
.bulkbar .linkbtn:hover { background: #374151; color: #fff; }
@media (min-width: 1000px) { .bulkbar { justify-content: center; } body.bulk-active main { padding-bottom: 6rem; } }

/* Bulk step page */
.tagbuttons { display: grid; gap: .5rem; }
.tagbutton {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: 100%;
  min-height: 60px; padding: .5rem .9rem; font: inherit; text-align: left; cursor: pointer;
  background: #fff; border: 2px solid var(--line); border-radius: 12px;
}
.tagbutton .muted { white-space: nowrap; }
.tagbutton:hover, .tagbutton:focus-visible { border-color: var(--accent); background: #EEF4FF; }
.selected-list summary { cursor: pointer; font-weight: 600; min-height: 44px; display: list-item; }
.selected-list ul { margin: .4rem 0 0; padding-left: 1.4rem; }

/* Business card scanning */
.headbuttons { display: flex; flex-wrap: wrap; gap: .5rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.scan-buttons { display: flex; flex-wrap: wrap; gap: .75rem; }
.scan-buttons .btn { position: relative; cursor: pointer; flex: 1 1 14rem; }
.scan-buttons .btn:focus-within { outline: 3px solid #F59E0B; outline-offset: 2px; }
/* Computers with a mouse can't "take a photo" — just show the upload button there. */
@media (hover: hover) and (pointer: fine) { .camera-only { display: none; } }
.scan-side.has-photo .scan-buttons .btn { min-height: var(--tap); font-size: 1rem; }
.scan-preview { display: flex; flex-direction: column; align-items: flex-start; gap: .5rem; }
.scan-preview[hidden] { display: none; }
.scan-preview img, .scan-thumbs img {
  max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid var(--line);
}
.scan-thumbs { display: flex; flex-wrap: wrap; gap: .75rem; }
.scan-result { margin-bottom: 1rem; border: 2px solid var(--ok-line); background: var(--ok-bg); }
.linkbtn-dark { background: none; border-color: transparent; color: var(--accent); text-decoration: underline; padding-left: 0; }
.scan-wait {
  position: fixed; inset: 0; z-index: 20; background: rgba(244, 241, 236, .94);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.scan-wait[hidden] { display: none; }
.scan-wait .card { max-width: 420px; width: 100%; }
.spinner {
  width: 56px; height: 56px; margin: 0 auto; border-radius: 50%;
  border: 6px solid #D6D0C6; border-top-color: var(--accent); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.scan-result > p:first-child { margin-top: 0; }
.tight-p { margin: .1rem 0; }
