@import url("https://fonts.googleapis.com/css2?family=Dosis:wght@400;500;600;700&display=swap");

:root {
  --brand: #553527;
  --brand-dark: #541300;
  --bg: #f8f6f5;
}

body {
  margin: 0;
  font-family: "Dosis", sans-serif;
  background: var(--bg);
  padding: 2rem;
}

button {
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.3s;
  font-size: 1rem;
}
button:hover {
  background: var(--brand-dark);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

h1 {
  color: var(--brand);
  margin: 0 0 1.5rem;
}
/* Clients table */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 16px;
  background: transparent;
}
.table thead th {
  background: var(--brand);
  color: #fff;
  padding: 1rem;
  border: none;
  font-weight: 600;
}
.table tbody tr {
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
  border-radius: 10px;
}
.table th,
.table td {
  background: #fff;
  padding: 1.75rem 2rem; /* 1.75rem = more vertical space, 2rem = horizontal */
  line-height: 1.8; /* adds extra inner spacing for text */
  text-align: left;
  vertical-align: middle; /* centers content vertically */
}

.table tbody tr td:first-child {
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}
.table tbody tr td:last-child {
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

/* Pagination */
.pagination {
  margin-top: 1.5rem;
  text-align: center;
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
}
.page-info {
  color: #333;
}
/* ---------- Shell ---------- */
body {
  padding: 0;
}
.container {
  max-width: 1100px;
  margin: 72px auto 96px;
  padding: 0 24px;
}

/* ---------- Topbar / Nav ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #fff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 24px;
}
.nav__brand {
  font-weight: 700;
  color: var(--brand);
  text-decoration: none;
  letter-spacing: 0.5px;
}
.nav__links {
  display: flex;
  gap: 20px;
  align-items: center;
}
.nav__links a {
  position: relative;
  color: #272727;
  text-decoration: none;
  padding: 8px 2px;
}
.nav__links a::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 0;
  height: 2px;
  background: var(--brand);
  border-radius: 6px;
  transition: width 0.25s, left 0.25s;
}
.nav__links a:hover::after {
  width: 100%;
  left: 0;
}
.nav__links .is-active {
  color: var(--brand);
}
.nav__links .is-active::after {
  width: 100%;
  left: 0;
}

/* ---------- Page head ---------- */
.pagehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0 12px;
}
.pagehead h1 {
  margin: 0;
  font-size: 28px;
}
#pdf-button-container {
  display: flex;
  gap: 8px;
}

/* ---------- Cards ---------- */
.card {
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.05);
}
.card--form {
  padding: 20px;
}

/* ---------- Sections ---------- */
.section {
  padding: 12px 0 4px;
}
.section + .section {
  border-top: 1px dashed rgba(0, 0, 0, 0.08);
  margin-top: 12px;
}
.section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.section__title {
  margin: 0 0 12px;
  color: var(--brand);
  font-size: 20px;
}

/* ---------- Form fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.field label {
  font-weight: 600;
  color: #351915;
}
.field input,
.field textarea,
.field select {
  width: 95%;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field textarea {
  min-height: 96px;
  resize: vertical;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(85, 53, 39, 0.12);
}
/* --- Fix product grid layout overriding global .field styles --- */
.product-item {
  display: grid;
  grid-template-columns: repeat(3, 1fr); /* 3 equal columns */
  gap: 14px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.05);
  padding: 14px;
  align-items: start;
}

.product-item .field {
  display: flex;
  flex-direction: column;
  min-width: 0; /* critical to prevent overflow in grid cells */
}

.product-item .field input,
.product-item .field textarea,
.product-item .field select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box; /* ensure consistent width inside grid cells */
}

.product-item .field:nth-child(4) {
  grid-column: 1 / -1; /* make description span all 3 columns */
}

.product-item textarea {
  min-height: 96px;
}

@media (max-width: 720px) {
  .product-item {
    grid-template-columns: 1fr; /* stack on mobile */
  }
}

/* ---------- Utilities: grid / layout ---------- */
.grid {
  display: grid;
  gap: 14px;
}
.grid--full {
  grid-column: 1 / -1;
}
.grid--2 {
  grid-template-columns: repeat(2, 1fr);
}
.grid--3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  align-items: start;
}

.grid--4 {
  grid-template-columns: repeat(4, 1fr);
}
/* --- Fix overlapping date/time fields --- */
.grid--3 .field input[type="date"],
.grid--3 .field input[type="datetime-local"],
.grid--3 .field input[type="number"] {
  max-width: 280px;
}

@media (max-width: 1024px) {
  .grid--3 .field input[type="date"],
  .grid--3 .field input[type="datetime-local"],
  .grid--3 .field input[type="number"] {
    max-width: 100%;
  }
}

.split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.stack {
  display: grid;
  gap: 14px;
}

/* ---------- Buttons ---------- */
.btn {
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 0.7rem 1.2rem;
  border-radius: 10px;
  font-weight: 300;
  cursor: pointer;
  transition: transform 0.05s ease;
  font-family: "Dosis", sans-serif;
}
.btn:active {
  transform: translateY(1px);
}
.btn--outline {
  background: #fff;
  color: var(--brand);
  border: 1px solid var(--brand);
}
.btn--ghost {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand);
  margin-top: 20px;
}

