* { box-sizing: border-box; }

:root {
  --border: #555;
  --soft: #ececec;
  --panel: #f5f5f5;
  --text: #111;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: #dcdcdc;
  color: var(--text);
}

.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #e8e8e8;
}

.login-card {
  width: 390px;
  background: white;
  border: 1px solid #999;
  padding: 24px;
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
}

.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card p { margin-top: 0; color: #666; }
.login-card label { display: block; font-weight: bold; font-size: 13px; margin-top: 14px; }
.login-card input { width: 100%; margin-top: 5px; padding: 9px; border: 1px solid #888; }
.login-card button { width: 100%; margin-top: 18px; }
.login-card small { display: block; margin-top: 12px; color: #777; line-height: 1.4; }
.login-card small.login-error { color: #8b1e1e; font-weight: 600; }

button {
  cursor: pointer;
  border: 1px solid #777;
  background: #efefef;
  padding: 8px 12px;
  font-weight: 600;
}
button:hover { background: #e2e2e2; }
button.secondary { background: white; }

.topbar {
  min-height: 52px;
  background: #f5f5f5;
  border-bottom: 1px solid #999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
}
.muted { color: #777; margin-left: 8px; font-size: 12px; }
.top-actions { display: flex; gap: 8px; }

.workspace {
  display: grid;
  grid-template-columns: 190px 1fr;
  min-height: calc(100vh - 52px);
}

.sidebar {
  background: #efefef;
  border-right: 1px solid #aaa;
  padding: 12px;
}
.sidebar .nav {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 4px;
  background: transparent;
}
.sidebar .nav.active { background: white; border-color: #555; }
.sidebar h3 { font-size: 13px; margin-bottom: 8px; }
.saved-list button {
  width: 100%;
  text-align: left;
  font-size: 11px;
  margin-bottom: 4px;
  padding: 6px;
}

.main { padding: 18px; overflow: auto; }

.hint {
  max-width: 8.5in;
  margin: 0 auto 10px;
  background: #fff9cf;
  border: 1px solid #c3b356;
  padding: 8px 10px;
  font-size: 12px;
}

.sheet {
  width: min(8.5in, 100%);
  min-height: 11in;
  margin: 0 auto;
  background: white;
  padding: .45in .48in .45in;
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
  font-size: 12px;
}

.invoice-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.25in;
  gap: .25in;
  align-items: start;
  width: 100%;
}
.company-block h1 { font-size: 17px; margin: 0 0 8px; letter-spacing: .2px; }
.company-block div { line-height: 1.35; }

.meta-table {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
}
.meta-head, .meta-value {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  min-height: 26px;
  padding: 5px 7px;
  text-align: center;
}
.meta-head { font-weight: bold; background: #fafafa; }

.cell-input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  padding: 1px 2px;
}
.centered { text-align: center; }
.numeric { text-align: right; }

.bill-to-box {
  width: 4.25in;
  max-width: 100%;
  margin-top: .28in;
  border: 1px solid var(--border);
}
.box-title {
  font-weight: bold;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}
.box-textarea {
  width: 100%;
  min-height: 1.05in;
  border: 0;
  outline: 0;
  resize: none;
  overflow: hidden;
  padding: 7px;
  font: inherit;
  line-height: 1.35;
  background: transparent;
}

.secondary-meta {
  width: 4.95in;
  margin-left: auto;
  margin-top: .18in;
  display: grid;
  grid-template-columns: 1.15in 1.35in 1fr;
  gap: 0;
  border: 1px solid var(--border);
}
.secondary-meta > div {
  min-width: 0;
  border-right: 1px solid var(--border);
}
.secondary-meta > div:last-child { border-right: 0; }
.secondary-meta .box-title {
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.meta-value,
.secondary-meta .meta-value {
  min-height: 30px;
  padding: 6px 7px;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.job-address-row,
.job-label,
.job-input { display: none !important; }

.items-table {
  margin-top: .12in;
  display: grid;
  grid-template-columns: .7in 1fr 1in 1.05in;
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  align-items: stretch;
}
.items-head {
  font-weight: bold;
  text-align: center;
  padding: 5px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}
.item-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  min-height: 4.8in;
  padding: 6px;
}
.description-cell { min-width: 0; }

.description-textarea {
  width: 100%;
  min-height: 4.55in;
  height: auto;
  overflow: hidden;
  resize: none;
  border: 0;
  outline: 0;
  padding: 0;
  font: inherit;
  line-height: 1.42;
  background: transparent;
}

.add-row { margin: 8px 0 10px; }

.extra-row {
  display: grid;
  grid-template-columns: .7in 1fr 1in 1.05in;
  border-left: 1px solid var(--border);
}
.extra-row > div {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  min-height: 34px;
  padding: 6px;
}
.extra-row textarea {
  width: 100%;
  min-height: 28px;
  border: 0;
  outline: 0;
  overflow: hidden;
  resize: none;
  font: inherit;
  background: transparent;
}

.invoice-footer {
  margin-top: .2in;
  display: grid;
  grid-template-columns: 1fr 2.25in;
  gap: .2in;
  align-items: stretch;
}
.contact-grid {
  display: grid;
  grid-template-columns: 1.15in 1.15in 1fr;
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
}
.contact-grid > div {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.contact-value { padding: 6px; min-height: 28px; }

.total-box {
  display: grid;
  grid-template-columns: .8in 1fr;
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
}
.total-label, .total-value {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  min-height: 54px;
  padding: 8px;
}
.total-label { font-size: 17px; font-weight: bold; }
.total-value { justify-content: flex-end; font-size: 16px; font-weight: bold; }

.panel {
  max-width: 950px;
  margin: 0 auto;
  background: white;
  border: 1px solid #aaa;
  padding: 18px;
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
}
.panel h2 { margin-top: 0; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px,1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.form-grid input, .form-grid textarea, .form-grid select {
  padding: 8px;
  border: 1px solid #999;
  font: inherit;
}
.form-grid textarea { min-height: 70px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border: 1px solid #aaa; padding: 7px; text-align: left; }
th { background: #f3f3f3; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sheet { width: 100%; min-height: 0; padding: 18px; }
}

@media print {
  @page { size: letter; margin: .25in; }
  body { background: white; }
  .no-print, .topbar, .sidebar, .hint, .data-screen { display: none !important; }
  .workspace { display: block; }
  .main { padding: 0; overflow: visible; }
  .sheet { width: 100%; min-height: 0; padding: 0; margin: 0; box-shadow: none; }
  input, textarea { color: #000; -webkit-text-fill-color: #000; }
  .items-table, .extra-row, .invoice-footer, .bill-to-box, .secondary-meta, .meta-table {
    break-inside: avoid;
  }
}

.save-status { padding: 10px 14px; background: #e9f4e9; border-bottom: 1px solid #999; font-size: 13px; }
.save-status.error { background: #ffe7e7; color: #851818; }
.saved-entry { margin-bottom: 12px; border-bottom: 1px solid #bbb; }
.saved-list .delete-document { width: auto; color: #8c2020; background: white; }
.top-actions { flex-wrap: wrap; }

#connectionLabel { display:block; color:#555; margin-top:4px; }
.workspace { grid-template-columns: 245px 1fr; }
#documentSearch { width:100%; padding:7px; margin-bottom:6px; }
#documentCount,.saved-entry small { display:block; font-size:11px; color:#555; margin-bottom:8px; overflow-wrap:anywhere; }
.document-toolbar { max-width:8.5in; margin:0 auto 12px; display:flex; align-items:center; justify-content:space-between; gap:12px; font-size:12px; }
.archive-row { display:flex; justify-content:space-between; border-bottom:1px solid #bbb; padding:10px; }
#tokenOutput { width:100%; margin:10px 0; }
@media (max-width:900px) { .workspace {grid-template-columns:1fr;} .sidebar {display:block;border-right:0;} .sidebar .nav {display:inline-block;width:auto;} .topbar {flex-wrap:wrap;gap:10px;} }
@media print { .document-toolbar {display:none;} }

dialog { width:min(850px,95vw); max-height:85vh; border:1px solid #777; }
dialog pre { white-space:pre-wrap; overflow-wrap:anywhere; background:#f5f5f5; padding:10px; }
.print-value {display:none;}
@media print {
 #printSheet input,#printSheet textarea {display:none;}
 .print-value {display:block;white-space:pre-wrap;overflow-wrap:anywhere;min-height:1em;}
 .items-table {break-inside:auto;}
 .numeric + .print-value {text-align:right;}
 .centered + .print-value {text-align:center;}
 dialog {display:none;}
}



.document-heading {
  text-align: right;
  justify-self: stretch;
  width: 100%;
  min-width: 0;
}
.document-title {
  font-size: 22px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.header-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border);
  width: 100%;
}
.header-meta-label,
.header-meta-value {
  text-align: center;
  min-width: 0;
}
.header-meta-label:nth-child(1),
.header-meta-value:nth-child(3) {
  border-right: 1px solid var(--border);
}
.header-meta-label {
  border-bottom: 1px solid var(--border);
}
.header-meta-label {
  font-weight: bold;
  background: #fafafa;
  padding: 4px 6px;
}
.header-meta-value {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.boxed-meta-input {
  min-height: 27px;
  padding: 4px 5px;
}
@media print {
  .print-page .invoice-header {
    grid-template-columns: minmax(0, 1fr) 2.25in;
    width: 100%;
  }
  .print-page .document-heading { width: 100%; min-width: 0; }
  .print-page .document-title { font-size: 20px; margin-bottom: 6px; }
  .print-page .header-meta-grid,
  .print-page .bill-to-box,
  .print-page .secondary-meta { box-sizing: border-box; }
}

/* V5: paginated print layout with a repeated document header on every page. */
.print-pages { display: none; }

@media print {
  @page { size: letter; margin: 0; }
  #printSheet { display: none !important; }
  #printPages {
    display: block !important;
    width: 8.5in;
    margin: 0;
    padding: 0;
  }
  .print-page {
    width: 8.5in;
    height: 11in;
    padding: .38in .45in .42in;
    background: #fff;
    color: #000;
    overflow: hidden;
    break-after: page;
    page-break-after: always;
    position: relative;
    font: 12px Arial, Helvetica, sans-serif;
  }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page .invoice-header { margin-bottom: .20in; }
  .print-page .company-block h1 { font-size: 16px; }
  .print-page .bill-to-box { margin-top: 0; }
  .print-page .secondary-meta { margin-top: .14in; }
  .print-page .print-items {
    margin-top: .12in;
    border: 1px solid var(--border);
    border-bottom: 0;
  }
  .print-page .print-items-head,
  .print-page .print-item-row {
    display: grid;
    grid-template-columns: .7in 1fr 1in 1.05in;
  }
  .print-page .print-items-head > div {
    font-weight: bold;
    text-align: center;
    background: #fafafa;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 5px;
  }
  .print-page .print-items-head > div:last-child { border-right: 0; }
  .print-page .print-item-row > div {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 6px;
    min-height: 28px;
  }
  .print-page .print-item-row > div:last-child { border-right: 0; }
  .print-page .print-description {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.42;
  }
  .print-page .print-qty,
  .print-page .print-rate,
  .print-page .print-amount { text-align: right; }
  .print-page .invoice-footer { margin-top: .16in; }
  .print-page-number {
    position: absolute;
    left: .45in;
    right: .45in;
    bottom: .16in;
    text-align: center;
    font-size: 10px;
    color: #666;
  }
  .print-measure { display: none !important; }
}

/* V13 customer deletion */
#customersTable .delete-document { white-space: nowrap; padding: 5px 9px; }
#customersTable td:last-child { width: 1%; white-space: nowrap; text-align: center; }

/* V19 customer/project shortcuts */
.customer-fill {
  width: 4.95in;
  margin: .22in 0 .08in;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px;
  align-items: end;
}
.customer-fill label { grid-column: 1 / -1; font-size: 12px; }
.customer-fill select {
  width: 100%;
  min-width: 0;
  border: 1px solid #777;
  background: white;
  padding: 7px;
  font: inherit;
}
.customer-fill button { white-space: nowrap; }
#customersTable td:last-child { white-space: nowrap; }
#customersTable td:last-child button + button { margin-left: 6px; }

/* Shared estimator availability calendar */
.availability-topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.availability-topbar h2 { margin-bottom: 4px; }
.availability-topbar p { margin-top: 0; color: #555; }
.calendar-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.calendar-nav strong { min-width: 145px; text-align: center; }
.calendar-weekdays,
.availability-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.calendar-weekdays {
  border-left: 1px solid #888;
  border-top: 1px solid #888;
}
.calendar-weekdays > div {
  padding: 7px 4px;
  text-align: center;
  font-weight: bold;
  background: #f3f3f3;
  border-right: 1px solid #888;
  border-bottom: 1px solid #888;
  font-size: 12px;
}
.availability-calendar {
  border-left: 1px solid #888;
}
.calendar-day {
  min-height: 92px;
  padding: 6px;
  border-right: 1px solid #888;
  border-bottom: 1px solid #888;
  background: white;
  text-align: left;
  font: inherit;
  position: relative;
  overflow: hidden;
}
.calendar-day:hover { background: #f8f8f8; }
.calendar-day.other-month { background: #f4f4f4; color: #999; }
.calendar-day.selected { outline: 2px solid #333; outline-offset: -2px; }
.calendar-day .day-number { font-weight: bold; font-size: 12px; }
.calendar-day .availability-status {
  display: block;
  margin-top: 8px;
  font-weight: bold;
  font-size: 11px;
}
.calendar-day .availability-note {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.calendar-day.available { background: #edf7ed; }
.calendar-day.limited { background: #fff7d6; }
.calendar-day.unavailable { background: #f9e8e8; }
.availability-editor {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1.1fr 1.5fr 1fr 1fr;
  gap: 8px;
  align-items: center;
  border: 1px solid #aaa;
  padding: 12px;
  background: #fafafa;
}
.availability-editor > div:first-child { grid-column: 1 / -1; }
.availability-editor input,
.availability-editor select { padding: 8px; border: 1px solid #999; font: inherit; }
.availability-editor #availabilityUpdatedBy { grid-column: 1 / -1; margin-left: 0; }
@media (max-width: 800px) {
  .availability-topbar { flex-direction: column; }
  .calendar-day { min-height: 72px; padding: 4px; }
  .availability-editor { grid-template-columns: 1fr; }
  .availability-editor > div:first-child,
  .availability-editor #availabilityUpdatedBy { grid-column: auto; }
}


/* Final release: printable payment receipts */
.payment-actions { white-space: nowrap; }
.payment-actions button { margin: 2px 4px 2px 0; }
@media print {
  .payment-receipt-page { font-size: 12px; }
  .payment-receipt-page .invoice-header { margin-bottom: .35in; }
  .receipt-from-box { border: 1px solid var(--border); margin-top: .2in; }
  .receipt-from-box .box-title, .receipt-details .box-title, .receipt-note .box-title { background: #fafafa; border-bottom: 1px solid var(--border); padding: 6px 8px; font-weight: bold; }
  .receipt-main-value { padding: 12px 10px 4px; font-size: 16px; font-weight: 700; }
  .receipt-sub-value { padding: 2px 10px 12px; }
  .receipt-details { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-right: 0; border-bottom: 0; margin-top: .2in; }
  .receipt-details > div { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); min-height: .78in; }
  .receipt-detail-value { padding: 12px 10px; font-size: 15px; }
  .receipt-details > div:first-child .receipt-detail-value { font-size: 22px; font-weight: 800; }
  .receipt-note { border: 1px solid var(--border); margin-top: .2in; }
  .receipt-note-value { padding: 12px 10px; white-space: pre-wrap; min-height: .65in; }
  .receipt-thanks { margin-top: .45in; text-align: center; font-size: 18px; font-weight: 700; }
  .receipt-footer { position: absolute; left: .45in; right: .45in; bottom: .38in; border-top: 1px solid #999; padding-top: 8px; text-align: center; font-size: 10px; color: #555; }
}

/* Payment receipt form clarity */
.payment-help { margin: -4px 0 12px; color: #555; font-size: 13px; }
.form-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-field > span { font-size: 12px; font-weight: 700; color: #333; }
.form-field input, .form-field textarea, .form-field select { width: 100%; }
.form-field-wide { grid-column: span 1; }
.payment-form-grid button.form-field-wide { grid-column: 1 / -1; }
@media (min-width: 700px) { .payment-form-grid .form-field-wide:first-child { grid-column: span 1; } }
