:root {
  color-scheme: light;
  --bg: #f5f3ec;
  --card: #fffefa;
  --text: #243a31;
  --muted: #5b685f;
  --line: #d9ddd2;
  --accent: #244d3c;
  --amber: #fbefd3;
  --error: #9a3026;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 "Work Sans",-apple-system,"Segoe UI",sans-serif;
}

h1,h2,h3,.brand {
  font-family: "Fraunces",Georgia,serif;
  font-weight: 600;
  text-wrap: balance;
  line-height: 1.15;
}

h1 {
  font-size: clamp(2.2rem,4vw,3.7rem);
  margin: .5rem 0 1rem;
}

h2 {
  font-size: 1.65rem;
  margin: 0 0 .8rem;
}

h3 {
  font-size: 1.2rem;
}

p {
  margin: .5rem 0 1rem;
}

button,input,textarea {
  font: inherit;
}

button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  padding: .7rem 1rem;
  cursor: pointer;
  min-height: 44px;
}

button:hover:not(:disabled) {
  background: #34634d;
}

button:disabled {
  opacity: .6;
  cursor: wait;
}

a {
  color: var(--accent);
  text-underline-offset: 3px;
}

input,textarea {
  background: white;
  color: var(--text);
  border: 1px solid #9ba99d;
  border-radius: 7px;
  padding: .7rem;
  width: 100%;
  min-width: 0;
}

input[type=checkbox] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

label {
  display: block;
  font-size: .9rem;
  font-weight: 500;
}

textarea {
  resize: vertical;
}

button:focus-visible,input:focus-visible,textarea:focus-visible,a:focus-visible,summary:focus-visible {
  outline: 3px solid #b36b16;
  outline-offset: 4px;
}

[hidden] {
  display: none!important;
}

#nav-bar {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: 1.2rem max(1.5rem,calc((100vw - 1200px)/2));
  background: var(--accent);
  color: white;
}

.brand {
  font-size: 1.4rem;
  margin-right: auto;
  white-space: nowrap;
}

.brand-detail {
  display: block;
  font: .65rem/1.8 "IBM Plex Mono",monospace;
  letter-spacing: .07em;
  color: #d3e0d3;
}

.nav-tab {
  background: transparent;
  color: #edf2e9;
  white-space: nowrap;
}

.nav-tab.active {
  background: #f1f3e8;
  color: var(--accent);
}

main {
  max-width: 1248px;
  margin: auto;
  padding: 2rem 1.5rem 4rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-radius: 18px;
  overflow: hidden;
  background: #e7ebdf;
  margin-bottom: 1.5rem;
}

.hero-copy {
  padding: 2.5rem;
}

.hero-copy p:last-child {
  color: var(--muted);
}

.hero-photo {
  min-height: 280px;
  background: #cad6c3 url('/static/images/background.jpeg') center/cover no-repeat;
}

.eyebrow {
  font: .72rem/1.6 "IBM Plex Mono",monospace;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  margin: 0 0 .65rem;
}

.counts {
  display: flex;
  gap: 2rem;
  padding: .3rem 0 1.5rem;
  flex-wrap: wrap;
}

.count-number {
  font: 1.6rem "IBM Plex Mono",monospace;
  color: var(--accent);
  margin-right: .5rem;
}

.visit-callout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  border: 1px solid #cbd5c1;
  border-left: 5px solid var(--accent);
  background: #eaf0e1;
  border-radius: 12px;
  padding: 1.6rem 2rem;
  margin-bottom: 2.5rem;
}

.visit-callout p:last-child {
  margin: 0;
}

.visit-callout button {
  flex-shrink: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.5rem 0;
}

.task-grid,.secondary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.pane,#chat-panel,.category {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem;
  min-width: 0;
}

.hint,.empty-hint {
  color: var(--muted);
  font-size: .9rem;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .8rem 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.todo-actions {
  display: flex;
  align-items: center;
  gap: .45rem;
  flex-shrink: 0;
}

.todo-item label {
  display: flex;
  align-items: center;
  gap: .7rem;
  flex: 1;
  min-width: 0;
  min-height: 44px;
}

.todo-text {
  overflow-wrap: anywhere;
  font-weight: 400;
}

.todo-done .todo-text {
  text-decoration: line-through;
  color: var(--muted);
}

.todo-item button {
  background: #edf1e6;
  color: var(--accent);
  font-size: .8rem;
  padding: .45rem .65rem;
  flex-shrink: 0;
}

.delete-button {
  background: transparent;
  color: #8a2d24;
  border-color: #c99b94;
}

.delete-button:hover:not(:disabled) {
  background: #fff0ed;
}

.todo-item button:hover:not(:disabled) {
  background: #dce5d3;
}

.badge {
  font: .7rem "IBM Plex Mono",monospace;
  border-radius: 4px;
  background: #eaf0e1;
  padding: .2rem .4rem;
}

.badge-high {
  background: var(--amber);
  color: #744700;
}

.todo-item .badge {
  display: none;
}

.todo-add {
  display: flex;
  gap: .6rem;
  margin-top: .5rem;
}

.task-card>label {
  margin-top: 1rem;
}

.todo-list-heading {
  font: .8rem "IBM Plex Mono",monospace;
  margin-top: 1.5rem;
}

.secondary-grid {
  grid-template-columns: 1.2fr 1fr;
  margin-top: 2rem;
}

#chat-form {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.chat-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

#chat-log {
  max-height: 280px;
  overflow: auto;
}

