:root {
  --brand-red: #e60012;
  --brand-red-dark: #b8000e;
  --gold: #ffc107;
  --green: #187a56;
  --ink: #262a31;
  --muted: #667085;
  --line: #dde3ea;
  --panel: #ffffff;
  --page: #f4f6f8;
  --soft-red: #fff1f2;
  --soft-gold: #fff8df;
  --soft-green: #eaf8f1;
  --shadow: 0 14px 32px rgba(20, 24, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
  line-height: 1.5;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

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

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(230, 0, 18, 0.08), transparent 40%),
    linear-gradient(315deg, rgba(255, 193, 7, 0.2), transparent 46%),
    var(--page);
}

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

.login-panel {
  display: grid;
  gap: 16px;
  width: min(440px, 100%);
  padding: 28px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.bit-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 42%, #ffffff 42%, #ffffff 58%, transparent 58%),
    linear-gradient(0deg, transparent 42%, #ffffff 42%, #ffffff 58%, transparent 58%),
    linear-gradient(135deg, var(--brand-red), var(--gold));
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--brand-red-dark);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-panel h1,
.brand-lockup h1 {
  font-size: 1.52rem;
  line-height: 1.2;
}

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 0.92rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 9px 11px;
}

textarea {
  min-height: 98px;
  padding: 11px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px rgba(230, 0, 18, 0.1);
}

.primary-action,
.secondary-action,
.ghost-action {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 900;
  white-space: nowrap;
}

.primary-action {
  color: #fff;
  background: var(--brand-red);
}

.secondary-action {
  color: var(--brand-red-dark);
  background: var(--soft-red);
}

.ghost-action {
  color: #584000;
  background: var(--soft-gold);
}

.status-line {
  min-height: 24px;
  color: var(--muted);
  font-weight: 700;
}

.status-line.is-error {
  color: var(--brand-red);
}

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

.side-panel {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100vh;
  border-top: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
  padding: 22px;
}

.user-chip {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--soft-gold);
}

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

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

.nav-list button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: transparent;
  font-weight: 900;
  text-align: left;
}

.nav-list button:hover,
.nav-list button.is-active {
  color: var(--brand-red-dark);
  background: var(--soft-red);
}

.side-actions {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

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

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

.topbar h2 {
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.25;
}

.top-status {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--green);
  background: #fff;
  font-size: 0.9rem;
  font-weight: 800;
}

.page-section {
  display: none;
}

.page-section.is-active {
  display: grid;
  gap: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 12px;
}

.metric-card {
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}

.metric-card span,
.detail-grid span,
.pricing-preview span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.metric-card strong {
  display: block;
  margin-top: 10px;
  font-size: 1.45rem;
  line-height: 1.15;
}

.overview-grid,
.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

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

.panel-heading h3 {
  font-size: 1.22rem;
  line-height: 1.3;
}

.panel-heading > span,
.section-mini-heading span {
  color: var(--brand-red-dark);
  font-weight: 900;
}

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

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

.addon-section,
.pricing-preview,
.detail-section {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.addon-grid {
  display: grid;
  gap: 12px;
}

.addon-group {
  display: grid;
  grid-template-columns: 160px repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: start;
}

.addon-group > strong {
  padding-top: 10px;
  color: var(--brand-red-dark);
}

.addon-group label {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px 10px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.addon-group input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
  accent-color: var(--brand-red);
}

.addon-group span {
  font-weight: 800;
}

.addon-group em {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.84rem;
  font-style: normal;
}

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

.pricing-preview div,
.detail-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.pricing-preview strong,
.detail-grid strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

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

.filter-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.3fr) repeat(7, minmax(120px, 1fr)) auto auto;
  gap: 8px;
  margin-bottom: 14px;
}

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

.table-head,
.table-row {
  display: grid;
  grid-template-columns: 1.1fr 1.35fr 1fr 0.9fr 0.9fr 0.85fr;
  gap: 10px;
  align-items: center;
}

.table-head {
  padding: 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.table-row {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.table-row:hover,
.table-row.is-active {
  border-color: var(--brand-red);
  background: var(--soft-red);
}

.table-row strong,
.compact-item strong {
  display: block;
}

.table-row small,
.compact-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 3px 9px;
  color: #344054;
  background: #eef2f6;
  font-style: normal;
  font-weight: 900;
  white-space: nowrap;
}

.status-draft {
  background: #eef2f6;
}

.status-pending_approval {
  color: #7a5200;
  background: var(--soft-gold);
}

.status-approved,
.status-sent {
  color: var(--green);
  background: var(--soft-green);
}

.status-signed,
.status-paid {
  color: #fff;
  background: var(--green);
}

.status-rejected,
.status-cancelled {
  color: var(--brand-red-dark);
  background: var(--soft-red);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.pager span {
  color: var(--muted);
  font-weight: 800;
}

.detail-panel {
  align-self: start;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.line-list,
.history-list,
.compact-list,
.user-list,
.log-list {
  display: grid;
  gap: 8px;
}

.line-list > div,
.compact-item,
.user-row,
.log-row,
.history-list article,
.schema-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.line-list > div,
.compact-item,
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compact-item {
  width: 100%;
  color: var(--ink);
  text-align: left;
}

.compact-item:hover {
  border-color: var(--brand-red);
}

.compact-item em,
.user-row em {
  color: var(--brand-red-dark);
  font-style: normal;
  font-weight: 900;
  white-space: nowrap;
}

.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

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

.history-list span,
.log-row span,
.log-row small,
.schema-card span,
.user-row small {
  color: var(--muted);
}

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

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-row div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.bar-row span {
  color: var(--muted);
  font-weight: 900;
}

.bar-row i {
  display: block;
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #edf0f3;
}

.bar-row b {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand-red), var(--gold));
}

.large-number {
  color: var(--brand-red-dark);
  font-size: clamp(2rem, 4vw, 4.2rem);
  font-weight: 900;
  line-height: 1.1;
}

.schema-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.schema-grid h3 {
  margin: 0 0 10px;
}

.schema-grid section {
  display: grid;
  align-content: start;
  gap: 8px;
}

.schema-card {
  display: grid;
  gap: 5px;
}

.empty-state {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: #fff;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: 360px;
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1280px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .filter-grid,
  .pricing-preview,
  .detail-grid,
  .payment-grid,
  .schema-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-grid {
    align-items: stretch;
  }
}

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

  .side-panel {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .nav-list button {
    text-align: center;
  }

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

  .overview-grid,
  .report-grid,
  .form-grid,
  .addon-group,
  .table-head,
  .table-row {
    grid-template-columns: 1fr;
  }

  .table-head {
    display: none;
  }
}

@media (max-width: 640px) {
  .workspace,
  .side-panel {
    padding: 16px;
  }

  .topbar,
  .panel-heading,
  .section-mini-heading,
  .line-list > div,
  .compact-item,
  .user-row {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .filter-grid,
  .pricing-preview,
  .detail-grid,
  .payment-grid,
  .schema-grid,
  .nav-list {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .pager {
    flex-direction: column;
  }

  .primary-action,
  .secondary-action,
  .ghost-action {
    width: 100%;
  }
}
