:root {
  --bg: #f8eef4;
  --panel: #ffffff;
  --ink: #2b1b25;
  --muted: #6a4d5d;
  --line: #e5cfdc;
  --accent: #c13a7d;
  --accent-soft: #f6deea;
  --danger: #9b234f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at right top, var(--accent-soft), var(--bg) 45%);
  color: var(--ink);
  font-family: "Work Sans", "Segoe UI", sans-serif;
}

main {
  padding: 1rem;
}

h1,
h2,
h3,
summary {
  font-family: "Space Grotesk", "Avenir Next", sans-serif;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--accent-soft);
  gap: 0.8rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.topbar h1 .title-rep {
  font-weight: 400;
}

.warning-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  margin-right: 0.35rem;
  border: 1px solid var(--danger);
  border-radius: 0.2rem;
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: text-top;
}

.topbar p {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-brand {
  min-width: 0;
}

.topbar-logo-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
}

.header-logo {
  max-height: 68px;
  max-width: 180px;
  object-fit: contain;
}

.whoami {
  font-size: 0.86rem;
  color: var(--muted);
}

.panel,
details {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  padding: 0.9rem;
  margin-bottom: 0.9rem;
}

summary {
  cursor: pointer;
  font-weight: 700;
  margin-bottom: 0.8rem;
}

.admin-section > summary {
  margin-bottom: 0.35rem;
}

.admin-section > .card {
  margin-top: 0.35rem;
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem;
}

.split {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.between {
  justify-content: space-between;
}

.wrap {
  flex-wrap: wrap;
}

.search {
  width: 100%;
}

.form-grid {
  display: grid;
  gap: 0.28rem;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.form-grid .full {
  grid-column: 1 / -1;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  color: var(--muted);
  font-size: 0.88rem;
}

input,
select,
textarea,
button {
  font: inherit;
  border-radius: 7px;
  border: 1px solid var(--line);
  padding: 0.45rem 0.55rem;
}

select {
  min-height: 42px;
}

button {
  border: 0;
  color: white;
  background: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

button.ghost {
  background: var(--accent-soft);
  color: var(--ink);
}

button.danger {
  background: var(--danger);
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.8rem;
  font-size: 0.88rem;
}

#feedbackView table {
  table-layout: fixed;
}

#feedbackView th:nth-child(1),
#feedbackView td:nth-child(1) {
  width: 16%;
}

#feedbackView th:nth-child(2),
#feedbackView td:nth-child(2) {
  width: 16%;
}

#feedbackView th:nth-child(3),
#feedbackView td:nth-child(3) {
  width: 56%;
}

#feedbackView th:nth-child(4),
#feedbackView td:nth-child(4) {
  width: 12%;
  text-align: center;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 0.42rem;
  vertical-align: top;
}

th {
  background: var(--accent-soft);
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover {
  background: var(--accent-soft);
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 0.7rem;
  margin-top: 0.6rem;
}

.list {
  list-style: none;
  margin: 0.7rem 0 0;
  padding: 0;
}

.list li {
  border-bottom: 1px dashed var(--line);
  padding: 0.4rem 0;
}

.compact-list {
  margin-top: 0.35rem;
}

.compact-list li {
  padding: 0.22rem 0;
}

.tiny {
  font-size: 0.8rem;
  color: var(--muted);
}

.territory-cell {
  max-width: 380px;
}

.territory-snippet {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  max-width: 100%;
}

.territory-exclude {
  color: var(--danger);
  font-weight: 600;
}

.territory-editor {
  display: grid;
  gap: 0.55rem;
}

.field-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem;
}

.field-group > strong {
  display: block;
  margin-bottom: 0.28rem;
}

.state-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(52px, 1fr));
  gap: 0.25rem;
}

.state-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.18rem 0.3rem;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.78rem;
}

.state-chip input {
  margin: 0;
  accent-color: var(--accent);
}

.state-chip:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.state-chip.zip-implied,
.state-chip.zip-implied:has(input:checked) {
  background: #e4f0ff;
  border-color: #4d88d8;
}

