:root {
  color-scheme: light;
  --ink: #23201d;
  --muted: #746e68;
  --line: #e1d9d0;
  --canvas: #fbf7ef;
  --panel: #fffdf8;
  --soft: #f3eadf;
  --accent: #147c72;
  --accent-dark: #0c5f58;
  --rose: #c75d4d;
  --gold: #b7791f;
  --danger: #b42318;
  --focus: #2563eb;
  font-family:
    ui-rounded, "SF Pro Rounded", Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgb(199 93 77 / 0.16), transparent 34rem),
    linear-gradient(135deg, #fbf7ef 0%, #f7f8f2 46%, #f9f0e8 100%);
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 750;
  padding: 0 14px;
}

button:hover,
select:hover {
  border-color: #b8aea4;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-dark);
}

button.danger {
  border-color: #efb4ad;
  color: var(--danger);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefb;
  color: var(--ink);
  font-size: 16px;
  padding: 12px;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
button:focus-visible,
select:focus {
  outline: 3px solid color-mix(in srgb, var(--focus) 22%, transparent);
  border-color: var(--focus);
}

label {
  display: grid;
  gap: 7px;
  color: #4c4741;
  font-size: 0.9rem;
  font-weight: 750;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel,
.meeting-prep,
.quick-note,
.notes-section,
.profile-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(255 253 248 / 0.94);
  box-shadow: 0 20px 55px rgb(43 34 26 / 0.08);
}

.auth-panel {
  width: min(100%, 520px);
  padding: clamp(24px, 5vw, 42px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--rose);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-panel h1,
.topbar h1,
.profile-hero h2,
.empty-state h2 {
  margin: 0;
  letter-spacing: 0;
}

.auth-panel h1 {
  font-size: clamp(2rem, 4.4vw, 3.3rem);
  line-height: 1.02;
}

.auth-copy,
.muted,
.empty-state p {
  color: var(--muted);
  line-height: 1.55;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.app-shell {
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgb(255 253 248 / 0.9);
  padding: 16px clamp(16px, 4vw, 34px);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 0;
}

.topbar-actions span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  min-height: calc(100vh - 78px);
  min-width: 0;
}

.contact-finder {
  border-right: 1px solid var(--line);
  background: rgb(255 253 248 / 0.62);
  padding: 16px;
  min-width: 0;
}

.finder-actions {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
}

.search-label {
  flex: 1;
}

.contacts-list,
.notes-list,
.contact-detail {
  display: grid;
  gap: 12px;
}

.contact-card {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 11px;
  width: 100%;
  min-height: 72px;
  padding: 8px;
  text-align: left;
}

.contact-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.avatar,
.hero-photo {
  overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, #f8dfd7, #e0f0ec);
}

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
}

.avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--accent-dark);
  font-weight: 900;
}

.card-text strong,
.card-text span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-text span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.detail-panel {
  padding: clamp(16px, 4vw, 34px);
  min-width: 0;
}

.contact-detail {
  max-width: 1040px;
  min-width: 0;
}

.contact-detail.is-new-contact .profile-editor {
  order: -1;
}

.profile-hero {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 18px;
  align-items: end;
}

.hero-photo {
  position: relative;
  width: 132px;
  aspect-ratio: 1;
  border-radius: 8px;
  display: grid;
  place-items: center;
}

.hero-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-photo img[src=""] {
  display: none;
}

#photo-placeholder {
  color: var(--accent-dark);
  font-size: 1.9rem;
  font-weight: 900;
}

.profile-hero h2 {
  font-size: clamp(1.75rem, 4.2vw, 3.25rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  border: 1px solid #e3cab0;
  border-radius: 999px;
  background: #fff4e4;
  color: #6f4712;
  font-size: 0.84rem;
  font-weight: 800;
  padding: 6px 10px;
}

.tag-editor-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 10px;
}

.tag-pill {
  min-height: 34px;
  border-color: #e3cab0;
  border-radius: 999px;
  background: #fff4e4;
  color: #6f4712;
  font-size: 0.86rem;
  padding: 0 12px;
}

.tag-pill::after {
  content: " x";
  color: var(--rose);
  font-weight: 900;
}

.meeting-prep,
.quick-note,
.notes-section,
.profile-editor {
  padding: 16px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h3,
.profile-editor summary {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 900;
}

.section-title span {
  color: var(--rose);
  font-size: 0.9rem;
  font-weight: 850;
}

.prep-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.prep-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf2;
  padding: 12px;
}

.prep-card span {
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.prep-card p {
  margin: 5px 0 0;
  line-height: 1.45;
}

.quick-note {
  display: grid;
  gap: 10px;
}

.quick-note-actions,
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.note-card {
  border-left: 4px solid var(--rose);
  border-radius: 8px;
  background: #fffaf2;
  padding: 12px 14px;
}

.note-card time,
.note-card strong {
  display: inline-block;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 850;
}

.note-card strong {
  margin-left: 8px;
  color: var(--accent-dark);
  text-transform: capitalize;
}

.note-card p {
  margin: 7px 0 0;
  line-height: 1.5;
}

.profile-editor summary {
  cursor: pointer;
}

.contact-form {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.photo-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.children-fields {
  display: grid;
  gap: 10px;
}

.child-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(74px, 0.35fr) minmax(0, 1.7fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf2;
  padding: 10px;
}

.child-details {
  min-width: 0;
}

.wide {
  grid-column: 1 / -1;
}

.empty-state {
  max-width: 560px;
  padding-top: 10vh;
}

.empty-state h2 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1.02;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar,
  .topbar-actions,
  .workspace,
  .profile-hero,
  .form-grid,
  .prep-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .workspace {
    min-height: auto;
  }

  .contact-finder {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 72px;
    z-index: 5;
    backdrop-filter: blur(14px);
    max-width: 100vw;
  }

  .contacts-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(210px, calc(100vw - 52px));
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    padding-bottom: 6px;
  }

  .contact-card {
    max-width: calc(100vw - 52px);
  }

  .hero-photo {
    width: min(34vw, 126px);
  }

  .profile-hero {
    gap: 14px;
  }

  .quick-note-actions,
  .form-actions,
  .finder-actions {
    flex-wrap: wrap;
  }

  .quick-note-actions button,
  .quick-note-actions select,
  .form-actions button {
    flex: 1;
  }

  .child-row {
    grid-template-columns: 1fr;
  }

  .photo-field {
    grid-template-columns: 1fr;
  }
}
