:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1f2328;
  --muted: #6b7280;
  --primary: #0a7d1f;
  --primary-hover: #0c8d23;
  --danger: #b42318;
  --danger-bg: #fef0ef;
  --success-bg: #effaf0;
  --warn-bg: #fff7e6;
  --info-bg: #eef4ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef0f3; padding: 2px 6px; border-radius: 4px; font-size: 0.92em; }
pre { white-space: pre-wrap; }

.container { max-width: 1100px; margin: 24px auto; padding: 0 20px; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .brand a { font-weight: 700; font-size: 1.05em; color: var(--text); }
.topnav { display: flex; gap: 16px; flex: 1; margin-left: 20px; }
.topnav a { color: var(--text); padding: 4px 0; border-bottom: 2px solid transparent; }
.topnav a:hover { border-bottom-color: var(--primary); text-decoration: none; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 0.92em; }

.role { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 0.78em; margin-left: 6px; }
.role-admin { background: #1a73e8; color: #fff; }
.role-customer { background: #6b7280; color: #fff; }

.footer { text-align: center; color: var(--muted); padding: 20px 0; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.page-head h1 { margin: 0; font-size: 1.5em; }
.page-head .actions { display: flex; gap: 8px; }

h1 { font-size: 1.6em; margin: 0 0 16px; }
h2 { font-size: 1.2em; margin: 0 0 12px; }
h3 { font-size: 1.05em; margin: 0 0 8px; }
.muted { color: var(--muted); }
.ta-right { text-align: right; }

.btn { display: inline-block; padding: 6px 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; cursor: pointer; font-size: 0.95em; text-decoration: none; }
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-block { width: 100%; }

form.inline { display: inline-block; margin: 0; }
form.stacked { display: flex; flex-direction: column; gap: 12px; }
form.stacked label { display: flex; flex-direction: column; gap: 4px; font-size: 0.92em; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff; color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 18px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.kpi-label { color: var(--muted); font-size: 0.85em; }
.kpi-value { font-size: 1.6em; font-weight: 700; margin-top: 4px; }

table.data { width: 100%; border-collapse: collapse; background: var(--surface); }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { background: #fafbfc; font-weight: 600; font-size: 0.92em; color: var(--muted); }
table.data tr:hover td { background: #fafbfc; }

.status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.82em; background: #eef0f3; color: #4b5563; }
.status-draft { background: #e5e7eb; color: #374151; }
.status-sent { background: var(--info-bg); color: #1e40af; }
.status-viewed { background: #fef3c7; color: #92400e; }
.status-accepted { background: var(--success-bg); color: #166534; }
.status-rejected { background: var(--danger-bg); color: var(--danger); }
.status-expired { background: #f3f4f6; color: #6b7280; }

.event-tag { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 0.75em; background: #e5e7eb; color: #374151; margin-right: 6px; }
.event-viewed { background: #fef3c7; color: #92400e; }
.event-accepted { background: var(--success-bg); color: #166534; }
.event-rejected { background: var(--danger-bg); color: var(--danger); }
.event-status_changed { background: var(--info-bg); color: #1e40af; }

.events { list-style: none; padding: 0; margin: 0; }
.events li { padding: 8px 0; border-bottom: 1px dotted var(--border); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 0.93em; }
.events time { color: var(--muted); font-size: 0.85em; margin-left: auto; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid transparent; }
.flash-success { background: var(--success-bg); border-color: #b9e4c1; color: #166534; }
.flash-error { background: var(--danger-bg); border-color: #f4c4c0; color: var(--danger); }
.flash-info { background: var(--info-bg); border-color: #c7d8f5; color: #1e40af; }

.login-card { max-width: 380px; margin: 80px auto; background: var(--surface); padding: 28px; border-radius: 10px; border: 1px solid var(--border); }
.login-card h1 { text-align: center; margin: 0 0 6px; }
.login-card p.muted { text-align: center; margin: 0 0 18px; }

.filter { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; }
.filter input, .filter select { width: auto; min-width: 200px; }

.notes { background: #fafbfc; padding: 10px 12px; border-left: 3px solid var(--border); border-radius: 4px; font-family: inherit; }

.danger-zone { margin-top: 30px; padding: 14px; border: 1px dashed var(--danger); border-radius: 6px; }

.items-table input { width: 100%; }
.items-table .qty, .items-table .price { text-align: right; }
.line-total { font-weight: 600; text-align: right; }

.totals { margin-top: 16px; text-align: right; }
.totals > div { padding: 4px 0; }
.total-grand { font-size: 1.3em; font-weight: 700; border-top: 2px solid var(--text); margin-top: 6px; padding-top: 8px; }

.status-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.quote-public { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 28px; }
.quote-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 2px solid var(--text); padding-bottom: 12px; margin-bottom: 18px; }
.quote-head h1 { margin: 0; }
.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 12px 0 24px; }
.parties h3 { color: var(--muted); font-size: 0.85em; margin: 0 0 6px; }
.parties p { margin: 2px 0; }
.quote-items tfoot td, .quote-items tfoot th { padding-top: 8px; }
.quote-items tfoot tr.grand th, .quote-items tfoot tr.grand td { font-size: 1.15em; font-weight: 700; border-top: 2px solid var(--text); }
.quote-actions { margin-top: 24px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

dialog { border: none; border-radius: 10px; padding: 24px; max-width: 480px; width: 90%; box-shadow: 0 10px 40px rgba(0,0,0,0.2); }
dialog::backdrop { background: rgba(0,0,0,0.4); }

/* === v0.2 additions === */

.card-inset { border: 1px dashed var(--border); border-radius: 8px; padding: 14px 18px; margin: 8px 0; background: #fafbfc; }
.card-inset legend { padding: 0 8px; font-weight: 600; color: var(--muted); font-size: 0.9em; }

.switch-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.switch-row input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; }

.signature-canvas { border: 2px dashed var(--border); border-radius: 8px; background: #fff; touch-action: none; cursor: crosshair; display: block; width: 100%; max-width: 500px; height: 160px; }
.sig-pad-wrap { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.signature-preview { max-width: 360px; border: 1px solid var(--border); border-radius: 6px; padding: 6px; background: #fff; }

.badge-ok { color: #166534; background: var(--success-bg); padding: 2px 8px; border-radius: 4px; font-size: 0.85em; }

.status-pending { background: #fef3c7; color: #92400e; }
.status-paid, .status-succeeded { background: var(--success-bg); color: #166534; }
.status-failed, .status-refunded { background: var(--danger-bg); color: var(--danger); }
.status-none { background: #f3f4f6; color: #6b7280; }

.huge-amount { font-size: 2.5em; font-weight: 700; text-align: center; color: var(--primary); margin: 12px 0; }

.pay-methods { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin: 16px 0; }
.pay-method-form { margin: 0; }
.pay-method-btn { width: 100%; padding: 24px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; transition: all 0.15s ease; }
.pay-method-btn:hover { border-color: var(--primary); background: #f0f9f1; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.pm-icon { font-size: 2em; }
.pm-title { font-size: 1.2em; font-weight: 600; }
.pm-desc { font-size: 0.85em; color: var(--muted); }

dialog .signature-canvas { max-width: 100%; }
