:root {
  --ink: #1c2523;
  --muted: #68746f;
  --line: #dedbd4;
  --panel: #ffffff;
  --soft: #f2f1ed;
  --blue: #1f4d45;
  --teal: #627481;
  --orange: #b9823b;
  --green: #2f7d57;
  --red: #b94a48;
  --shadow: 0 18px 42px rgba(45, 50, 45, 0.1);
  --focus: #c79a5b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #f6f5f2;
  font-family: "Microsoft JhengHei", "PingFang TC", Arial, sans-serif;
  letter-spacing: 0;
}

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

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(31, 77, 69, 0.12), rgba(185, 130, 59, 0.12)),
    #f6f5f2;
}

.login-screen.hidden,
.app-shell.locked {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 30px;
  background: #fff;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}

.login-card img {
  width: 128px;
  height: 88px;
  object-fit: contain;
}

.login-card h1 {
  font-size: 26px;
}

.login-card p {
  margin: 0;
  color: var(--muted);
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 278px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: #fbfaf7;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 78px;
}

.brand img {
  width: 78px;
  height: 78px;
  object-fit: contain;
}

.brand strong {
  display: block;
  font-size: 18px;
}

.brand span,
.company-card small,
.eyebrow,
.hint {
  color: var(--muted);
  font-size: 12px;
}

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

.nav button {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 7px;
  padding: 9px 11px;
  background: transparent;
  color: #384842;
  text-align: left;
  cursor: pointer;
}

.nav button.active,
.nav button:hover {
  background: #e9eee8;
  color: #1f4d45;
}

.company-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f2f1ed;
  display: grid;
  gap: 6px;
}

.company-card span {
  font-weight: 700;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 28px;
}

h2 {
  margin: 0;
  font-size: 18px;
}

h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.user-badge {
  max-width: 180px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: #fff;
  color: #384842;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search {
  width: min(360px, 38vw);
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdfa;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
}