.chat-line {
  padding: .8rem;
  border-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-you {
  background: #eaf0e1;
}

.chat-assistant {
  background: #f1f0e9;
}

.chat-error,.lock-error {
  color: var(--error);
}

#task-feedback {
  position: sticky;
  top: .5rem;
  z-index: 20;
  background: #fff6dd;
  border: 1px solid #bf9655;
  border-radius: 8px;
  padding: .8rem 1rem;
}

#task-feedback.error {
  color: var(--error);
  background: #fff0ea;
}

.upcoming-heading {
  font-weight: 600;
}

.upcoming-row {
  padding: .7rem 0;
  border-bottom: 1px solid var(--line);
}

.upcoming-see-all {
  display: inline-block;
  margin-top: .8rem;
}

.mono-cell {
  font-family: "IBM Plex Mono",monospace;
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

#summary-text {
  font-size: .9rem;
}

.suggestions-section {
  margin-top: 3rem;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: 1rem;
  margin-top: 1.5rem;
}

.suggestion {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: #eeeee4;
  border-radius: 10px;
  padding: 1.2rem;
}

.suggestion p {
  flex: 1;
}

.suggestion button {
  background: transparent;
  color: var(--accent);
  border-color: #9eaf9b;
}

.visit-selector {
  margin-top: 2rem;
}

.visit-selector>button {
  margin-top: 1.5rem;
}

.category {
  margin: 1rem 0;
  padding: 1.2rem;
}

.category summary {
  cursor: pointer;
  font: 600 1.15rem/1.4 "Fraunces",Georgia,serif;
  min-height: 44px;
  padding: .5rem 0;
}

.contact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit,minmax(320px,1fr));
  gap: 1rem;
  margin-top: .9rem;
}

.contact-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 1.1rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.contact-card-header {
  min-width: 0;
}

.contact-card h3 {
  margin: 0;
  font-size: 1.2rem;
}

.contact-card-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: .9rem;
  padding-top: .75rem;
  border-top: 1px solid var(--line);
}

.contact-card-footer .delete-button {
  min-height: 36px;
  padding: .35rem .55rem;
  font-size: .78rem;
  flex: 0 0 auto;
}

.contact-role {
  color: var(--muted);
  margin: .35rem 0 .7rem;
}

.contact-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-bottom: .75rem;
}

.contact-status,.contact-priority {
  border-radius: 999px;
  padding: .25rem .55rem;
  font-size: .76rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.contact-status {
  background: #eef2ea;
}

.contact-priority {
  background: #efeee7;
}

.contact-priority.priority-high {
  background: var(--amber);
  color: #744700;
}

.contact-phone {
  display: inline-block;
  margin-bottom: .75rem;
}

.contact-services,.contact-notes p {
  margin: .5rem 0;
  overflow-wrap: anywhere;
}

.contact-notes {
  margin-top: .8rem;
  padding-top: .75rem;
  border-top: 1px solid var(--line);
}

.notes-preview {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.text-button {
  min-height: 32px;
  padding: .25rem 0;
  color: var(--accent);
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
  margin-top: .75rem;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: .9rem;
  min-width: 720px;
}

th,td {
  text-align: left;
  padding: .85rem .65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  overflow-wrap: anywhere;
  max-width: 300px;
}

th {
  color: var(--muted);
  font-size: .8rem;
  background: #f4f4ed;
}

td button {
  font-size: .8rem;
}

#vendor-search,#doc-search {
  max-width: 520px;
  margin: .4rem 0 1rem;
}

.doc-row-file-input {
  font-size: 0.78rem;
  max-width: 180px;
  color: var(--muted);
}

.docs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.notice {
  background: var(--amber);
  padding: 1rem;
  border-radius: 8px;
}

.inline-form {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
}

.inline-form label {
  flex: 1;
  min-width: 0;
}

.inline-form input {
  margin-top: .4rem;
}

.lock-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.lock-pane {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  width: 100%;
  max-width: 430px;
  overflow: hidden;
  padding: 2rem;
}

.lock-photo {
  height: 170px;
  background: #cad6c3 url('/static/images/background.jpeg') center/cover;
  margin: -2rem -2rem 2rem;
}

#lock-form {
  display: flex;
  flex-direction: column;
  gap: .8rem;
}

#mic-btn.recording {
  background: #9a3026;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: .55rem .7rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--accent);
}

.badge-idea {
  background: var(--amber);
  color: #744700;
}

.badge-change {
  background: var(--accent);
  color: white;
}

/* --- Overview: Recent Activity pane --- */

