:root {
  --green: #0f5132;
  --green-2: #174f38;
  --mint: #e8f2ed;
  --ink: #17211c;
  --muted: #52615a;
  --helper: #718078;
  --line: #d5dfd9;
  --paper: #ffffff;
  --bg: #edf2ef;
  --danger: #9d3434;
  --shadow: 0 18px 55px rgba(21, 55, 39, .12);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.appbar {
  height: 64px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.appbar-brand { display: flex; align-items: center; gap: 10px; }
.appbar-brand strong { font-size: 15px; }
.appbar-brand #saveStatus { font-size: 12px; color: var(--helper); margin-left: 10px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px var(--mint); }
nav { display: flex; gap: 9px; align-items: center; }
.button, .nav-button { border: 1px solid transparent; border-radius: 9px; padding: 9px 15px; background: transparent; font-weight: 650; }
.nav-button { color: var(--muted); }
.nav-button.active { background: var(--mint); color: var(--green); }
.button.primary { background: var(--green); color: white; }
.button.secondary { border-color: #b7c8bf; background: #fff; color: var(--green); }
.button.ghost { color: var(--muted); }

.editor-toolbar {
  background: #e5ede8;
  border-bottom: 1px solid #cad7d0;
  padding: 14px 20px;
}
.editor-toolbar-inner {
  width: min(1180px, calc(100vw - 40px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(430px, 1fr) auto;
  gap: 22px;
  align-items: end;
}
.editor-search { min-width: 0; }
.editor-label { display: flex; align-items: baseline; gap: 12px; margin-bottom: 7px; }
.editor-label strong { font-size: 14px; color: var(--green); }
.editor-label span { font-size: 12px; color: var(--muted); font-weight: 650; }
.quote-type-control { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 650; }
.quote-type-control select { min-width: 165px; padding: 6px 8px; }
.search-wrap { position: relative; }
.search-wrap > input, .management-search > input {
  width: 100%;
  height: 40px;
  padding: 9px 14px;
  border: 1px solid #b8c9c0;
  border-radius: 9px;
  background: white;
  outline: none;
  font-size: 14px;
}
.search-wrap > input:focus, .management-search > input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(15, 81, 50, .09); }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 35px rgba(17, 55, 37, .16);
  max-height: 350px;
  overflow: auto;
  z-index: 60;
}
.search-result { width: 100%; display: grid; grid-template-columns: 90px 90px 1.2fr 1fr 100px; gap: 10px; text-align: left; border: 0; border-bottom: 1px solid #e5ebe7; background: white; padding: 12px 15px; font-size: 13px; }
.search-result:hover { background: #f1f8f4; }
.search-result:last-child { border-bottom: 0; }
.search-result strong { color: var(--green); font-weight: 700; }
.search-result .price { text-align: right; font-weight: 750; }
.search-empty { padding: 18px; text-align: center; color: var(--muted); }
.editor-controls { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; align-items: center; }
.toolbar-control { min-height: 40px; padding: 8px 10px; border: 1px solid #c8d5ce; border-radius: 9px; background: rgba(255,255,255,.72); }
.setting-group { display: flex; gap: 8px; align-items: center; font-size: 12px; }
.setting-group input, .setting-group select { max-width: 95px; height: 28px; border: 1px solid #bdccc4; border-radius: 6px; padding: 4px 7px; background: white; font-size: 12px; }
.compact-field input { width: 68px; text-align: right; }
.inline-settings { display: flex; gap: 6px; align-items: center; }
.compact-percent { font-size: 10px !important; }
.switch { display: inline-flex !important; align-items: center; gap: 7px; font-size: 12px !important; color: var(--ink) !important; text-transform: none !important; letter-spacing: 0 !important; font-weight: 650 !important; margin: 0 !important; white-space: nowrap; }
.switch input { display: none; }
.switch span { display: inline-block; width: 30px; height: 17px; border-radius: 20px; background: #9daca4; position: relative; margin: 0; flex: none; }
.switch span::after { content: ""; position: absolute; width: 13px; height: 13px; left: 2px; top: 2px; border-radius: 50%; background: white; transition: .18s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(13px); }

#quotePage { padding: 22px 20px 56px; }
.quote-tabs { background: #f5f8f6; border-bottom: 1px solid #d6e0da; padding: 10px max(20px, calc((100vw - 1180px) / 2)); display: flex; gap: 10px; align-items: center; overflow: hidden; }
.quote-tabs-inner { display: flex; gap: 8px; overflow-x: auto; flex: 1; padding-bottom: 2px; }
.quote-tab { flex: 0 0 auto; border: 1px solid #cbd9d1; background: #fff; color: var(--ink); border-radius: 9px; padding: 8px 13px; cursor: pointer; font-weight: 650; white-space: nowrap; }
.quote-tab.active { background: var(--green); color: white; border-color: var(--green); }
.quote-tab small { opacity: .75; margin-left: 6px; font-weight: 500; }
.quote-center-card { cursor: pointer; }
.quote-center-card .product-actions { margin-top: 8px; }
.management-shell h3 { margin-top: 24px; color: var(--green); }
.quote-sheet {
  width: min(1180px, calc(100vw - 40px));
  min-height: 720px;
  margin: auto;
  background: var(--paper);
  box-shadow: var(--shadow);
  border-radius: 4px;
  padding: 34px 42px 30px;
}
.quote-heading {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 34px;
  align-items: center;
  min-height: 178px;
  padding: 24px 28px;
  border: 1px solid #d5e4dc;
  border-bottom: 3px solid var(--green);
  border-radius: 13px 13px 5px 5px;
  background: linear-gradient(125deg, #f4faf6 0%, #ffffff 53%, #edf7f1 100%);
}
.quote-heading::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: 260px;
  height: 260px;
  right: -118px;
  top: -145px;
  border: 42px solid rgba(15, 81, 50, .045);
  border-radius: 50%;
}
.company-lockup { display: flex; align-items: center; gap: 28px; min-width: 0; }
.company-lockup img { width: 168px; height: 66px; object-fit: contain; object-position: left center; flex: none; }
.company-copy { min-width: 0; padding-left: 24px; border-left: 1px solid #cadbd2; }
.company-lockup h1 { font-size: 30px; line-height: 1.12; letter-spacing: -.02em; font-weight: 750; margin: 0 0 5px; color: #10261c; }
.company-tagline { margin: 0 0 7px; color: var(--muted); font-size: 11px; line-height: 1.35; font-weight: 750; letter-spacing: .085em; text-transform: uppercase; }
.company-lockup a { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 650; color: var(--green); text-decoration: none; }
.company-lockup a::before { content: "↗"; font-size: 11px; }
.brand-highlights { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.brand-highlights span { padding: 4px 8px; border: 1px solid #cfdfd6; border-radius: 999px; background: rgba(255,255,255,.78); color: #40584c; font-size: 9.5px; line-height: 1; font-weight: 700; letter-spacing: .025em; white-space: nowrap; }
.document-title { min-width: 0; padding-left: 32px; border-left: 1px solid #c6d9cf; text-align: right; }
.eyebrow { display: flex; justify-content: flex-end; align-items: center; gap: 7px; letter-spacing: .15em; font-size: 9.5px; color: var(--green); font-weight: 800; margin: 0 0 6px; }
.eyebrow span { width: 22px; height: 2px; border-radius: 2px; background: var(--green); }
.document-title h2 { margin: 0 0 12px; font-family: inherit; font-size: 29px; line-height: 1.15; letter-spacing: -.02em; font-weight: 750; }
.document-title label { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin: 5px 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.document-title input { border: 0; border-bottom: 1px solid var(--line); padding: 4px; width: 165px; text-align: right; background: transparent; font-size: 13px; font-weight: 600; }

.meta-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 18px 0; }
.meta-card { min-height: 72px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfb; }
.meta-card span { display: block; color: var(--muted); font-size: 11.5px; font-weight: 650; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .055em; }
.meta-card small { font-size: 10px; font-weight: 550; color: var(--helper); }
.meta-card input, .meta-card select { width: 100%; border: 0; background: transparent; font-size: 16px; font-weight: 700; outline: none; }
.fx-control { display: flex; align-items: center; }
.fx-control input { min-width: 0; }
.fx-control button { border: 0; background: var(--mint); color: var(--green); border-radius: 6px; width: 28px; height: 26px; font-weight: 800; }
.fx-source { display: block; color: var(--helper); font-size: 10px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.table-wrap { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.quote-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.quote-table th { background: var(--green); color: #fff; text-align: left; padding: 12px 9px; font-size: 13px; line-height: 1.2; font-weight: 700; letter-spacing: .02em; }
.quote-table th:nth-child(1) { width: 38px; text-align: center; }
.quote-table th:nth-child(2) { width: 108px; }
.quote-table th:nth-child(3) { width: 18%; }
.quote-table th:nth-child(4) { width: 24%; }
.quote-table th:nth-child(5) { width: 64px; text-align: center; }
.quote-table th:nth-child(6), .quote-table th:nth-child(7), .quote-table th:nth-child(8) { width: 114px; text-align: right; }
.quote-table th.discount-column, .quote-table td.discount-column { color: var(--green); font-weight: 700; text-align: right; }
.quote-table th.discount-column { color: #fff; }
.quote-table th.action-col { width: 104px; text-align: center; }
.quote-table td { padding: 11px 8px; border-bottom: 1px solid #e3e9e5; vertical-align: top; font-size: 13px; color: var(--ink); }
.quote-table tr:last-child td { border-bottom: 0; }
.quote-table td:first-child { text-align: center; color: var(--muted); font-size: 13px; font-weight: 650; }
.cell-input { width: 100%; border: 1px solid transparent; border-radius: 5px; background: transparent; padding: 4px; color: var(--ink); }
.cell-input:hover, .cell-input:focus { border-color: #b9ccc1; background: #fff; outline: none; }
.quote-table td:nth-child(2) .cell-input { font-size: 13.5px; font-weight: 600; }
.quote-table td:nth-child(3) .cell-input { font-size: 14px; font-weight: 650; }
.quote-table td:nth-child(4) .cell-input { font-size: 13.5px; font-weight: 500; }
.quote-table td:nth-child(5) .cell-input { font-size: 14px; font-weight: 600; }
.quote-table td:nth-child(6) .cell-input { font-size: 14px; font-weight: 700; }
.qty-input { text-align: center; }
.money-input { text-align: right; font-weight: 700; }
.subtotal { text-align: right; font-size: 14px !important; font-weight: 700; padding-top: 15px !important; }
.internal-price { display: block; color: var(--helper); font-size: 11px; font-weight: 500; line-height: 1.45; padding: 3px 4px 0; }
.manual-badge { color: #835b18; font-weight: 700; }
.row-actions { display: flex; justify-content: center; gap: 3px; }
.row-actions button { border: 0; background: #e8f0eb; border-radius: 5px; width: 24px; height: 24px; color: var(--green); font-weight: 700; }
.row-actions button.delete { color: var(--danger); }
.empty-state { text-align: center; padding: 28px; color: var(--muted); font-size: 13px; }

.quote-footer { display: grid; grid-template-columns: 1fr 380px; gap: 50px; margin-top: 20px; }
.notes-block h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--green); margin: 0 0 8px; font-weight: 700; }
.notes-block textarea { width: 100%; resize: vertical; border: 1px solid transparent; line-height: 1.58; padding: 7px; border-radius: 7px; color: var(--muted); font-size: 14px; font-weight: 500; }
.notes-block textarea:hover, .notes-block textarea:focus { border-color: var(--line); outline: none; }
.totals-block { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; align-self: start; }
.total-row, .grand-total { display: flex; justify-content: space-between; align-items: center; padding: 11px 15px; border-bottom: 1px solid var(--line); font-size: 14px; }
.total-row strong { font-size: 14px; font-weight: 700; }
.discount-row strong { color: #8e3434; }
.discounted-product-row strong { color: var(--green); font-weight: 750; }
.customer-only { display: none; }
.editable-total { display: flex; align-items: center; justify-content: flex-end; gap: 2px; min-width: 124px; font-size: 14px; font-weight: 700; }
.editable-total input { width: 88px; padding: 4px 6px; border: 1px solid #b9ccc1; border-radius: 6px; background: #fff; text-align: right; font-size: 14px; font-weight: 700; outline: none; }
.editable-total input:hover, .editable-total input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(15,81,50,.08); }
.discount-input { color: #8e3434; }
.discount-input input { color: #8e3434; }
.grand-total { background: var(--green); color: #fff; border: 0; font-weight: 700; }
.grand-total strong { font-size: 18px; font-weight: 700; }
.grand-total .editable-total { font-size: 17px; }
.grand-total .editable-total input { border-color: rgba(255,255,255,.58); background: rgba(255,255,255,.12); color: #fff; font-size: 17px; }
.grand-total .editable-total input:focus { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.16); }

.back-to-edit { position: fixed; right: 18px; bottom: 18px; border: 0; border-radius: 10px; padding: 11px 14px; background: #102c20; color: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.22); z-index: 100; }
.back-to-edit kbd { margin-left: 8px; padding: 2px 5px; border: 1px solid #72847b; border-radius: 4px; }

.management-page { padding: 28px; }
.management-shell { max-width: 1180px; margin: auto; background: white; border-radius: 14px; box-shadow: var(--shadow); padding: 28px; }
.management-title { display: flex; justify-content: space-between; align-items: end; }
.management-title h2 { font-size: 28px; margin: 0; }
.management-title p:not(.eyebrow) { color: var(--muted); margin: 7px 0 0; }
.management-title > div:last-child { display: flex; gap: 8px; }
.management-search { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 18px; margin: 22px 0; }
.management-search label { font-size: 12px; color: var(--muted); }
.bulk-product-toolbar { display:flex; align-items:center; gap:16px; margin: -8px 0 12px; color:var(--muted); font-size:13px; }
.bulk-product-toolbar label { display:flex; align-items:center; gap:6px; }
.bulk-product-toolbar .button.danger { border-color:#d9a5a5; color:#9a3030; background:#fff; }
.bulk-product-toolbar .button:disabled { opacity:.45; cursor:not-allowed; }
.product-list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.product-card { display: grid; grid-template-columns: 28px 115px 1.1fr 1.3fr 105px 1fr 145px; gap: 12px; align-items: center; padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 12px; }
.product-card:last-child { border: 0; }
.product-card.inactive { opacity: .58; background: #f5f5f5; }
.product-card strong { color: var(--green); font-size: 13px; }
.product-card .aliases { color: var(--muted); }
.product-actions { display: flex; justify-content: flex-end; gap: 6px; }
.product-actions button { border: 1px solid var(--line); border-radius: 6px; background: white; padding: 6px 8px; }
.product-actions .danger { color: var(--danger); }

dialog { border: 0; border-radius: 14px; box-shadow: 0 25px 80px rgba(0,0,0,.3); padding: 0; width: min(620px, calc(100vw - 40px)); }
dialog::backdrop { background: rgba(15,32,24,.48); }
dialog form { padding: 24px; }
.about-version { display: flex; align-items: baseline; justify-content: space-between; margin-top: 24px; padding: 18px; border: 1px solid #d7e0db; border-radius: 10px; background: #f5f8f6; }
.about-version span { color: #52615a; font-weight: 600; }
.about-version strong { color: #0b5a39; font-size: 22px; }
.about-build { color: #718078; margin: 12px 4px 0; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; }
.dialog-head h3 { font-size: 22px; margin: 0; }
.icon-button { font-size: 25px; border: 0; background: transparent; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 20px; }
.form-grid label { font-size: 11px; color: var(--muted); font-weight: 700; }
.form-grid .wide { grid-column: 1/-1; }
.form-grid input, .alias-add input { width: 100%; margin-top: 6px; border: 1px solid #cbd8d1; border-radius: 7px; padding: 9px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.alias-editor { margin-top: 18px; }
.alias-editor > strong { font-size: 12px; }
.alias-add { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 9px; }
.alias-chip { display: inline-flex; gap: 5px; align-items: center; padding: 4px 7px; margin: 7px 5px 0 0; border-radius: 20px; background: var(--mint); font-size: 11px; }
.alias-chip button { border: 0; background: transparent; color: var(--danger); }
.wide-dialog { width: min(1000px, calc(100vw - 40px)); }
.import-summary { margin: 15px 0; color: var(--muted); font-size: 12px; }
.import-preview { max-height: 450px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 12px; }
.import-row { display: grid; grid-template-columns: 50px 90px 100px 1.15fr 1fr 90px 145px; gap: 8px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 11px; }
.import-row:first-child { position: sticky; top: 0; background: var(--green); color: white; font-weight: 700; }
.import-row select { padding: 5px; }
.product-type-badge { display: inline-block; padding: 3px 6px; border-radius: 999px; font-size: 9px; font-style: normal; text-transform: uppercase; letter-spacing: .05em; background: #e6f3ed; color: var(--green); }
.product-type-badge { background: #eef5f1; color: #40584c; }
.toast { position: fixed; left: 50%; bottom: 25px; transform: translateX(-50%); background: #173b2b; color: white; border-radius: 8px; padding: 11px 18px; z-index: 200; box-shadow: 0 8px 25px rgba(0,0,0,.2); }

body.customer-mode { background: #fff; }
body.customer-mode .edit-only { display: none !important; }
body.customer-mode .customer-only { display: inline !important; }
body.customer-mode #quotePage { padding: 14px 0; }
body.customer-mode .quote-sheet { box-shadow: none; width: min(1180px, 100vw); padding-top: 28px; }
body.customer-mode input, body.customer-mode select, body.customer-mode textarea { appearance: none; border: 0 !important; background: transparent !important; pointer-events: none; resize: none; }
body.customer-mode select { background-image: none; }
body.customer-mode .cell-input { padding-left: 0; padding-right: 0; }
body.customer-mode .quote-table th:last-child, body.customer-mode .quote-table td:last-child { display: none; }
body.customer-mode .quote-table th:nth-child(3) { width: 20%; }
body.customer-mode .quote-table th:nth-child(4) { width: 26%; }

@media print {
  .edit-only, .back-to-edit { display: none !important; }
  .customer-only { display: inline !important; }
  body { background: white; }
  .quote-sheet { box-shadow: none; width: 100%; padding: 20px; }
}

@media (max-width: 1100px) {
  .editor-toolbar-inner { grid-template-columns: 1fr; gap: 10px; }
  .editor-controls { justify-content: flex-start; }
}

@media (max-width: 900px) {
  .appbar { padding: 0 14px; }
  .appbar-brand #saveStatus, .nav-button { display: none; }
  .editor-toolbar-inner, .quote-sheet { width: min(100%, calc(100vw - 24px)); }
  .quote-sheet { padding: 28px 20px; }
  .quote-heading { grid-template-columns: 1fr; gap: 22px; padding: 22px; }
  .document-title { padding: 20px 0 0; border-left: 0; border-top: 1px solid #c6d9cf; }
  .company-lockup { gap: 18px; }
  .company-lockup img { width: 138px; }
  .company-copy { padding-left: 18px; }
  .company-lockup h1 { font-size: 24px; }
  .meta-grid { grid-template-columns: 1fr 1fr; }
  .quote-footer { grid-template-columns: 1fr; }
  .quote-table { min-width: 850px; }
  .table-wrap { overflow: auto; }
  .product-card { grid-template-columns: 100px 1fr 1fr; }
  .product-card > *:nth-child(4), .product-card > *:nth-child(5) { display: none; }
}