.state-chip.zip-mismatch,
.state-chip.zip-mismatch:has(input:checked) {
  background: #fff6d8;
  border-color: #c9a227;
}

.state-chip.conflict,
.state-chip.conflict:has(input:checked) {
  background: #ffe7e7;
  border-color: var(--danger);
  color: #5e142f;
}

.state-chip.conflict input {
  accent-color: var(--danger);
}

.rep-picker {
  display: grid;
  gap: 0.35rem;
  min-width: 260px;
}

.rep-picker-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 7.2rem;
  max-height: 10rem;
  overflow: auto;
  background: #fff;
  padding: 0.2rem;
  display: grid;
  gap: 0.2rem;
}

.rep-picker-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.38rem 0.45rem;
  background: transparent;
  color: var(--ink);
  line-height: 1.15;
}

.rep-picker-item:hover {
  background: var(--accent-soft);
}

.rep-picker-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.field-caption {
  display: block;
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

#weeklyReportBody {
  margin-top: 0.8rem;
}

.report-rep-page {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem;
  margin-bottom: 0.8rem;
  background: var(--panel);
}

.report-rep-page h3,
.report-rep-page h4 {
  margin: 0.35rem 0 0.45rem;
}

.company-top-row {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: 2fr 1fr;
}

.company-box-grid {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: start;
}

.company-box {
  min-height: 0;
}

.company-box strong {
  display: block;
  margin-bottom: 0.45rem;
}

.company-box input,
.company-box select,
.company-box textarea {
  min-height: 42px;
  padding: 0.55rem 0.6rem;
}

.company-box select {
  height: 42px;
  line-height: 1.2;
}

.field-stack {
  display: grid;
  gap: 0.24rem;
  margin-top: 0.24rem;
}

.address-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.street-field {
  resize: vertical;
  min-height: 42px;
  max-height: 150px;
}

.documents-layout {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 2fr;
  gap: 0.9rem;
  align-items: start;
  margin-top: 0.55rem;
}

.documents-controls {
  display: grid;
  gap: 0.45rem;
  justify-items: start;
}

.docs-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
  direction: rtl;
}

.doc-card {
  direction: ltr;
  width: 170px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem;
  background: var(--panel);
  display: grid;
  gap: 0.3rem;
}

.doc-name {
  font-size: 0.84rem;
  word-break: break-word;
}

.small-btn {
  padding: 0.2rem 0.45rem;
  font-size: 0.76rem;
  justify-self: start;
}

.maps-link,
.email-link,
.phone-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
}

.readonly-value {
  min-height: 22px;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  display: block;
}

.address-clickable {
  cursor: pointer;
}

.address-clickable:hover {
  border-color: var(--line);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--line);
  transform: translateY(-1px);
}

.url-link {
  min-height: 22px;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  display: inline-block;
  word-break: break-all;
}

.readonly-multiline {
  white-space: pre-wrap;
  line-height: 1.4;
}

.photo-preview {
  margin-top: 0.5rem;
  width: 100%;
  height: 100%;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  width: 100%;
  min-height: 100%;
}

.photo-grid-item {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  overflow: hidden;
  background: #f8fbf8;
  display: grid;
  place-items: center;
  text-decoration: none;
}

.photo-grid-empty {
  background: transparent;
  border-style: dashed;
  opacity: 0.35;
}

.photo-grid-add {
  cursor: pointer;
  color: var(--accent);
  font-size: 1.6rem;
  font-weight: 700;
  background: #f8fbf8;
}

.photo-grid-count {
  position: absolute;
  right: 0.35rem;
  bottom: 0.35rem;
  padding: 0.18rem 0.35rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}

.contact-photo {
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: 0;
  object-fit: cover;
}

.company-standout {
  margin-bottom: 0.8rem;
  color: var(--accent);
  font-weight: 800;
  font-size: 1.15rem;
}

.contact-top-grid {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: start;
}

.contact-top-grid-two {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: 2fr 1fr;
  align-items: start;
}

.contact-assets-grid {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: 1fr 1fr;
  align-items: start;
}

.interaction-layout {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: 2fr 1fr;
  align-items: start;
}

