* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Sarabun', sans-serif; background: #f4f6fa; color: #1f2937; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }

.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; background: #1e293b; color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.15); position: sticky; top: 0; z-index: 10;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.topbar .sub { font-size: 12px; opacity: .75; }
.actions { display: flex; gap: 8px; }

.btn {
  background: #334155; color: #fff; border: 0; padding: 8px 14px;
  border-radius: 6px; cursor: pointer; font-weight: 500; transition: .15s;
}
.btn:hover { background: #475569; }
.btn.primary { background: #3b82f6; }
.btn.primary:hover { background: #2563eb; }
.btn.success { background: #10b981; }
.btn.success:hover { background: #059669; }
.btn.danger { background: #ef4444; }
.btn.danger:hover { background: #dc2626; }

.privacy-notice {
  background: #ecfdf5; color: #065f46; padding: 8px 16px;
  font-size: 13px; border-bottom: 1px solid #a7f3d0; display: flex; gap: 8px; align-items: center;
}
.privacy-notice .link-btn { background: transparent; border: 0; color: #047857; cursor: pointer; text-decoration: underline; font-size: 12px; margin-left: auto; }
.privacy-notice.hidden { display: none; }

/* auth overlay */
.auth-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.65); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.auth-box {
  background: #fff; padding: 28px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  width: 100%; max-width: 380px;
}
.auth-box h2 { margin: 0 0 4px; font-size: 18px; color: #1e293b; }
.auth-box .auth-sub { margin: 0 0 16px; color: #64748b; font-size: 13px; }
.auth-box label { display: block; margin-bottom: 12px; font-size: 13px; color: #374151; }
.auth-box label input {
  display: block; width: 100%; padding: 10px 12px; margin-top: 5px;
  border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px;
}
.auth-box label input:focus { outline: 2px solid #93c5fd; border-color: #3b82f6; }
.auth-box .btn { width: 100%; padding: 10px; font-size: 14px; }
.auth-box .row-btn { display: flex; gap: 8px; }
.auth-box .row-btn .btn { flex: 1; }
.auth-err { color: #dc2626; font-size: 13px; margin-top: 8px; min-height: 16px; }
.auth-foot { margin-top: 16px; font-size: 11px; color: #94a3b8; text-align: center; }

.auth-tabs { display: flex; gap: 2px; margin: 0 0 16px; border-bottom: 1px solid #e5e7eb; }
.auth-tab {
  flex: 1; background: transparent; border: 0; padding: 8px 12px;
  font-size: 13px; color: #6b7280; cursor: pointer; border-bottom: 2px solid transparent;
  transition: .15s;
}
.auth-tab:hover { color: #1e293b; }
.auth-tab.active { color: #3b82f6; border-bottom-color: #3b82f6; font-weight: 600; }
.hint { display: block; color: #94a3b8; font-size: 11px; margin-top: 2px; }

.user-chip {
  background: rgba(255,255,255,.15); color: #fff; padding: 4px 10px;
  border-radius: 14px; font-size: 12px; margin-right: 6px;
}

.layout {
  display: grid;
  grid-template-columns: 220px minmax(420px, 1fr) minmax(520px, 1.1fr);
  gap: 12px; padding: 12px; flex: 1;
}

.sidebar { background: #fff; border-radius: 8px; padding: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.side-head h3 { margin: 4px 0 8px; font-size: 14px; }
.side-head input { width: 100%; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 5px; margin-bottom: 8px; }
.rec-list { list-style: none; padding: 0; margin: 0; max-height: 75vh; overflow: auto; }
.rec-list li {
  padding: 8px 10px; border-radius: 5px; cursor: pointer;
  border-left: 3px solid transparent; font-size: 13px; margin-bottom: 4px;
}
.rec-list li:hover { background: #f1f5f9; }
.rec-list li.active { background: #dbeafe; border-left-color: #3b82f6; }
.rec-list .nm { font-weight: 600; }
.rec-list .meta { color: #6b7280; font-size: 11px; }
.rec-list .del { float: right; color: #ef4444; padding: 0 4px; }

.editor, .preview-pane { background: #fff; border-radius: 8px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); overflow: auto; max-height: calc(100vh - 80px); }

fieldset { border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin: 0 0 12px; }
legend { padding: 0 8px; font-weight: 600; color: #1e40af; }
label { display: block; font-size: 13px; color: #374151; margin-bottom: 8px; }
label input, label select, label textarea {
  display: block; width: 100%; padding: 6px 8px; margin-top: 3px;
  border: 1px solid #d1d5db; border-radius: 5px; background: #fff;
}
label input:focus, label select:focus, label textarea:focus { outline: 2px solid #93c5fd; border-color: #3b82f6; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.profile-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; align-items: center; padding: 8px 10px; background: #f0f9ff; border-radius: 5px; border: 1px dashed #93c5fd; }
.btn-mini { background: #3b82f6; color: #fff; border: 0; padding: 5px 10px; font-size: 12px; border-radius: 4px; cursor: pointer; }
.btn-mini:hover { background: #2563eb; }
.btn-mini.danger { background: #ef4444; }
.btn-mini.danger:hover { background: #dc2626; }
.profile-status { font-size: 12px; color: #059669; font-weight: 500; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.income-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.income-tbl th, .income-tbl td { border: 1px solid #e5e7eb; padding: 6px 8px; vertical-align: middle; }
.income-tbl th { background: #f9fafb; font-weight: 600; text-align: left; }
.income-tbl input[type=number], .income-tbl input[type=text] { width: 100%; padding: 4px 6px; border: 1px solid #d1d5db; border-radius: 4px; }
.income-tbl input[type=checkbox] { transform: scale(1.15); }
.income-tbl td.r, .income-tbl th.r { text-align: right; }

.preview-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.preview-head h3 { margin: 0; }
.preview-scale { background: #e5e7eb; padding: 16px; border-radius: 6px; overflow: auto; }

/* certificate */
.cert {
  width: 210mm; min-height: 297mm; padding: 12mm 12mm 10mm;
  background: #fff; color: #000; font-size: 11pt; line-height: 1.35;
  box-shadow: 0 2px 8px rgba(0,0,0,.1); margin: 0 auto;
}
.cert h2 { text-align: center; font-size: 16pt; margin: 0 0 2px; }
.cert .sub-h { text-align: center; font-size: 11pt; margin: 0 0 6px; }
.cert .copy-line { text-align: left; font-size: 9pt; margin: 0 0 2px; }
.cert .doc-no { text-align: right; font-size: 10pt; }
.cert .top-row { display: flex; justify-content: space-between; align-items: flex-start; }
.cert .top-row .title-block { flex: 1; }
.cert .top-row .num-block { text-align: right; font-size: 10pt; width: 110px; }
.cert .party { border: 1px solid #000; padding: 6px 8px; margin-bottom: 6px; font-size: 10.5pt; }
.cert .party .head { display: flex; justify-content: space-between; }
.cert .party .head .label { font-weight: 600; }
.cert .row { display: flex; gap: 4px; align-items: baseline; margin: 2px 0; }
.cert .row .lab { flex: 0 0 auto; }
.cert .row .val { flex: 1; border-bottom: 1px dotted #555; min-height: 14pt; padding: 0 4px; }
.cert .row .val.right { text-align: right; }
.cert .taxid-boxes { display: inline-flex; gap: 2px; margin-left: 6px; }
.cert .taxid-boxes span { width: 14px; height: 16px; border: 1px solid #000; display: inline-block; text-align: center; font-size: 9pt; line-height: 16px; }
.cert .form-line { font-size: 10pt; margin: 4px 0 6px; }
.cert .form-line .opt { margin-right: 12px; }
.cert .check { display: inline-block; width: 12px; height: 12px; border: 1px solid #000; text-align: center; line-height: 11px; margin-right: 3px; vertical-align: middle; }
.cert .income-table { width: 100%; border-collapse: collapse; font-size: 10pt; margin-top: 4px; }
.cert .income-table th, .cert .income-table td { border: 1px solid #000; padding: 3px 5px; vertical-align: top; }
.cert .income-table th { background: #f0f0f0; text-align: center; font-weight: 600; }
.cert .income-table td.r { text-align: right; }
.cert .income-table td.c { text-align: center; }
.cert .income-table .desc { padding-left: 6px; }
.cert .income-table .sub-desc { padding-left: 18px; font-size: 9.5pt; }
.cert .total-row td { font-weight: 700; background: #f8f8f8; }
.cert .footer-block { border: 1px solid #000; padding: 6px 8px; margin-top: 6px; font-size: 10pt; }
.cert .sign-area { display: flex; gap: 10px; margin-top: 8px; align-items: flex-start; }
.cert .sign-area .warn { flex: 1; border: 1px solid #000; padding: 6px 8px; font-size: 9.5pt; }
.cert .sign-area .sign { flex: 1.2; padding: 6px 8px; font-size: 10pt; text-align: center; }
.cert .sign-area .sign .stamp { display: inline-block; border: 1px dashed #888; padding: 14px 18px; border-radius: 50%; margin-top: 6px; font-size: 9pt; color: #666; }

/* print */
.print-area { display: none; }

@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .no-print { display: none !important; }
  .print-area { display: block; }
  .cert { box-shadow: none; margin: 0; width: 210mm; min-height: 297mm; }
}
