:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-soft: #ebe7dd;
  --text: #15211a;
  --muted: #5b655e;
  --line: #d6d0c4;
  --green: #16784d;
  --green-dark: #10583a;
  --amber: #b66f16;
  --amber-soft: #fff1d9;
  --red: #b5463d;
  --red-soft: #fbe4e1;
  --blue: #315f8f;
  --blue-soft: #e6eef7;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  margin: 0;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-header {
  align-items: center;
  background: rgba(245, 243, 238, 0.98);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  min-height: 72px;
  padding: 0 4vw;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  align-items: center;
  color: inherit;
  display: inline-flex;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--green);
  color: #fff;
  display: inline-flex;
  font-weight: 700;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.brand small {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 400;
  margin-top: 2px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  min-height: 38px;
  padding: 0 12px;
}

.tab:hover,
.tab.is-active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

main {
  padding: 34px 4vw 60px;
}

.workspace {
  display: none;
}

.workspace.is-active {
  display: block;
}

.page-title {
  align-items: end;
  display: flex;
  gap: 24px;
  justify-content: space-between;
  margin-bottom: 28px;
}

.page-title.compact h1 {
  font-size: clamp(34px, 5vw, 56px);
}

.eyebrow {
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(40px, 5.8vw, 72px);
  line-height: 1;
  margin-bottom: 14px;
  max-width: 980px;
}

h2 {
  font-size: 22px;
  margin-bottom: 0;
}

.lead {
  color: var(--muted);
  font-size: 20px;
  line-height: 1.5;
  max-width: 760px;
}

.today-box {
  background: var(--surface);
  border: 1px solid var(--line);
  min-width: 170px;
  padding: 16px;
}

.today-box span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
}

.metrics {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 18px;
}

.metric {
  background: var(--red-soft);
  border: 1px solid var(--line);
  min-height: 120px;
  padding: 18px;
}

.metric.warning {
  background: var(--amber-soft);
}

.metric.blue {
  background: var(--blue-soft);
}

.metric.green {
  background: #e8f4ee;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 14px;
  min-height: 34px;
}

.metric strong {
  display: block;
  font-size: 42px;
  line-height: 1;
  margin-top: 16px;
}

.dashboard-grid,
.split-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
}

.quick-panel {
  margin-top: 18px;
}

.search-panel {
  margin-bottom: 18px;
}

.customer-list-panel,
.manual-panel {
  margin-top: 18px;
}

.manual-panel summary {
  cursor: pointer;
  font-size: 18px;
  font-weight: 800;
  list-style-position: inside;
}

.manual-form {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 16px;
}

.send-row {
  flex-wrap: wrap;
  margin-top: 8px;
}

.send-row .button {
  min-width: 92px;
}

.pilot-readiness-panel {
  margin-bottom: 18px;
}

.info-hero {
  align-items: center;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 18px;
}

.info-hero h2,
.info-card h2 {
  font-size: 24px;
}

.info-hero p {
  color: var(--muted);
  line-height: 1.55;
  max-width: 820px;
}

.info-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.info-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.price-line {
  color: var(--muted);
  margin: 0;
}

.price-line strong {
  color: var(--text);
}

.pilot-progress {
  background: var(--text);
  color: #fff;
  font-weight: 700;
  min-width: 72px;
  padding: 8px 10px;
  text-align: center;
}

.pilot-readiness-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.pilot-readiness-item {
  align-items: center;
  border: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  padding: 12px;
}

.pilot-readiness-item.done {
  background: #e8f4ee;
}

