:root {
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-soft: #eef6f2;
  --ink: #17211f;
  --muted: #62706c;
  --line: #d9e1dc;
  --primary: #0f766e;
  --primary-dark: #0a4f49;
  --accent-blue: #315a9b;
  --warning-amber: #a45f00;
  --danger-red: #b42318;
  --profit-green: #147a3f;
  --shadow: 0 16px 40px rgba(29, 43, 39, 0.08);
  color-scheme: light;
  font-family: Inter, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  padding: 14px 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand-logo {
  height: 42px;
  width: 150px;
}

.brand strong,
.brand span {
  display: block;
  overflow-wrap: anywhere;
}

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

.brand span,
.view-heading span,
label span,
.metric span,
.history-card span,
.offline-status,
.sheet-note,
.rule-panel li,
.rule-panel a {
  color: var(--muted);
}

.view-nav,
.button-row,
.pwa-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

.view-nav {
  background: #edf3ef;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
}

.view-nav button,
.install-button,
.primary-button,
.secondary-button,
.icon-text-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
}

.view-nav button {
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
}

.view-nav button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.12);
}

.install-button,
.secondary-button,
.icon-text-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  padding: 8px 12px;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
  padding: 9px 14px;
}

.primary-button:hover,
.primary-button:focus {
  background: var(--primary-dark);
}

.secondary-button:hover,
.icon-text-button:hover,
.install-button:hover {
  border-color: var(--primary);
}

.icon-button {
  background: #f7f8f5;
  border-color: var(--line);
  color: var(--muted);
  height: 38px;
  padding: 0;
  width: 38px;
}

.workspace {
  margin: 0 auto;
  max-width: 1440px;
  padding: 24px;
}

.view-panel[hidden] {
  display: none;
}

.quote-layout,
.business-layout {
  align-items: start;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1.6fr) minmax(360px, 0.9fr);
}

.quote-editor,
.business-form,
.summary-panel,
.quote-preview,
.rule-panel,
.history-layout {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.quote-editor,
.business-form,
.rule-panel,
.history-layout {
  padding: 20px;
}

.quote-side {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 92px;
}

.view-heading,
.section-row,
.item-card-header,
.sheet-head,
.sheet-meta,
.history-card {
  align-items: start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.view-heading {
  margin-bottom: 18px;
}

.view-heading p,
.summary-header p,
.history-layout p {
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.16;
  margin-bottom: 8px;
}

h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

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

.form-section {
  border-top: 1px solid var(--line);
  padding: 20px 0 0;
}

.form-section + .form-section {
  margin-top: 20px;
}

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

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

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label.wide,
.checkbox-line {
  grid-column: 1 / -1;
}

.checkbox-line {
  align-items: center;
  display: flex;
}

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

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(15, 118, 110, 0.14);
}

.item-list {
  display: grid;
  gap: 14px;
}

.item-card {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.button-row.compact {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button-row.compact select {
  min-height: 38px;
  width: 190px;
}

.summary-panel {
  overflow: hidden;
}

.summary-header {
  background: var(--surface-soft);
  padding: 20px;
}

.summary-header strong {
  display: block;
  font-size: 32px;
  line-height: 1.1;
}

.metric-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 16px;
}

.metric {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.metric strong {
  display: block;
  font-size: 18px;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.metric.good strong {
  color: var(--profit-green);
}

.metric.danger strong,
.warning-list .danger {
  color: var(--danger-red);
}

.tax-groups,
.warning-list {
  border-top: 1px solid var(--line);
  padding: 16px;
}

.tax-groups div {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}

.warning-list p {
  border-radius: 8px;
  margin: 8px 0 0;
  padding: 10px;
}

.warning-list .warning,
.warning-list .info {
  background: #fff7e6;
  color: var(--warning-amber);
}

.warning-list .ok {
  background: #ecfdf3;
  color: var(--profit-green);
}

.quote-preview {
  overflow-x: auto;
  padding: 16px;
}

.print-sheet {
  background: #ffffff;
  color: #111827;
}

.sheet-head {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 14px;
}

.sheet-head p,
.sheet-meta span,
.quote-table small {
  color: var(--muted);
  display: block;
}

.sheet-meta {
  border-bottom: 1px solid var(--line);
  margin: 16px 0;
  padding-bottom: 16px;
}

.quote-table {
  border-collapse: collapse;
  width: 100%;
}

.quote-table th,
.quote-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 6px;
  text-align: left;
  vertical-align: top;
}

.quote-table th {
  color: var(--muted);
  font-size: 13px;
}

.quote-table td:last-child,
.quote-table th:last-child {
  text-align: right;
}

.sheet-total {
  display: grid;
  gap: 8px 18px;
  grid-template-columns: 1fr auto;
  margin-left: auto;
  margin-top: 16px;
  max-width: 340px;
}

.sheet-total strong:last-child {
  color: var(--primary);
  font-size: 22px;
}

.sheet-note {
  margin: 16px 0 0;
}

.history-layout {
  min-height: 70vh;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-card {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.history-card > div {
  display: grid;
  min-width: 0;
}

.history-card select {
  max-width: 150px;
}

.empty-state {
  align-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  min-height: 180px;
}

.rule-panel ul {
  margin: 0 0 20px;
  padding-left: 20px;
}

.rule-panel a {
  display: block;
  margin-top: 10px;
}

.toast {
  background: var(--ink);
  border-radius: 8px;
  bottom: 18px;
  color: #ffffff;
  left: 50%;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 40;
}

@media (max-width: 1080px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .view-nav,
  .pwa-actions {
    justify-content: flex-start;
  }

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

  .quote-side {
    position: static;
  }
}

@media (max-width: 720px) {
  .workspace,
  .quote-editor,
  .business-form,
  .rule-panel,
  .history-layout {
    padding: 14px;
  }

  .workspace {
    padding: 14px;
  }

  .brand-logo {
    width: 128px;
  }

  .view-heading,
  .section-row,
  .item-card-header,
  .history-card {
    display: grid;
  }

  .button-row,
  .view-nav,
  .pwa-actions {
    flex-wrap: wrap;
  }

  .form-grid,
  .item-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .quote-table {
    font-size: 14px;
  }
}

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

  .topbar,
  .quote-editor,
  .summary-panel,
  .toast {
    display: none !important;
  }

  .workspace,
  .quote-preview {
    margin: 0;
    padding: 0;
  }

  .quote-layout {
    display: block;
  }

  .quote-preview {
    border: 0;
    box-shadow: none;
  }

  .print-sheet {
    font-size: 12px;
  }
}
