:root {
  --primary-color: #00bfa5;
  --secondary-color: #111827;
  --success-color: #22c55e;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --gray-light: #f3f4f6;
  --gray: #6b7280;
  --border-radius: 10px;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
  --shadow-soft: 0 4px 16px rgba(17, 24, 39, 0.06);
  --ring: 0 0 0 3px rgba(0, 191, 165, 0.18);
  --font-sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html { font-family: var(--font-sans); }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

.container { max-width: 1200px; margin: 0 auto; }

.page-header {
  background: var(--surface);
  padding: 16px 20px;
  border-radius: var(--border-radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
}

.page-header h1 { color: var(--text); font-size: 20px; }
.page-header h2 { color: var(--text); font-size: 20px; }

.card {
  background: var(--surface);
  border-radius: var(--border-radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  border: 1px solid var(--border);
}

.card-header {
  padding: 16px 20px;
  background: var(--gray-light);
  border-bottom: 1px solid var(--border);
}

.card-header h2 { font-size: 16px; color: var(--text); }
.card-body { padding: 20px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.form-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--border-radius); font-size: 14px; font-family: inherit; color: var(--text); background: #fff; }
.form-control:focus { outline: none; border-color: var(--primary-color); box-shadow: var(--ring); }
textarea.form-control { min-height: 90px; resize: vertical; }
.dup-warning { display: block; color: var(--danger-color); font-size: 12px; margin-top: 4px; padding: 4px 8px; background: #fef2f2; border-radius: 4px; }
.form-control.has-duplicate { border-color: var(--danger-color); background: #fef2f2; }

.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    gap: 6px;
    align-items: center;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.btn span { opacity: 0.85; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); box-shadow: 0 1px 2px rgba(0,0,0,0.1); }
.btn-small { padding: 6px 12px; font-size: 12px; }
.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover { background: #00a896; }
.btn-success { background: var(--success-color); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-secondary { background: var(--gray-light); color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn-secondary:hover { background: #e5e7eb; }
.btn-danger { background: var(--danger-color); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-info { background: #3b82f6; color: #fff; }
.btn-info:hover { background: #2563eb; }

.doc {
  background: white;
  padding: 40px;
  border: 1px solid #ddd;
  color: #111;
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.65;
  font-weight: 500;
}

.receipt-main { margin: 22px 0; }
.receipt-amount { font-size: 28px; font-weight: 800; margin: 14px 0; }
.receipt-box { border-top: 1px solid #ddd; padding-top: 14px; white-space: pre-line; }
.receipt-doc .doc-title { text-align: left; }
.receipt-doc .doc-meta-table { margin-left: 0; }
.receipt-doc .doc-meta-table tr:last-child td { border-bottom: 1px solid #ddd; }
.receipt-doc .doc-seal-wrap { justify-content: flex-end; }
.receipt-doc .doc-seal-wrap .doc-company-info { right: auto; left: 0; }
.receipt-doc .doc-seal { justify-content: flex-end; transform: translate(0, -18px); }
.doc-header { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 18px; align-items: flex-start; }
.doc-client-info { flex: 1; }
.doc-client-info #previewClientName,
.doc-client-info #previewVendorName,
.invoice-client-info #previewClientName { font-size: 22px; font-weight: 800; margin-bottom: 6px; }

.doc #previewClientName,
.doc #previewVendorName { font-size: 22px; font-weight: 800; }
.doc-title { text-align: left; min-width: 248px; }
.doc:not(.receipt-doc) .doc-title { margin-right: 0; }
.doc-title h1 { font-size: 34px; color: #333; margin-bottom: 8px; }
.doc-company-info { margin-top: 10px; font-size: 13px; color: #111; text-align: left; }
.doc-meta-table { margin-left: 0; border-collapse: collapse; font-size: 14px; line-height: 1.35; }
.doc-meta-table td { padding: 4px 0; vertical-align: top; border-bottom: 1px solid #ddd; }
.doc-meta-table tr:last-child td { border-bottom: 1px solid #ddd; }
.doc-meta-table td:first-child { white-space: nowrap; padding-right: 10px; color: #374151; text-align: left; }
.doc-meta-table td:last-child { white-space: nowrap; font-weight: 600; text-align: left; }
.doc-seal { margin-top: 6px; display: flex; justify-content: flex-end; transform: translate(0, -18px); }
.doc:not(.receipt-doc) .doc-seal { transform: translate(-24px, -18px); }
.doc-seal img { max-width: 120px; max-height: 120px; object-fit: contain; }

.doc-seal-wrap { position: relative; margin-top: 10px; display: flex; justify-content: flex-end; }
.doc-seal-wrap .doc-company-info { position: absolute; right: auto; left: 0; top: 0; margin-top: 0; z-index: 1; }
.doc-seal-wrap .doc-seal { position: relative; z-index: 2; }
.doc-seal-wrap .doc-seal::before {
  content: "";
  position: absolute;
  inset: -6px;
  background: transparent;
  border-radius: 10px;
  z-index: -1;
}

.doc-table { width: 100%; border-collapse: separate; border-spacing: 0; margin: 24px 0; border: 1px solid #cfd4dc; border-radius: 6px; overflow: hidden; }
.doc-table th, .doc-table td { border: 0; border-bottom: 1px solid #cfd4dc; border-right: 1px solid #cfd4dc; padding: 10px; text-align: left; }
.doc-table tr:last-child th, .doc-table tr:last-child td { border-bottom: 0; }
.doc-table th:last-child, .doc-table td:last-child { border-right: 0; }
.doc-table th { background: var(--gray-light); font-weight: 600; }

.invoice-bank { margin-top: 30px; padding: 20px; background: transparent; border: 1px solid #cfd4dc; border-radius: 6px; overflow: hidden; }
.invoice-bank h3 { margin-bottom: 10px; color: var(--primary-color); }
.invoice-bank-table { width: 100%; border-collapse: separate; border-spacing: 0; background: transparent; border: 0; }
.invoice-bank-table th, .invoice-bank-table td { border: 0; border-bottom: 1px solid #cfd4dc; border-right: 1px solid #cfd4dc; padding: 8px 10px; vertical-align: top; font-size: 13px; }
.invoice-bank-table tr:last-child th, .invoice-bank-table tr:last-child td { border-bottom: 0; }
.invoice-bank-table th:last-child, .invoice-bank-table td:last-child { border-right: 0; }
.invoice-bank-table th { width: 140px; background: var(--gray-light); font-weight: 700; white-space: nowrap; text-align: left; }
.invoice-bank-table td { text-align: left; }

.doc-summary { margin-top: 8px; border: 1px solid #cfd4dc; border-radius: 6px; overflow: hidden; }
.doc-summary-table { width: 100%; border-collapse: collapse; }
.doc-summary-table th, .doc-summary-table td { border-bottom: 1px solid #cfd4dc; padding: 8px 12px; vertical-align: top; }
.doc-summary-table tr:last-child th, .doc-summary-table tr:last-child td { border-bottom: 0; }
.doc-summary-table th { text-align: left; font-weight: 600; background: #fff; white-space: nowrap; width: 110px; }
.doc-summary-table td { text-align: right; font-weight: 700; background: #fff; white-space: nowrap; min-width: 200px; width: 50%; }
.doc-summary-remarks { text-align: left; font-weight: 400; white-space: pre-line; width: 40%; border-right: 1px solid #cfd4dc; border-bottom: 0 !important; min-width: 0; }
.doc-summary-table tr.is-total th { background: #f8fafc; }
.doc-summary-table tr.is-total td { background: #f8fafc; font-size: 22px; font-weight: 800; }

.data-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.data-table th, .data-table td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--gray-light); font-weight: 600; color: var(--text-muted); }
.data-table tr:hover { background: #f9fafb; }

.status-badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-draft { background: #e5e7eb; color: #374151; }
.status-submitted { background: #fef3c7; color: #92400e; }
.status-approved { background: #dcfce7; color: #166534; }
.status-rejected { background: #fee2e2; color: #991b1b; }
.status-paid { background: #dbeafe; color: #1e40af; }
.status-issued { background: #e0f2fe; color: #075985; }

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.message { padding: 12px; border-radius: var(--border-radius); margin-bottom: 15px; display: none; }
.message.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.message.error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.message.show { display: block; }

@media print {
  body { background: white; padding: 0; }
  .card { box-shadow: none; margin: 0; }
  .no-print { display: none !important; }
  .doc:not(.receipt-doc):not(.invoice-preview) { border: none; padding: 0; }
  .invoice-preview { border: none; padding: 40px; }
  .receipt-doc { border: 1px solid #000; padding: 40px; }
  .doc-header, .invoice-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
  .doc-client-info, .invoice-client-info { flex: 1; max-width: 320px; }
  .doc-title, .invoice-title { min-width: 248px; margin-right: 0; }
  .receipt-doc .doc-title { min-width: 0; margin-right: 0; }
  .doc-summary-table { table-layout: fixed; }
  .doc-summary-table th, .doc-summary-table td { padding: 6px 10px; }
  .doc-summary-remarks { width: 40% !important; }
  .doc-summary-table th { width: 10% !important; }
  .doc-summary-table td { width: 50% !important; min-width: 0 !important; }
  .doc-summary-table tr.is-total td { font-size: 18px !important; }
}
