* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", sans-serif;
  background: #f5f6f8;
  color: #1a1a1a;
}
.topbar {
  position: sticky;
  top: 0;
  background: #fff;
  padding: 12px 16px 4px;
  border-bottom: 1px solid #e5e5e5;
  z-index: 10;
}
.topbar h1 {
  font-size: 18px;
  margin: 0 0 8px;
}
.nav-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.navbtn {
  flex: 1;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid #d9d9d9;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  color: #555;
}
.navbtn.active {
  background: #1a1a1a;
  border-color: #1a1a1a;
  color: #fff;
}
.search-row input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #d9d9d9;
  font-size: 14px;
  margin-bottom: 8px;
}
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.tab {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #d9d9d9;
  background: #fff;
  font-size: 13px;
  color: #555;
}
.tab.active {
  background: #06c755;
  border-color: #06c755;
  color: #fff;
}
.status-tabs .tab.active {
  background: #333;
  border-color: #333;
}
main {
  padding: 12px 16px 80px;
}
.state-msg {
  text-align: center;
  color: #888;
  padding: 32px 0;
  font-size: 14px;
}
.state-msg.error { color: #c0392b; }
.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.item-card {
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.item-card .row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.item-card .contact {
  font-weight: 600;
  font-size: 15px;
}
.item-card .due {
  font-size: 12px;
  color: #888;
}
.item-card .due.overdue {
  color: #e74c3c;
  font-weight: 600;
}
.item-card .note {
  font-size: 13px;
  color: #444;
  margin-top: 4px;
}
.item-card .meta {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef0f2;
  color: #555;
}
.badge.tier-合約客戶 { background: #e3f6e8; color: #16794a; }
.badge.tier-非合約客戶 { background: #fdeeee; color: #b03434; }
.badge-warn { background: #fdecc8; color: #a15c00; font-weight: 600; }

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
/* .sheet's own `display: flex` has the same specificity as the browser's [hidden] default
   and wins on source order, so the sheet stays visible (as an empty bottom sliver) even
   when the `hidden` attribute is set unless we say this explicitly. */
.sheet[hidden] {
  display: none;
}
.sheet-content {
  background: #fff;
  width: 100%;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px 28px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}
.sheet-close {
  position: absolute;
  top: 10px;
  right: 14px;
  border: none;
  background: none;
  font-size: 16px;
  color: #888;
}
.field-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}
.field-row label {
  font-size: 12px;
  color: #888;
}
.field-row select, .field-row input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #d9d9d9;
  font-size: 14px;
}
.action-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.action-row button {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 600;
}
.btn-primary { background: #06c755; color: #fff; }
.btn-secondary { background: #eef0f2; color: #333; }
.media-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  color: #06c755;
}

.confirm-summary {
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 14px;
  color: #444;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.confirm-summary div {
  margin-bottom: 4px;
}
.lineitem-block {
  background: #fff;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.lineitem-block > label:first-child {
  font-weight: 600;
  color: #1a1a1a;
  font-size: 13px;
}
.lineitem-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #444 !important;
  margin: 10px 0 4px;
}
.checkbox-row input {
  width: auto;
}

.export-row {
  font-size: 12px;
  color: #888;
  padding: 4px 0 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.export-row a {
  color: #06c755;
  text-decoration: none;
  font-weight: 600;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 18px 0 8px;
  padding-top: 10px;
  border-top: 1px solid #eee;
}
.contract-history-item, .note-item {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: #555;
}
.note-item .note-date {
  color: #999;
  font-size: 11px;
  margin-bottom: 2px;
}
.inline-btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  background: #eef0f2;
  color: #333;
  font-size: 12px;
  font-weight: 600;
}
.inline-btn.pay {
  background: #06c755;
  color: #fff;
}
.item-card .row1 .amount {
  font-weight: 600;
  color: #1a1a1a;
}
