:root {
  --bg: #f3f6f0;
  --surface: #ffffff;
  --surface-2: #eef4eb;
  --ink: #173024;
  --muted: #65746b;
  --line: #d8e1d4;
  --green: #0f5d35;
  --green-2: #dff2e2;
  --leaf: #6fb43f;
  --teal: #277b75;
  --amber: #b87514;
  --amber-2: #fff2d8;
  --red: #b3342f;
  --red-2: #ffe4e2;
  --blue: #2d64a7;
  --blue-2: #e1edff;
  --shadow: 0 18px 45px rgba(33, 54, 40, 0.1);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

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

button {
  cursor: pointer;
}

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

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(140deg, rgba(16, 34, 24, 0.92), rgba(15, 93, 53, 0.84)),
    var(--bg);
}

.login-gate.show {
  display: grid;
}

.login-card {
  width: min(420px, 100%);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: var(--surface);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.24);
  padding: 22px;
  display: grid;
  gap: 14px;
}

.login-card h1 {
  margin: 2px 0 0;
  font-size: 28px;
  line-height: 1.1;
}

.login-logo {
  width: 136px;
  height: 74px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.login-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 6px;
}

.demo-accounts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.demo-accounts span {
  min-height: 30px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  padding: 7px 8px;
  font-size: 12px;
}

.login-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 16px;
  background:
    linear-gradient(180deg, rgba(111, 180, 63, 0.08), rgba(111, 180, 63, 0) 35%),
    #102218;
  color: #f7fbf5;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand small {
  color: #b8c8bd;
  margin-top: 2px;
  font-size: 12px;
}

.brand-mark {
  width: 70px;
  height: 50px;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  color: #d8e6dc;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.nav-item svg,
.icon-button svg,
.primary-action svg,
.ghost-button svg,
.role-pill svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  color: #b8c8bd;
  font-size: 12px;
}

.role-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #f7fbf5;
}

