:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #eef4f1;
  --ink: #172023;
  --muted: #5b686b;
  --line: #ccd7d4;
  --accent: #155e63;
  --accent-strong: #0f4549;
  --accent-soft: #d9eeeb;
  --warn: #b8512f;
  --focus: #d88a2d;
  --shadow: 0 12px 28px rgba(23, 32, 35, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, #e6f1ef 0, #f6f8f7 260px);
}

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 2px 0 3px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 10vw, 3.1rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.05rem;
}

.total-tile {
  min-width: 116px;
  padding: 10px 12px;
  border: 1px solid rgba(21, 94, 99, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  text-align: right;
}

.total-tile span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.total-tile strong {
  display: block;
  font-size: 1.15rem;
}

form {
  display: grid;
  gap: 14px;
}

.panel,
.sheet-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 18px rgba(23, 32, 35, 0.06);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.job-field {
  align-self: start;
  grid-template-rows: 34px auto;
}

.job-field span {
  display: flex;
  align-items: center;
  min-height: 34px;
}

.job-field input {
  height: auto;
  min-height: 44px;
}

.labor-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.labor-heading,
.labor-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.labor-rows {
  display: grid;
  gap: 6px;
}

.labor-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px 34px 34px;
  gap: 6px;
  align-items: center;
}

.labor-total {
  min-height: 24px;
  color: var(--accent-strong);
  font-size: 0.76rem;
}

.labor-total strong {
  font-size: 0.95rem;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

#jobName::placeholder,
#workOrder::placeholder {
  font-style: italic;
}

input:focus,
select:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(216, 138, 45, 0.18);
}

input.required-missing {
  border-color: #d88484;
  background: #fff1f1;
  box-shadow: inset 0 0 0 1px rgba(184, 72, 72, 0.12);
}

input.required-missing:focus {
  border-color: #c96565;
  box-shadow: 0 0 0 3px rgba(216, 132, 132, 0.25);
}

input.required-missing::placeholder {
  color: #a65050;
}

.sheet-panel {
  overflow: hidden;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.icon-btn,
.row-remove,
.mini-icon-btn,
.mini-remove-btn {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent-strong);
  background: #fff;
  cursor: pointer;
}

.icon-btn,
.row-remove {
  width: 42px;
  height: 42px;
}

.icon-btn {
  font-size: 1.45rem;
  font-weight: 800;
}

.mini-icon-btn,
.mini-remove-btn {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 1rem;
  font-weight: 850;
}

.mini-remove-btn {
  color: var(--warn);
}

.row-remove {
  width: 36px;
  height: 36px;
  color: var(--warn);
  font-size: 1.2rem;
  font-weight: 800;
}

.icon-btn:focus-visible,
.row-remove:focus-visible,
.mini-icon-btn:focus-visible,
.mini-remove-btn:focus-visible,
.primary-btn:focus-visible,
.secondary-btn:focus-visible,
.text-btn:focus-visible {
  outline: 3px solid rgba(216, 138, 45, 0.38);
  outline-offset: 2px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid #e3e9e7;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

th:nth-child(1),
td:nth-child(1) {
  width: 92px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 142px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 48px;
}

td input,
td select {
  min-height: 40px;
  padding: 9px;
}

.item-cell {
  display: grid;
  gap: 6px;
}

.search-wrap {
  position: relative;
  display: grid;
  gap: 4px;
}

.material-search-input {
  border-color: #adc5c1;
  background: #f9fcfb;
}

.material-search-input.item-required-missing {
  border-color: #d88484;
  background: #fff1f1;
  box-shadow: inset 0 0 0 1px rgba(184, 72, 72, 0.12);
}

.material-search-input.item-required-missing:focus {
  border-color: #c96565;
  box-shadow: 0 0 0 3px rgba(216, 132, 132, 0.25);
}

.search-results {
  display: grid;
  max-height: 224px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(23, 32, 35, 0.12);
  z-index: 4;
}

.search-results[hidden] {
  display: none;
}

.search-group {
  display: grid;
}

.search-group + .search-group {
  border-top: 1px solid #d8e5e2;
}

.search-group-title {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 7px 10px;
  color: var(--accent-strong);
  background: var(--surface-2);
  border-bottom: 1px solid #d8e5e2;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.2;
}

.search-result-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  border-bottom: 1px solid #e3e9e7;
}

.search-result-row:last-child {
  border-bottom: 0;
}

.search-browse-row {
  grid-template-columns: 1fr;
}

.search-result-btn {
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 0;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.search-result-btn:hover,
.search-result-btn:focus-visible,
.search-detail-toggle:hover,
.search-detail-toggle:focus-visible {
  background: var(--accent-soft);
}

.search-result-btn strong {
  font-size: 0.84rem;
  line-height: 1.2;
}

.search-result-btn span {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.2;
}

.search-detail-toggle {
  min-width: 64px;
  border: 0;
  border-left: 1px solid #e3e9e7;
  border-radius: 0;
  padding: 0 9px;
  color: var(--accent-strong);
  background: #fff;
  font-size: 0.72rem;
  font-weight: 850;
  cursor: pointer;
}

.search-result-details {
  grid-column: 1 / -1;
  padding: 8px 10px;
  color: var(--muted);
  background: #f9fcfb;
  border-top: 1px solid #e3e9e7;
  font-size: 0.74rem;
  line-height: 1.3;
}

.search-result-details[hidden] {
  display: none;
}

.search-empty {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.2;
}

.search-empty {
  padding: 10px;
  font-weight: 750;
}

.browse-controls[hidden] {
  display: none;
}

.browse-controls {
  display: grid;
  gap: 6px;
}

.custom-item-input[hidden] {
  display: none;
}

td input[data-field="quantity"],
td input[data-field="price"] {
  text-align: right;
}

.price-cell {
  vertical-align: top;
}

.price-stack {
  display: grid;
  gap: 6px;
}

.markup-field {
  display: grid;
  gap: 3px;
}

.markup-field span {
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 850;
  line-height: 1;
  text-transform: uppercase;
}

.markup-field select {
  min-height: 34px;
  padding: 7px 8px;
  text-align: right;
}

.remove-heading {
  color: transparent;
}

.remove-cell {
  text-align: center;
}

.actions {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px 0 0;
  background: linear-gradient(180deg, rgba(246, 248, 247, 0), var(--bg) 18px);
}

.primary-btn,
.secondary-btn,
.text-btn {
  min-height: 48px;
  border-radius: 6px;
  padding: 0 14px;
  border: 1px solid transparent;
  font-weight: 850;
  cursor: pointer;
}

.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-btn {
  color: #fff;
  background: var(--accent);
}

.primary-btn:active {
  background: var(--accent-strong);
}

.secondary-btn {
  color: var(--accent-strong);
  border-color: rgba(21, 94, 99, 0.34);
  background: var(--accent-soft);
}

.text-btn {
  color: var(--warn);
  background: transparent;
}

.primary-btn:disabled,
.secondary-btn:disabled,
.text-btn:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.button-icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 0.78rem;
  line-height: 1;
}

.status {
  display: block;
  min-height: 28px;
  margin: 10px 2px 0;
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 750;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
  }

  .total-tile {
    min-width: 104px;
  }

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

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

  .text-btn {
    grid-column: 1 / -1;
  }
}

@media (max-width: 420px) {
  .topbar {
    display: grid;
  }

  .total-tile {
    width: 100%;
    text-align: left;
  }
}