/* ---------- Form footer ---------- */
.form__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
  margin-top: 8px;
  border-top: 1px dashed rgba(0, 0, 0, 0.08);
}
#postCarpentryPaymentDate[readonly] {
  background: #f2f2f2;
  color: #777;
  border: 1px solid rgba(0, 0, 0, 0.1);
  cursor: not-allowed;
  box-sizing: border-box;
  height: 42px; /* match other inputs’ height */
  padding: 12px 14px; /* same as normal field */
  font-size: 15px;
  border-radius: 10px;
}
/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .grid--4 {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 720px) {
  .container {
    margin: 32px auto 48px;
  }
  .joborder-layout {
    flex-direction: column;
    gap: 24px;
  }
  .joborder-layout .container {
    width: 100%;
    order: 1;
  }
  .calculator {
    width: 100%;
    order: 2;
  }
  .nav {
    padding: 12px 16px;
  }
  .pagehead {
    flex-direction: column;
    align-items: flex-start;
  }
  .grid--3,
  .grid--2,
  .grid--4 {
    grid-template-columns: 1fr;
  }
  .card--form {
    .table th,
    .table td {
      padding: 1rem 1rem;
    }
    .table-responsive {
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }
    padding: 16px;
  }
}
.nav__logo {
  height: 80px;
  width: auto;
  display: block;
}

/* --- Mobile Navigation Sidebar --- */
.nav {
  position: relative; /* Ensure toggle button is positioned correctly */
}

#menuToggle {
  display: none;
  background: none;
  border: none;
  color: var(--brand);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  margin-left: 1rem;
}

@media (max-width: 720px) {
  .nav {
    justify-content: space-between;
  }
  #menuToggle {
    display: block;
  }
  .nav__links {
    display: none; /* Hide by default on mobile */
    position: fixed;
    top: 0;
    right: -250px; /* Hidden off-screen */
    width: 250px;
    height: 100%;
    background: #fff;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.1);
    flex-direction: column;
    align-items: flex-start;
    padding: 80px 20px 20px;
    gap: 20px;
    transition: right 0.3s ease-in-out;
    z-index: 45; /* Below topbar z-index 50 */
  }
  .nav__links a,
  .nav__links button {
    color: var(--brand);
    width: 100%;
    text-align: left;
    margin-left: 0 !important;
    padding: 10px 0;
    border: none !important;
  }
  .nav__links button {
    border: 1px solid var(--brand) !important;
    padding: 10px 12px;
    border-radius: 6px;
  }
  .nav__links a::after {
    display: none; /* Hide underline effect on sidebar links */
  }
  .nav.nav--open .nav__links {
    right: 0; /* Slide in */
    display: flex; /* Show when open */
  }

  .nav.nav--open #logoutBtn {
    background: var(--brand);
    color: #fff;
  }
}
/* --- Expandable Search Input Fix --- */
/* DROP-IN REPLACEMENT */
#clientSearchField {
  position: relative;
  z-index: 40;
}
#clientSearchResults {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.15);
  max-height: 260px;
  overflow-y: auto;
  display: none;
  z-index: 100;
}
#clientSearchResults.show {
  display: block;
}

/* --- make dynamic products identical to static grid --- */
.product-item {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.05);
  padding: 14px;
  align-items: start;
}

.product-item .field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.product-item .field:nth-child(4) {
  grid-column: 1 / -1; /* make description full width */
}

.product-item input,
.product-item textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: "Dosis", sans-serif;
}

@media (max-width: 1024px) {
  .product-item {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 720px) {
  .product-item {
    grid-template-columns: 1fr;
  }
}
#addClientForm {
  gap: 18px;
}
.grid--3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  align-items: start;
}
/* --- FIX: Prevent overlapping inputs in grid forms --- */
#addClientForm {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  align-items: start;
  width: 100%;
  box-sizing: border-box;
}

/* ensure field boxes don’t overflow grid cells */
#addClientForm .field {
  min-width: 0;
}

#addClientForm input {
  width: 100%;
  box-sizing: border-box;
}
/* --- Adjust layout proportions --- */
.joborder-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 40px;
  max-width: 1500px;
  margin: 72px auto 96px;
  padding: 0 24px;
}

/* make job form wider */
.joborder-layout .container {
  flex: 1.3;
  max-width: 1000px;
}

/* make calculator smaller and more compact */
.calculator {
  position: sticky;
  top: 100px;
  width: 220px; /* smaller width */
  padding: 12px;
  height: fit-content;
  align-self: flex-start;
  text-align: center;
}

/* calculator heading smaller */
.calculator h2 {
  color: var(--brand);
  font-size: 1.1rem;
  margin-bottom: 10px;
}

/* smaller display */
#calc-display {
  width: 100%;
  padding: 8px;
  font-size: 1rem;
  text-align: right;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  margin-bottom: 10px;
}

/* tighter grid */
#calc-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

/* smaller buttons */
#calc-buttons button {
  padding: 0.6rem;
  font-size: 0.9rem;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}

#calc-buttons button:hover {
  background: var(--brand-dark);
}

@media (max-width: 430px) {
  .calculator {
    position: static;
  }
}