.workspace {
  min-width: 0;
  padding: 18px 22px 32px;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 3px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-brand {
  width: 118px;
  height: 42px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar-brand img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.user-chip {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 6px 10px;
  display: grid;
  align-content: center;
  gap: 1px;
}

.user-chip strong,
.user-chip span {
  display: block;
  white-space: nowrap;
}

.user-chip strong {
  font-size: 13px;
}

.user-chip span {
  color: var(--muted);
  font-size: 11px;
}

.icon-button,
.ghost-button,
.primary-action {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  width: 40px;
  padding: 0;
}

.primary-action {
  background: linear-gradient(135deg, var(--green), #167344);
  color: white;
  border-color: var(--green);
  font-weight: 650;
}

.ghost-button:hover,
.icon-button:hover {
  border-color: #a9b8ad;
}

.menu-toggle {
  display: none;
}

.screen {
  display: none;
}

.screen.active {
  display: grid;
  gap: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric:first-child {
  border-top: 3px solid var(--leaf);
}

.metric:nth-child(2) {
  border-top: 3px solid var(--green);
}

.metric {
  padding: 16px;
  display: grid;
  gap: 8px;
}

.metric span,
.metric small,
.panel p,
label,
.quote-info span,
.quote-total span,
.result-grid span,
.cost-breakdown span {
  color: var(--muted);
}

.metric strong {
  font-size: 26px;
  line-height: 1.05;
}

.panel {
  padding: 18px;
}

.panel h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}

.panel p {
  margin: 5px 0 0;
  font-size: 13px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.content-grid {
  display: grid;
  gap: 16px;
}

.two-col {
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
}

.pricing-grid {
  grid-template-columns: minmax(280px, 0.9fr) minmax(280px, 0.7fr) minmax(330px, 1fr);
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.pipeline div {
  min-height: 86px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 12px;
  display: grid;
  align-content: space-between;
}

.pipeline span {
  color: var(--muted);
  font-size: 13px;
}

.pipeline strong {
  font-size: 26px;
}

.visual-panel {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  overflow: hidden;
}

.greenhouse-visual {
  position: relative;
  height: 150px;
  border-radius: var(--radius);
  border: 1px solid #bbd0c0;
  background: linear-gradient(180deg, #e9f8ed 0%, #f9fbf7 58%, #d7ead9 100%);
  overflow: hidden;
}

.greenhouse-visual .roof {
  position: absolute;
  inset: 20px 18px auto;
  height: 60px;
  border: 3px solid rgba(47, 125, 70, 0.5);
  border-bottom: 0;
  border-radius: 70px 70px 0 0;
}

.rows {
  position: absolute;
  inset: auto 10px 18px;
  display: grid;
  gap: 8px;
}

.rows span {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #3e8a4f, #b7d767);
}

.spray {
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid rgba(39, 123, 117, 0.22);
  background: rgba(39, 123, 117, 0.08);
}

.spray-one {
  left: 36px;
  top: 55px;
}

.spray-two {
  right: 24px;
  top: 70px;
}

.inline-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.inline-stats span,
.status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
}

.inline-stats span,
.status.green {
  color: var(--green);
  background: var(--green-2);
}

.status.blue {
  color: var(--blue);
  background: var(--blue-2);
}

.status.amber {
  color: var(--amber);
  background: var(--amber-2);
}

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

.alert-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border-radius: var(--radius);
  padding: 12px;
  border: 1px solid var(--line);
}

.alert-row svg {
  width: 18px;
  height: 18px;
}

.alert-row.danger {
  background: var(--red-2);
  color: var(--red);
  border-color: #ffc6c2;
}

.alert-row.warn {
  background: var(--amber-2);
  color: var(--amber);
  border-color: #f6d99d;
}

.alert-row.info {
  background: var(--blue-2);
  color: var(--blue);
  border-color: #c1d7fb;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar.dense {
  justify-content: space-between;
}

.search-box {
  flex: 1 1 320px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
}

.search-box svg {
  width: 17px;
  height: 17px;
  color: var(--muted);
}

.search-box input {
  border: 0;
  outline: 0;
  width: 100%;
  background: transparent;
}

.table-panel {
  overflow: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

tbody tr[data-project-id] {
  cursor: pointer;
}

tbody tr[data-project-id]:hover,
.selected-row {
  background: #f0f7ec;
}

.form-grid {
  display: grid;
  gap: 16px;
}

.form-section {
  display: grid;
  gap: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  padding: 8px 10px;
  outline: 0;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 125, 70, 0.12);
}

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

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
}

.segmented button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 6px 12px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--green);
  color: white;
}

.editable-table input {
  width: 94px;
  min-height: 34px;
}

.editable-table .reason-input {
  width: 180px;
}

.catalog-form {
  grid-template-columns: repeat(5, minmax(150px, 1fr));
}

.catalog-submit {
  display: flex;
  align-items: end;
}

.catalog-table {
  min-width: 1180px;
}

.users-table {
  min-width: 980px;
}

.catalog-table input,
.catalog-table select,
.users-table input,
.users-table select {
  width: 100%;
  min-width: 92px;
}

.catalog-table td:nth-child(2) input {
  min-width: 220px;
}

.user-form {
  grid-template-columns: repeat(5, minmax(150px, 1fr));
}

.settings-grid {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.wide-field {
  grid-column: span 2;
}

.wide-field textarea {
  width: 100%;
}

.compact-save {
  min-height: 34px;
  padding: 6px 10px;
}

.diff-bad {
  color: var(--red);
  font-weight: 700;
}

.cost-breakdown,
.control-stack,
.result-grid {
  display: grid;
  gap: 12px;
}

.cost-breakdown div,
.result-grid div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdf9;
}

.cost-breakdown input,
.control-stack input,
.control-stack select {
  max-width: 180px;
}

.total-line,
.result-grid div:last-child {
  background: var(--green-2) !important;
  border-color: #bbd9c2 !important;
}

.result-panel {
  display: grid;
  gap: 14px;
}

.profit-warning {
  display: none;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--red-2);
  color: var(--red);
  border: 1px solid #ffc6c2;
  font-weight: 650;
}

.profit-warning.show {
  display: block;
}

.lock-notice {
  display: none;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--blue-2);
  color: var(--blue);
  border: 1px solid #c1d7fb;
  font-weight: 650;
}

.lock-notice.show {
  display: block;
}

.quote-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.quote-document {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
  position: relative;
  overflow: hidden;
}

.quote-document::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 6px;
  background: linear-gradient(90deg, var(--green), var(--leaf), var(--teal));
}

.quote-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0 18px;
  margin-bottom: 16px;
}

.quote-head strong,
.quote-head span {
  display: block;
}

.quote-head strong {
  font-size: 18px;
}

.quote-head span {
  color: var(--muted);
  margin-top: 4px;
}

.quote-title {
  margin-bottom: 16px;
  padding: 16px 18px;
  border-left: 5px solid var(--green);
  background: linear-gradient(90deg, rgba(15, 93, 53, 0.08), rgba(111, 180, 63, 0.08));
}

.quote-title span {
  display: block;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.quote-title h2 {
  margin: 4px 0 0;
  font-size: 28px;
  line-height: 1.15;
  color: var(--ink);
}

.quote-company {
  display: grid;
  gap: 8px;
}

.quote-logo {
  width: 250px;
  height: 100px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.quote-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 6px;
}

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

.quote-info div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  display: grid;
  gap: 4px;
  background: #fbfdf9;
}