.activity-item {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .1rem .5rem;
  padding: .45rem 0;
  border-bottom: 1px solid var(--line);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-summary {
  font-size: .85rem;
  color: var(--text);
  flex: 1;
  min-width: 60%;
  overflow-wrap: break-word;
}

.activity-category {
  font-family: "IBM Plex Mono",monospace;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
}

.activity-date {
  font-family: "IBM Plex Mono",monospace;
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
  margin-left: auto;
}

td.notes-cell {
  max-width: 320px;
}

/* --- Expenses tab --- */

#export-csv-btn {
  display: inline-block;
  text-decoration: none;
}

.expense-form {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-top: 1rem;
}

.expense-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
}

.expense-form label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  flex: 1;
  min-width: 140px;
  font-size: .78rem;
  color: var(--muted);
}

.expense-notes-label {
  min-width: 100%;
}

.expense-form select,.history-controls select {
  font: inherit;
  padding: .7rem;
  border: 1px solid #9ba99d;
  border-radius: 7px;
  background: white;
  color: var(--text);
}

.expense-form > button[type="submit"] {
  align-self: flex-start;
}

.expense-receipt-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .6rem;
}

.expense-receipt-row label {
  flex: initial;
  flex-direction: row;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}

#expense-receipt-input {
  min-width: 0;
  max-width: 100%;
  flex: 1;
}

#scan-receipt-status {
  font-size: .8rem;
}

.receipt-thumb {
  max-height: 32px;
  max-width: 48px;
  border-radius: 4px;
  border: 1px solid var(--line);
  object-fit: cover;
}

/* --- History tab --- */

.history-controls {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  margin-bottom: 1rem;
}

.history-controls input {
  flex: 1;
  min-width: 160px;
}

@media(max-width:760px) {
  #nav-bar {
    padding: 1rem;
    flex-wrap: wrap;
    gap: .2rem;
  }
  .brand {
    width: 100%;
    margin-bottom: .7rem;
  }
  .nav-tab {
    flex: 1;
    padding: .6rem .4rem;
    font-size: .85rem;
  }
  main {
    padding: 1rem 1rem 3rem;
  }
  .hero {
    grid-template-columns: 1fr;
  }
  .hero-copy {
    padding: 1.6rem;
  }
  .hero-photo {
    min-height: 170px;
  }
  .hero-copy h1 br {
    display: none;
  }
  .counts {
    gap: .8rem 1.2rem;
    font-size: .85rem;
  }
  .count-number {
    font-size: 1.3rem;
  }
  .visit-callout {
    padding: 1.2rem;
    flex-direction: column;
    align-items: stretch;
  }
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }
  .task-grid,.secondary-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .pane,#chat-panel {
    padding: 1.1rem;
  }
  .suggestion-grid {
    grid-template-columns: 1fr;
  }
  .inline-form,.docs-header {
    flex-direction: column;
    align-items: stretch;
  }
  .expense-form-row,.history-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .todo-add button {
    padding: .7rem;
  }
  .todo-item {
    align-items: flex-start;
    gap: .45rem;
    flex-wrap: wrap;
  }
  .todo-item label {
    flex-basis: 100%;
  }
  .todo-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .todo-actions button {
    flex: 1 1 auto;
    max-width: none;
  }
  .contact-grid {
    grid-template-columns: 1fr;
  }
  .contact-card-header {
    align-items: flex-start;
  }
  .chat-line {
    font-size: .9rem;
  }
}

@media print {
  @page {
    margin: 15mm;
  }
  body {
    background: white;
    color: black;
    font-size: 11pt;
  }
  #nav-bar,#task-feedback,.view,#print-visit,.visit-selector {
    display: none!important;
  }
  #view-visit {
    display: block!important;
  }
  main {
    padding: 0;
    max-width: none;
  }
  .task-grid {
    display: block;
  }
  .pane {
    border: 0;
    padding: 0;
    margin-bottom: 2rem;
    break-inside: avoid;
  }
  .todo-item {
    break-inside: avoid;
  }
  .todo-item button {
    display: none;
  }
  .delete-button {
    display: none!important;
  }
  .todo-item input {
    display: none;
  }
  .todo-item::before {
    content: '';
    display: block;
    border: 1px solid black;
    width: 16px;
    height: 16px;
    line-height: 14px;
    text-align: center;
    flex: 0 0 16px;
  }
  .todo-item.todo-checked::before {
    content: '✓';
  }
  .section-heading {
    margin-top: 0;
  }
  h1 {
    font-size: 25pt;
  }
  .eyebrow,.hint {
    color: #444;
  }
}

@media (max-width: 760px) {
  .hero {
    position: relative;
  }
  .hero-copy {
    padding: 1.2rem;
    padding-right: 90px;
  }
  .hero-copy h1 {
    font-size: 1.7rem;
    margin-bottom: .4rem;
  }
  .hero-copy p:last-child {
    display: none;
  }
  .hero-photo {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 72px;
    min-height: 0;
  }
  .hero .eyebrow {
    font-size: .62rem;
  }
  .visit-callout {
    margin-bottom: 1.5rem;
    gap: .8rem;
  }
  .visit-callout h2 {
    font-size: 1.45rem;
  }
  .expense-form-row {
    flex-direction: column;
  }
  .history-controls {
    flex-direction: column;
    align-items: stretch;
  }
}
