*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #0052CC;
  --primary-hover: #0747A6;
  --primary-light: #DEEBFF;
  --danger: #DE350B;
  --danger-light: #FFEBE6;
  --success: #006644;
  --success-light: #E3FCEF;
  --warning: #FF8B00;
  --warning-light: #FFFAE6;
  --border: #DFE1E6;
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --text: #172B4D;
  --text-muted: #6B778C;
  --text-subtle: #97A0AF;
  --radius: 6px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(9,30,66,0.13);
  --shadow-lg: 0 4px 12px rgba(9,30,66,0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

header {
  background: var(--surface);
  border-bottom: 2px solid var(--primary);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 20px; font-weight: 700; color: var(--text); }

.badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 3px;
  white-space: nowrap;
}

.header-right { display: flex; align-items: center; gap: 8px; }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

.section-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 12px;
}

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full-width { grid-column: 1 / -1; }

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.form-group input:read-only {
  background: var(--bg);
  color: var(--text-muted);
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
}

.computed-value {
  padding: 8px 12px;
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
}

.total-highlight {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 20px;
}

/* Logo Upload */
.logo-upload { position: relative; }

.logo-placeholder {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  transition: border-color 0.2s, background 0.2s;
}

.logo-placeholder:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.logo-preview {
  max-width: 200px;
  max-height: 80px;
  object-fit: contain;
  border-radius: var(--radius);
}

/* Revenue Stamp Notice */
.stamp-notice {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: var(--warning-light);
  border: 1px solid var(--warning);
  border-radius: var(--radius);
  margin-top: 16px;
}

.stamp-icon { font-size: 24px; flex-shrink: 0; }

.stamp-notice strong { color: var(--text); }
.stamp-notice p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.stamp-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 13px;
}

.stamp-table th,
.stamp-table td {
  padding: 4px 8px;
  border: 1px solid var(--border);
  text-align: left;
}

.stamp-table th {
  background: var(--bg);
  font-weight: 600;
}

.stamp-table tr.current {
  background: #FFF3CD;
  font-weight: 600;
}

/* Signature */
.signature-container { margin-top: 12px; }

#signaturePad {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  height: 200px;
  cursor: crosshair;
  touch-action: none;
}

.signature-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* Preview */
.receipt-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  background: #fff;
  min-height: 400px;
  font-size: 14px;
  line-height: 1.8;
}

.preview-header {
  text-align: center;
  margin-bottom: 24px;
  border-bottom: 3px double var(--text);
  padding-bottom: 16px;
}

.preview-header h3 {
  font-size: 28px;
  letter-spacing: 8px;
  margin-bottom: 8px;
}

.preview-header .receipt-no {
  font-size: 12px;
  color: var(--text-muted);
}

.preview-recipient {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--text);
  padding-bottom: 4px;
  display: inline-block;
}

.preview-amount-box {
  background: var(--bg);
  border: 2px solid var(--text);
  border-radius: var(--radius);
  padding: 16px 24px;
  text-align: center;
  margin: 16px 0;
}

.preview-amount {
  font-size: 32px;
  font-weight: 700;
}

.preview-details {
  margin: 20px 0;
}

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

.preview-details td {
  padding: 6px 0;
  font-size: 13px;
}

.preview-details td:first-child {
  width: 140px;
  font-weight: 600;
  color: var(--text-muted);
}

.preview-tax-breakdown {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin: 16px 0;
  font-size: 13px;
}

.preview-tax-breakdown table {
  width: 100%;
  border-collapse: collapse;
}

.preview-tax-breakdown th,
.preview-tax-breakdown td {
  padding: 4px 8px;
  text-align: right;
}

.preview-tax-breakdown th {
  text-align: left;
  font-weight: 600;
}

.preview-footer {
  margin-top: 32px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.preview-issuer { font-size: 13px; line-height: 1.6; }
.preview-issuer .name { font-size: 16px; font-weight: 600; }

.preview-seal {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-seal img {
  max-width: 80px;
  max-height: 80px;
}

.preview-logo {
  text-align: right;
  margin-bottom: 8px;
}

.preview-logo img {
  max-width: 160px;
  max-height: 60px;
  object-fit: contain;
}

.preview-invoice-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 3px;
  margin-top: 4px;
}

/* Action bar */
.action-bar {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #EBECF0; }

.btn-ghost {
  background: transparent;
  color: var(--primary);
}
.btn-ghost:hover { background: var(--primary-light); }

.btn-danger {
  background: transparent;
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger-light); }

.btn-lg { padding: 12px 32px; font-size: 16px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* History Table */
.table-wrapper { overflow-x: auto; }

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.history-table th,
.history-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.history-table th {
  font-weight: 600;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-table tr:hover { background: var(--bg); }

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

.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Tips */
.tips-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 12px;
}

.tip-item {
  text-align: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--bg);
}

.tip-icon { font-size: 28px; margin-bottom: 8px; }
.tip-item h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.tip-item p { font-size: 12px; color: var(--text-muted); }

/* Related Tools */
.related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.related-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.2s, border-color 0.2s;
}

.related-item:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.related-icon { font-size: 28px; flex-shrink: 0; }
.related-item strong { font-size: 14px; }
.related-item p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* FAQ */
.faq-list { margin-top: 12px; }

.faq-item {
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}

.faq-item summary {
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 0;
  list-style: none;
}

.faq-item summary::before {
  content: '▸ ';
  color: var(--primary);
}

.faq-item[open] summary::before { content: '▾ '; }

.faq-item p {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
  padding-left: 16px;
}

/* Responsive */
@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
  .tips-grid { grid-template-columns: 1fr; }
  .related-grid { grid-template-columns: 1fr; }
  header { padding: 12px 16px; }
  .header-left h1 { font-size: 16px; }
  .card { padding: 16px; }
  .receipt-preview { padding: 16px; }
  .preview-amount { font-size: 24px; }
  .preview-header h3 { font-size: 22px; letter-spacing: 4px; }
  .preview-footer { flex-direction: column; gap: 16px; }
  .action-bar { flex-direction: column; }
  .action-bar .btn { width: 100%; }
  #signaturePad { max-width: 100%; height: 150px; }
}

@media (max-width: 480px) {
  .container { padding: 12px 8px; }
  .badge { display: none; }
}

/* Print */
@media print {
  header, .action-bar, .stamp-notice, footer,
  #historySection, #tipsSection, #relatedSection, #faqSection,
  #issuerSection, #receiptSection, #signatureSection { display: none; }
  .receipt-preview { border: none; box-shadow: none; padding: 0; }
}