.interaction-left-stack,
.interaction-right-stack {
  display: grid;
  gap: 0.6rem;
}

#interactionCreateForm input,
#interactionCreateForm select,
#interactionEditForm input,
#interactionEditForm select {
  min-height: 42px;
  height: 42px;
}

.name-row {
  display: grid;
  gap: 0.45rem;
  grid-template-columns: 1fr 1fr;
}

.photo-tile {
  margin-top: 0.45rem;
  border: 1px dashed var(--line);
  border-radius: 10px;
  min-height: 260px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #f8fbf8;
}

.photo-tile-editable {
  cursor: pointer;
}

.photo-tile-editable:hover {
  border-color: var(--line);
  background: var(--accent-soft);
}

.value-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.action-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 28, 22, 0.35);
  display: grid;
  place-items: center;
  z-index: 1000;
}

.action-modal {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem;
  min-width: 280px;
}

.invite-modal {
  width: min(640px, 92vw);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border-radius: 7px;
  padding: 0.45rem 0.7rem;
  text-decoration: none;
  color: #fff;
  background: var(--accent);
  font-weight: 600;
}

.user-filter-toggle {
  display: inline-flex;
  align-items: center;
  margin-left: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.user-role-select {
  min-width: 90px;
  height: 36px;
}

.user-active-cell {
  text-align: center;
}

.user-active-checkbox {
  width: 16px;
  height: 16px;
  vertical-align: middle;
}

#userAdminCard table {
  table-layout: fixed;
  width: 56%;
  min-width: 520px;
}

#userAdminCard th:nth-child(1),
#userAdminCard td:nth-child(1) {
  width: 16%;
}

#userAdminCard th:nth-child(2),
#userAdminCard td:nth-child(2) {
  width: 20%;
}

#userAdminCard th:nth-child(3),
#userAdminCard td:nth-child(3) {
  width: 12%;
}

#userAdminCard th:nth-child(4),
#userAdminCard td:nth-child(4) {
  width: 14%;
}

#userAdminCard th:nth-child(5),
#userAdminCard td:nth-child(5) {
  width: 8%;
  white-space: normal;
  overflow-wrap: anywhere;
}

#userAdminCard th:nth-child(6),
#userAdminCard td:nth-child(6) {
  width: 30%;
}

#userAdminCard td:nth-child(6) {
  white-space: nowrap;
}

.user-actions {
  flex-wrap: nowrap;
  gap: 0.35rem;
}

.action-modal h3 {
  margin: 0 0 0.7rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: #163024;
  color: #fff;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 750px) {
  .topbar {
    grid-template-columns: 1fr;
    justify-items: flex-start;
    gap: 0.6rem;
  }
  .topbar-logo-wrap {
    width: 100%;
    justify-content: flex-start;
  }
  .top-actions {
    justify-content: flex-start;
  }
  .company-top-row,
  .company-box-grid {
    grid-template-columns: 1fr;
  }
  .contact-top-grid,
  .contact-top-grid-two,
  .contact-assets-grid,
  .interaction-layout {
    grid-template-columns: 1fr;
  }
  .name-row {
    grid-template-columns: 1fr;
  }
  .address-row {
    grid-template-columns: 1fr;
  }
  .documents-layout {
    grid-template-columns: 1fr;
  }
  .docs-grid {
    justify-content: flex-start;
    direction: ltr;
  }
  .value-columns {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: letter;
    margin: 0.5in;
  }
  body {
    margin: 0;
    background: #fff;
  }
  main > section:not(#weeklyReportView),
  .topbar {
    display: none !important;
  }
  #weeklyReportView {
    display: block !important;
    position: static;
    width: 100%;
    border: 0;
    margin: 0;
    padding: 0;
  }
  #weeklyReportForm,
  #printWeeklyReportBtn {
    display: none !important;
  }
  .report-rep-page {
    page-break-inside: avoid;
    break-inside: avoid;
    border: 0;
    margin: 0;
    padding: 0 0 0.25rem;
  }
  .report-rep-page + .report-rep-page {
    page-break-before: always;
    break-before: page;
  }
}