.ghost-btn,
.primary-btn {
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid var(--line);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

.ghost-btn {
  background: #fffdfa;
  color: #384842;
}

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

.ghost-btn:hover {
  border-color: #b8b0a5;
  background: #f5f2eb;
}

.primary-btn:hover {
  background: #173d37;
}

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

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

.two-col {
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
}

.product-layout {
  grid-template-columns: 1fr;
}

.quote-layout {
  grid-template-columns: 1fr;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

.kpi {
  display: grid;
  gap: 8px;
  min-height: 112px;
}

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

.kpi strong {
  font-size: 28px;
}

.kpi small {
  color: var(--muted);
}

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

.inventory-toolbar {
  align-items: flex-end;
}

.compact-filter {
  min-width: 180px;
  max-width: 220px;
}

.sales-toolbar {
  align-items: flex-end;
}

.sales-filters {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 150px;
  gap: 10px;
  min-width: min(520px, 100%);
}

.quote-list-toolbar {
  align-items: flex-end;
}

.quote-list-search {
  min-width: min(420px, 100%);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-note {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fffdfa;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(199, 154, 91, 0.18);
  outline: 0;
}

.inline-status,
.inline-edit {
  min-width: 118px;
  min-height: 32px;
  padding: 5px 8px;
  border-color: #d4d0c8;
  background: #fffdfa;
  font-size: 13px;
}

.inline-edit {
  width: 100%;
  min-width: 130px;
}

.frozen-cell {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  border-radius: 7px;
  border: 1px solid #d7dde3;
  background: #eef1f4;
  color: var(--muted);
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
}

.stock-edit {
  display: grid;
  grid-template-columns: minmax(82px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

.bulk-textarea {
  min-height: 170px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.55;
}

.bulk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.product-check {
  width: 18px;
  min-width: 18px;
  min-height: 18px;
  accent-color: var(--blue);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.pagination .ghost-btn {
  min-width: 38px;
  padding: 7px 10px;
}

.pagination .active-page {
  background: #e8f3fb;
  border-color: #9ac9e8;
  color: #0d5e94;
  font-weight: 800;
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  background: #fffdfa;
}

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

th {
  position: sticky;
  top: 0;
  background: #eeece6;
  color: #384842;
  font-size: 12px;
}

td {
  font-size: 13px;
}

.money {
  text-align: right;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  background: #eeece6;
  color: #4c5a55;
  font-size: 12px;
  font-weight: 700;
}

.badge.green {
  background: #e4f6ed;
  color: var(--green);
}

.badge.orange {
  background: #fff0e7;
  color: var(--orange);
}

.badge.red {
  background: #fbe8e8;
  color: var(--red);
}

.inline-status.status-yellow,
.badge.status-yellow {
  background: #f7ebcf;
  border-color: #d8ad67;
  color: #7b551d;
}

.inline-status.status-green,
.badge.status-green {
  background: #e4f6ed;
  border-color: #a8dec3;
  color: var(--green);
}

.inline-status.status-red,
.badge.status-red {
  background: #fbe8e8;
  border-color: #efb8b8;
  color: var(--red);
}

.inline-status.status-blue,
.badge.status-blue {
  background: #e5ece9;
  border-color: #b7c7c0;
  color: #1f4d45;
}

.inline-status.status-done,
.badge.status-done {
  background: #edf1f5;
  border-color: #cfd8e1;
  color: #405262;
}

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

.status-row {
  display: grid;
  grid-template-columns: 120px 1fr 88px;
  gap: 10px;
  align-items: center;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #ebe8df;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--orange));
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.quote-head {
  margin-bottom: 14px;
}

.section-adders {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.section-adders button {
  min-height: 36px;
}

.quote-lines-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.quote-lines {
  min-width: 1260px;
  table-layout: fixed;
}

.quote-lines th,
.quote-lines td {
  padding: 8px;
  white-space: normal;
  overflow: hidden;
}

.quote-lines input,
.quote-lines select {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 6px 8px;
}

.quote-col-index {
  width: 58px;
}

.quote-col-model {
  width: 260px;
}

.quote-col-description {
  width: 300px;
}

.quote-col-qty {
  width: 84px;
}

.quote-col-unit {
  width: 88px;
}

.quote-col-price {
  width: 150px;
}

.quote-col-total {
  width: 130px;
}

.quote-col-note {
  width: 170px;
}

.quote-col-action {
  width: 80px;
}

.quote-lines .line-model {
  min-width: 0;
}

.quote-lines .line-description {
  min-width: 0;
}

.quote-lines .line-unit {
  width: 72px;
  text-align: center;
}

.quote-lines .line-qty,
.quote-lines .line-price {
  width: 118px;
}

.quote-lines .line-price {
  text-align: right;
}

.quote-lines .line-note {
  min-width: 0;
}

.apply-product {
  width: 100%;
  margin-top: 6px;
  min-height: 30px;
  padding: 0 8px;
}

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

.quote-entry-section {
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.quote-entry-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #efe2c6;
  border-bottom: 1px solid var(--line);
}

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

.quote-entry-section .quote-lines-wrap {
  border: 0;
  border-radius: 0;
}

.quote-lines tfoot td {
  background: #ead3b5;
  font-weight: 800;
}

.hidden-cost {
  display: none;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.sale-lines-wrap {
  margin-top: 14px;
}

.sale-lines-wrap h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.sale-lines {
  min-width: 860px;
}

.sale-lines input {
  width: 100%;
  min-width: 100px;
}

.repair-billing-panel .compact-form {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.repair-billing-lines {
  min-width: 760px;
}

.repair-billing-lines input {
  width: 100%;
  min-width: 86px;
}

.password-save-field {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.password-save-field input {
  min-width: 140px;
}

.password-save-field .ghost-btn {
  min-height: 34px;
  padding: 6px 10px;
  white-space: nowrap;
}

.repair-line-total {
  white-space: nowrap;
  font-weight: 800;
}

.billing-total-row {
  margin-top: 12px;
  text-align: right;
  font-size: 18px;
}

#repairBillingPrintRoot {
  display: none;
}

.repair-billing-sheet {
  width: 210mm;
  min-height: 148mm;
  background: #fff;
  color: #1f2a27;
  padding: 9mm 10mm;
  font-family: "Noto Sans TC", "PingFang TC", Arial, sans-serif;
}

.repair-billing-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12mm;
  border-bottom: 2px solid #285f53;
  padding-bottom: 5mm;
}

.repair-billing-head div {
  display: grid;
  grid-template-columns: 28mm 1fr;
  gap: 1mm 5mm;
  align-items: center;
}

.repair-billing-head img {
  width: 28mm;
  height: 16mm;
  object-fit: contain;
  grid-row: span 2;
}

.repair-billing-head strong {
  font-size: 18pt;
  line-height: 1.2;
}

.repair-billing-head span {
  font-size: 10pt;
  color: #4f5f5a;
}

.repair-billing-head h2 {
  margin: 0;
  font-size: 24pt;
  letter-spacing: 0;
  white-space: nowrap;
}

.repair-billing-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4mm;
  margin: 5mm 0;
  font-size: 11pt;
}

.repair-billing-print-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5pt;
}

.repair-billing-print-table th,
.repair-billing-print-table td {
  border: 1px solid #222;
  padding: 2.5mm 3mm;
  line-height: 1.2;
}

.repair-billing-print-table th {
  background: #eef1ec;
}

.repair-billing-print-table th:nth-child(1),
.repair-billing-print-table td:nth-child(1) {
  width: 24mm;
}

.repair-billing-print-table th:nth-child(3),
.repair-billing-print-table td:nth-child(3),
.repair-billing-print-table th:nth-child(5),
.repair-billing-print-table td:nth-child(5) {
  width: 28mm;
  text-align: right;
}

.repair-billing-print-table th:nth-child(4),
.repair-billing-print-table td:nth-child(4) {
  width: 16mm;
  text-align: center;
}

.repair-billing-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 16mm;
  margin-top: 8mm;
  font-size: 13pt;
}

.repair-billing-footer strong {
  text-align: right;
  font-size: 16pt;
}

.repair-billing-footer span {
  border-top: 1px solid #222;
  padding-top: 5mm;
  min-height: 18mm;
}

.serial-field {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.serial-field .scan-serial {
  min-height: 34px;
  padding: 6px 10px;
  white-space: nowrap;
}

.scanner-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(28, 37, 35, 0.58);
}

.scanner-card {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
  padding: 16px;
}

.scanner-card video {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #101816;
  border-radius: 7px;
  object-fit: cover;
}

.scanner-status {
  margin-top: 10px;
  color: var(--muted);
  font-weight: 700;
}

.danger-btn {
  color: var(--red);
  border-color: #e5c0be;
  background: #fff8f7;
}

.quote-manager {
  padding: 0;
}

.quote-manager summary {
  cursor: pointer;
  list-style: none;
  padding: 16px;
  font-weight: 800;
}

.quote-manager summary::-webkit-details-marker {
  display: none;
}

.quote-manager summary::after {
  content: "展開";
  float: right;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.quote-manager[open] summary::after {
  content: "收合";
}

.quote-manager-body {
  padding: 0 16px 16px;
}

.quote-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.quote-summary div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  padding: 12px;
  display: grid;
  gap: 6px;
}

.quote-summary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.print-quote {
  position: relative;
  overflow: hidden;
  background: #fff;
  border: 1px solid #d7d4cc;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(35, 39, 36, 0.08);
  padding: 22px 24px;
  max-width: 960px;
  margin: 0 auto;
}

.print-quote::before {
  content: "";
  position: absolute;
  inset: 130px 70px 110px;
  background: url("./assets/mx-logo.png") center / contain no-repeat;
  opacity: 0.055;
  pointer-events: none;
}

.print-quote > * {
  position: relative;
  z-index: 1;
}

.print-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  border-bottom: 3px solid var(--blue);
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.print-head div {
  display: grid;
  grid-template-columns: 135px 1fr;
  gap: 4px 16px;
  align-items: center;
}

.print-head img {
  width: 135px;
  height: 76px;
  object-fit: contain;
  grid-row: span 2;
}

.print-head strong {
  font-size: 25px;
}

.print-head h2 {
  min-width: 148px;
  margin: 0;
  text-align: center;
  white-space: nowrap;
  font-size: 31px;
  letter-spacing: 0;
}

.print-head span,
.muted-cell {
  color: var(--muted);
}

.print-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 15px;
  margin-bottom: 10px;
  font-size: 12.5px;
}

.print-title-row {
  margin: 8px 0 0;
  padding: 5px 10px;
  background: #eef1ec;
  border: 1px solid #222;
  border-bottom: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
}

.print-meta .span-2 {
  grid-column: span 2;
}

.print-table {
  min-width: 0;
  font-size: 12.5px;
}

.print-table th,
.print-table td {
  padding: 5px 8px;
  line-height: 1.35;
}

.print-table th {
  position: static;
  background: #f5f5f2;
  color: var(--ink);
  border-color: #222;
}

.print-table td {
  border-color: #222;
}

.quote-section-row td {
  background: #eef1ec;
  font-weight: 800;
  text-align: center;
  font-size: 16px;
  padding: 6px 8px;
}

.section-print-subtotal td {
  background: #f7f6f2;
  font-weight: 800;
  padding: 6px 8px;
}

.print-total {
  margin-top: 8px;
  display: grid;
  justify-content: end;
  gap: 3px;
  text-align: right;
}

.print-total strong {
  font-size: 18px;
}

.stamp-space {
  min-height: 78px;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  padding-top: 4px;
}

.stamp-space img {
  max-width: 150px;
  max-height: 92px;
  object-fit: contain;
}

.print-terms {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  font-size: 11.5px;
}

.print-terms p {
  margin: 2px 0;
}

.signature-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 34px;
  margin-top: 26px;
  min-height: 72px;
}

.signature-row > div {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(220px, 0.55fr);
  gap: 80px;
  align-items: flex-start;
}

.signature-row strong,
.signature-row span {
  display: block;
  min-height: 32px;
  white-space: nowrap;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .company-card {
    margin-top: 0;
  }

  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search {
    width: 100%;
  }

  .kpi-grid,
  .two-col,
  .form-grid,
  .sales-filters,
  .quote-summary {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .topbar,
  .panel,
  .print-tools {
    display: none !important;
  }

  .app-shell,
  .main {
    display: block;
    padding: 0;
  }

  .print-quote {
    display: block !important;
    border: 0;
    box-shadow: none;
    padding: 26px;
    max-width: none;
  }

  body.repair-print-mode .app-shell,
  body.repair-print-mode .login-screen {
    display: none !important;
  }

  body.repair-print-mode #repairBillingPrintRoot {
    display: block !important;
  }

  body.repair-print-mode .repair-billing-sheet {
    box-sizing: border-box;
    page-break-after: avoid;
  }

  table {
    font-size: 12px;
  }
}