.quote-total {
  margin-left: auto;
  margin-top: 14px;
  max-width: 360px;
  display: grid;
  gap: 8px;
}

.quote-total div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: #f8fbf6;
}

.quote-total div:last-child {
  padding-top: 10px;
  border-top: 2px solid var(--green);
  font-size: 18px;
  color: var(--green);
}

.quote-note {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.quote-terms {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: grid;
  gap: 8px;
}

.quote-terms h3 {
  margin: 0 0 2px;
  font-size: 15px;
}

.quote-terms p {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
}

.signature-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.signature-grid div {
  min-height: 98px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: grid;
  align-content: space-between;
}

.signature-grid span {
  color: var(--muted);
  font-size: 12px;
}

.signature-grid strong {
  font-size: 14px;
}

.approval-panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 12px;
}

.approval-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
}

.approval-step.done {
  color: var(--green);
  background: var(--green-2);
}

.approval-step svg {
  width: 18px;
  height: 18px;
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.wide-action {
  grid-column: 1 / -1;
}

.pdf-export-stage {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 794px;
  background: white;
  color: var(--ink);
  z-index: -1;
}

.pdf-document {
  width: 794px;
  min-height: 1123px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 34px 44px 30px;
  overflow: visible;
  font-size: 13px;
}

.pdf-document::before {
  height: 8px;
}

.pdf-document .quote-head {
  align-items: flex-start;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 20px;
}

.pdf-document .quote-head > div:last-child {
  min-width: 0;
  text-align: right;
  word-break: break-word;
}

.pdf-document .quote-title {
  page-break-inside: avoid;
}

.pdf-document .quote-title h2 {
  font-size: 29px;
}

.pdf-document .quote-info {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.pdf-document table {
  min-width: 0;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.pdf-document th {
  background: #0f5d35;
  color: white;
  border-color: #0f5d35;
  font-size: 12px;
}

.pdf-document td {
  font-size: 12px;
  white-space: normal;
}

.pdf-document tr,
.pdf-document .quote-total,
.pdf-document .quote-terms,
.pdf-document .signature-grid {
  page-break-inside: avoid;
}

.pdf-document .quote-logo {
  width: 214px;
  height: 112px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  overflow: hidden;
  background: #fff url("./assets/kcr-agritech-logo.jpg") center 54% / 100% auto no-repeat;
}

.pdf-document .quote-logo img {
  display: none;
}

.pdf-document .quote-total {
  max-width: 340px;
}

.pdf-document .quote-total div:last-child {
  background: #eaf6e8;
}

.pdf-document .signature-grid div {
  min-height: 92px;
}

@media (max-width: 1180px) {
  .summary-grid,
  .field-grid,
  .settings-grid,
  .user-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-col,
  .pricing-grid,
  .quote-layout {
    grid-template-columns: 1fr;
  }

  .approval-panel {
    position: static;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: 280px;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .workspace {
    padding: 14px;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .topbar-brand {
    display: none;
  }

  .topbar-actions .primary-action {
    display: none;
  }

  .summary-grid,
  .field-grid,
  .settings-grid,
  .user-form,
  .pipeline,
  .quote-info,
  .visual-panel,
  .signature-grid {
    grid-template-columns: 1fr;
  }

  .wide-field {
    grid-column: auto;
  }

  .visual-panel {
    align-items: stretch;
  }

  .greenhouse-visual {
    height: 120px;
  }

  .alert-row {
    grid-template-columns: 22px minmax(0, 1fr);
  }

  .alert-row strong {
    grid-column: 2;
  }

  .quote-head {
    display: grid;
  }

  .quote-logo {
    width: 190px;
    height: 74px;
  }
}

@media print {
  @page {
    size: A4;
    margin: 14mm;
  }

  body {
    background: white;
  }

  .app-shell {
    display: block;
    min-height: auto;
  }

  .sidebar,
  .topbar,
  .approval-panel,
  .screen:not(#quote-preview),
  .quote-note {
    display: none !important;
  }

  .workspace {
    padding: 0;
  }

  #quote-preview {
    display: block !important;
  }

  .quote-layout {
    display: block;
  }

  .quote-document {
    box-shadow: none;
    border: 0;
    padding: 0;
    width: 100%;
  }

  .quote-document::before {
    display: block;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .quote-logo {
    border-color: #d8e1d4;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .quote-document table {
    min-width: 0;
  }

  th,
  td {
    white-space: normal;
  }
}