.pilot-check {
  align-items: center;
  background: var(--amber-soft);
  border: 1px solid var(--line);
  color: var(--amber);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.pilot-readiness-item.done .pilot-check {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.pilot-test-list {
  display: grid;
  gap: 10px;
}

.pilot-test-item {
  align-items: center;
  border: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  padding: 12px;
}

.pilot-test-item.done {
  background: #e8f4ee;
}

.pilot-test-check {
  align-items: center;
  display: inline-flex;
  gap: 8px;
}

.pilot-test-check input {
  min-height: 20px;
  width: 20px;
}

.pilot-test-check span {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.pilot-test-item.done .pilot-test-check span {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.pilot-test-notes {
  margin-top: 14px;
}

.search.wide {
  max-width: 420px;
}

.global-search-results {
  display: grid;
  gap: 10px;
}

.search-result-row {
  align-items: center;
  border: 1px solid var(--line);
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 14px;
}

.search-result-kind {
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.work-plan-panel {
  margin-bottom: 18px;
}

.work-plan-list {
  display: grid;
  gap: 10px;
}

.work-plan-item {
  align-items: center;
  border: 1px solid var(--line);
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 14px;
}

.work-plan-item.visit {
  background: #e8f4ee;
}

.work-plan-item.due {
  background: var(--amber-soft);
}

.work-plan-item.followup {
  background: var(--blue-soft);
}

.work-plan-date {
  color: var(--green-dark);
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}

.service-day-panel {
  margin-bottom: 18px;
}

.service-day-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.service-day-controls input {
  min-width: 150px;
  width: auto;
}

.service-day-list,
.service-day-section {
  display: grid;
  gap: 12px;
}

.service-day-section + .service-day-section {
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 16px;
}

.service-day-section h3 {
  font-size: 18px;
  margin-bottom: 0;
}

.service-day-card {
  align-items: center;
  border: 1px solid var(--line);
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 14px;
}

.service-day-card.visit {
  background: #e8f4ee;
}

.service-day-card.candidate {
  background: var(--amber-soft);
}

.service-day-status {
  color: var(--green-dark);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.appointment-panel {
  margin-top: 18px;
}

.appointment-list {
  display: grid;
  gap: 10px;
}

.appointment-item {
  align-items: center;
  border: 1px solid var(--line);
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 14px;
}

.appointment-date {
  color: var(--green-dark);
  font-size: 18px;
  font-weight: 700;
}

.customer-detail {
  margin-top: 18px;
}

.customer-detail-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
}

.customer-profile,
.customer-detail-section {
  border: 1px solid var(--line);
  padding: 16px;
}

.customer-profile h3,
.customer-detail-section h3 {
  font-size: 18px;
  margin-bottom: 12px;
}

.customer-profile-head {
  align-items: start;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) minmax(220px, auto);
}

.customer-contact-lines {
  text-align: right;
}

.customer-stats {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  margin-top: 16px;
}

.customer-stat {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  min-height: 78px;
  padding: 12px;
}

.customer-stat span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 8px;
}

.customer-stat strong {
  font-size: 24px;
}

.customer-detail-main {
  display: grid;
  gap: 14px;
}

.customer-info-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 16px;
}

.customer-info-card {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  padding: 12px;
}

.customer-info-card h4 {
  font-size: 15px;
  margin-bottom: 8px;
}

.customer-note-block {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 14px;
}

.customer-device-list,
.customer-history-list,
.contact-log-list {
  display: grid;
  gap: 10px;
}

.customer-device-row,
.customer-work-row,
.contact-log-row {
  align-items: center;
  border: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 12px;
}

.customer-work-row {
  background: #fff;
  cursor: pointer;
}

.customer-work-row:hover,
.customer-work-row:focus {
  border-color: var(--green);
  outline: none;
}

.quick-form {
  grid-template-columns: repeat(3, 1fr);
}

.phone-row {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(110px, 130px) minmax(0, 1fr);
}

.phone-row select,
.phone-row input {
  min-width: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 22px;
}

.completed-panel {
  margin-bottom: 18px;
}

.service-history-panel {
  margin-bottom: 18px;
}

.panel-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 16px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.filter-row select {
  min-width: 150px;
  width: auto;
}

select,
input,
textarea {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  min-height: 42px;
  padding: 9px 10px;
  width: 100%;
}

textarea {
  line-height: 1.4;
  resize: vertical;
}

.search {
  max-width: 220px;
}

.button-row,
.button-column {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.button-column {
  align-items: flex-start;
  flex-direction: column;
}

.button {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
}

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

.button.secondary {
  background: var(--surface-soft);
}

.button.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.detail-panel > label {
  margin-bottom: 12px;
}

.file-button {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  display: inline-flex;
  font-weight: 700;
  min-height: 44px;
  padding: 0 14px;
}

.file-button input {
  display: none;
}

.helper {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  margin: 12px 0 0;
}

.due-list,
.completed-service-list,
.history-list {
  display: grid;
  gap: 10px;
}

.service-summary {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.service-summary h3 {
  font-size: 18px;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.button.small {
  font-size: 13px;
  min-height: 34px;
  padding: 0 10px;
}

.print-document {
  display: none;
}

.contact-status {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding-top: 18px;
}

.contact-status h3 {
  font-size: 18px;
  margin-bottom: 0;
}

.contact-chip {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  margin-left: 6px;
  min-height: 26px;
  padding: 0 8px;
  vertical-align: middle;
}

.contact-chip.done {
  background: #e8f4ee;
  color: var(--green-dark);
}

.contact-chip.warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.contact-chip.muted {
  background: var(--surface-soft);
  color: var(--muted);
}

.due-item,
.completed-service-item,
.history-item {
  border: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding: 14px;
}

.due-item,
.completed-service-item {
  background: #fff;
  grid-template-columns: 1fr auto;
}

.due-item.is-late {
  border-color: var(--red);
}

.due-actions {
  align-self: center;
  display: grid;
  gap: 8px;
  min-width: 110px;
}

.item-title {
  font-weight: 700;
}

.item-meta {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.badge {
  align-items: center;
  border: 1px solid var(--line);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  min-height: 28px;
  padding: 0 8px;
}

.badge.overdue {
  background: var(--red-soft);
  color: var(--red);
}

.badge.soon {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.ok {
  background: #e8f4ee;
  color: var(--green-dark);
}

.badge.muted {
  background: var(--surface-soft);
  color: var(--muted);
}

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

.form-grid.nested {
  margin-top: 14px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
}

.option-row {
  align-content: center;
  align-items: center;
  display: flex;
  gap: 10px;
  min-height: 42px;
}

.option-row input {
  min-height: 20px;
  width: 20px;
}

.is-disabled {
  opacity: 0.55;
}

.is-hidden {
  display: none !important;
}

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

.record-context {
  background: var(--blue-soft);
  border: 1px solid var(--line);
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 16px;
  padding: 14px;
}

.template-tools {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  padding: 14px;
}

.button-row.compact {
  flex-wrap: wrap;
  margin-top: 0;
}

.record-context strong {
  display: block;
  margin-bottom: 4px;
}

.advanced-fields {
  background: #faf9f6;
  border: 1px solid var(--line);
  padding: 14px;
}

.advanced-fields summary {
  color: var(--green-dark);
  cursor: pointer;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 640px;
  width: 100%;
}

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

th {
  color: var(--muted);
  font-size: 13px;
}

tr.is-selected td {
  background: #e8f4ee;
}

.check-list {
  margin: 0;
  padding-left: 20px;
}

.check-list li {
  line-height: 1.5;
  margin-bottom: 12px;
}

.toast {
  background: var(--text);
  bottom: 18px;
  color: #fff;
  left: 50%;
  min-width: 220px;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 20px);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 20;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1050px) {
  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .customer-info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .split-layout,
  .customer-detail-grid {
    grid-template-columns: 1fr;
  }

  .quick-form {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding-bottom: 14px;
    padding-top: 14px;
  }

  .tabs {
    justify-content: flex-start;
    width: 100%;
  }

  .page-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .info-hero {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .customer-info-grid {
    grid-template-columns: 1fr;
  }

  .metrics,
  .form-grid,
  .quick-form {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 38px;
  }

  .lead {
    font-size: 17px;
  }

  .panel-head,
  .due-item,
  .completed-service-item,
  .customer-profile-head,
  .search-result-row,
  .pilot-readiness-item,
  .pilot-test-item,
  .work-plan-item,
  .service-day-card,
  .appointment-item,
  .customer-device-row {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

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

  .customer-stats {
    grid-template-columns: 1fr;
  }

  .customer-contact-lines {
    text-align: left;
  }

  .filter-row {
    justify-content: stretch;
  }

  .service-day-controls,
  .filter-row select,
  .filter-row .button {
    width: 100%;
  }

  .service-day-controls input,
  .service-day-controls .button {
    width: 100%;
  }

  .due-actions {
    min-width: 0;
  }

  .button-row {
    flex-direction: column;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  main,
  .toast {
    display: none !important;
  }

  .print-document {
    color: #111;
    display: block;
    font-family: Arial, Helvetica, sans-serif;
    padding: 24mm 18mm;
  }

  .print-document h1 {
    border-bottom: 2px solid #111;
    font-size: 24px;
    line-height: 1.2;
    margin: 0 0 18px;
    padding-bottom: 12px;
  }

  .print-meta {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr 1fr;
    margin-bottom: 18px;
  }

  .print-block {
    border: 1px solid #999;
    margin-bottom: 14px;
    padding: 12px;
  }

  .print-block h2 {
    font-size: 15px;
    margin: 0 0 8px;
  }

  .print-block p {
    font-size: 13px;
    line-height: 1.45;
    margin: 0 0 6px;
  }

  .print-signature {
    display: grid;
    gap: 36px;
    grid-template-columns: 1fr 1fr;
    margin-top: 34px;
  }

  .print-line {
    border-top: 1px solid #111;
    font-size: 12px;
    padding-top: 8px;
    text-align: center;
  }
}
