/* ---------- Layout ---------- */
.tps { --tps-blue: #356df1; --tps-ink: #111827; --tps-muted: #64748b; --tps-line: #d1d5db; --tps-soft: #f3f4f6;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 24px;
  align-items: start; max-width: 1200px; margin: 0 auto; color: var(--tps-ink); }
.tps *, .tps *::before, .tps *::after { box-sizing: border-box; }
.tps [hidden] { display: none !important; }
.tps-side { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 12px; }

/* ---------- Form ---------- */
.tps .tps-card { border: 1px solid var(--tps-line); border-radius: 10px; padding: 16px; margin: 0 0 16px; min-width: 0; }
.tps .tps-card legend { font-weight: 700; padding: 0 6px; font-size: 16px; }
.tps legend span, .tps label span, .tps .tps-label span { font-weight: 400; color: var(--tps-muted); font-size: 12px; }
.tps-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tps-wide { grid-column: 1 / -1; }
.tps label, .tps .tps-label { display: block; font-size: 13px; font-weight: 600; margin: 0; }
.tps input[type="text"], .tps input[type="number"], .tps input[type="date"], .tps select, .tps textarea {
  display: block; width: 100%; padding: 8px 10px; border: 1px solid var(--tps-line); border-radius: 6px; font: inherit;
  font-size: 14px; font-weight: 400; background: #fff; color: var(--tps-ink); margin: 4px 0 0; }
.tps .tps-row input { margin: 0; }
.tps .tps-logo-row { margin-top: 4px; }
.tps input:focus, .tps select:focus, .tps textarea:focus { outline: 2px solid var(--tps-blue); outline-offset: 0; border-color: var(--tps-blue); }
.tps input[readonly] { background: var(--tps-soft); }
.tps input[type="color"] { display: block; margin-top: 4px; width: 100%; height: 38px; padding: 2px; border: 1px solid var(--tps-line); border-radius: 6px; background: #fff; }
.tps .tps-check { display: flex; flex-direction: row; align-items: center; gap: 8px; font-weight: 400; margin: 12px 0 0; }
.tps .tps-check input { width: 16px; height: 16px; margin: 0; }
.tps-notes { margin-top: 12px; }
.tps-hint { font-size: 13px; color: var(--tps-muted); margin: 0 0 10px; }

.tps-logo-row { display: flex; align-items: center; gap: 10px; min-height: 38px; }
.tps-logo-row img { max-height: 38px; max-width: 110px; object-fit: contain; border: 1px solid var(--tps-line); border-radius: 4px; padding: 2px; }

/* Line items */
.tps-rows { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.tps-row { display: grid; gap: 6px; align-items: center; }
.tps-row-head { font-size: 12px; color: var(--tps-muted); font-weight: 600; }
.tps .tps-row input { padding: 7px 8px; }
.tps .tps-row .tps-del { width: 32px; height: 32px; padding: 0; border: 1px solid #c62828; color: #c62828; background: #fff;
  border-radius: 6px; cursor: pointer; line-height: 1; }
.tps .tps-row .tps-del:hover { background: #c62828; color: #fff; }

/* Buttons */
.tps .tps-btn { display: inline-flex; align-items: center; justify-content: center; padding: 9px 16px; border-radius: 6px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid var(--tps-blue); line-height: 1.2;
  transition: background .15s, color .15s, box-shadow .15s; flex-direction: row; }
.tps .tps-btn-primary { background: var(--tps-blue); color: #fff; box-shadow: 0 2px 6px rgba(53, 109, 241, .35); }
.tps .tps-btn-primary:hover:not(:disabled) { background: #2453c9; }
.tps .tps-btn-ghost { background: #fff; color: var(--tps-blue); }
.tps .tps-btn-ghost:hover:not(:disabled) { background: var(--tps-blue); color: #fff; }
.tps .tps-btn-link { background: none; border-color: transparent; color: var(--tps-muted); text-decoration: underline; padding: 9px 6px; }
.tps .tps-btn:disabled { opacity: .6; cursor: progress; }
.tps-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tps-status { min-height: 1.2em; margin: 0; font-size: 14px; font-weight: 600; }
.tps-status.tps-error { color: #c62828; }

/* ---------- Payslip sheet (preview + print) ---------- */
.tps-preview { border: 1px solid var(--tps-line, #d1d5db); border-radius: 10px; background: #fff;
  box-shadow: 0 4px 18px rgba(15, 23, 42, .08); overflow: hidden; }
.tps-sheet { --accent: #356df1; font-family: "Noto Sans", Arial, Helvetica, sans-serif; color: #111827; font-size: 12px;
  line-height: 1.4; padding: 26px; background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.tps-sheet * { box-sizing: border-box; }
.tps-sheet .tps-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start;
  padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid #d1d5db; }
.tps-sheet .tps-co { display: flex; gap: 12px; align-items: flex-start; min-width: 0; }
.tps-sheet .tps-co img { max-height: 48px; max-width: 140px; object-fit: contain; }
.tps-sheet .tps-co-name { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.tps-sheet .tps-co-sub { color: #64748b; font-size: 11px; white-space: pre-line; }
.tps-sheet .tps-title { text-align: right; flex-shrink: 0; }
.tps-sheet .tps-title strong { display: block; font-size: 20px; letter-spacing: .04em; }
.tps-sheet .tps-title span { color: #64748b; font-size: 11px; }
.tps-sheet .tps-info { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; margin: 0 0 16px; }
.tps-sheet .tps-info div { display: grid; grid-template-columns: 96px 1fr; gap: 8px; padding: 2px 0; }
.tps-sheet dt { color: #64748b; font-size: 9.5px; text-transform: uppercase; letter-spacing: .03em; padding-top: 2px; }
.tps-sheet dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.tps-sheet h4 { font-size: 13px; margin: 16px 0 6px; color: #111827; }
.tps-sheet table { width: 100%; border-collapse: collapse; margin: 0; font-size: 12px; }
.tps-sheet th, .tps-sheet td { padding: 6px 8px; text-align: left; border: 0; border-bottom: 1px solid #e5e7eb; vertical-align: top; }
.tps-sheet th { font-size: 10.5px; color: #64748b; font-weight: 700; background: #f3f4f6; }
.tps-sheet .n { text-align: right; white-space: nowrap; }
.tps-sheet tfoot td { font-weight: 700; border-bottom: 0; border-top: 1px solid #9ca3af; }
.tps-sheet .tps-net { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 18px 0 4px;
  padding: 12px 14px; border-radius: 6px; background: #f3f4f6; }
.tps-sheet .tps-net span { font-weight: 700; font-size: 14px; }
.tps-sheet .tps-net strong { font-size: 18px; }
.tps-sheet .tps-net-ytd { text-align: right; color: #64748b; font-size: 11px; margin: 0; }
.tps-sheet .tps-net.neg strong { color: #c62828; }
.tps-sheet .tps-small { color: #64748b; font-size: 10.5px; margin: 0 0 6px; }
.tps-sheet .tps-notes-out { white-space: pre-line; margin: 0; }

/* Modern */
.tps-t-modern { padding-top: 0; }
.tps-t-modern .tps-head { background: var(--accent); color: #fff; margin: 0 -26px 18px; padding: 22px 26px; border: 0; }
.tps-t-modern .tps-head .tps-co-sub, .tps-t-modern .tps-head .tps-title span { color: rgba(255, 255, 255, .9); }
.tps-t-modern h4 { color: var(--accent); }
.tps-t-modern th { background: var(--accent); color: #fff; }
.tps-t-modern .tps-net { background: var(--accent); color: #fff; }
/* Minimal */
.tps-t-minimal .tps-head { border-bottom: 2px solid var(--accent); }
.tps-t-minimal .tps-title strong, .tps-t-minimal h4, .tps-t-minimal .tps-net strong { color: var(--accent); }
.tps-t-minimal th { background: none; border-bottom: 1px solid var(--accent); }
.tps-t-minimal .tps-net { background: none; border-top: 1.5px solid var(--accent); border-bottom: 1.5px solid var(--accent); border-radius: 0; }

/* Print iframe */
body.tps-print { margin: 0; background: #fff; }
body.tps-print .tps-sheet { padding: 0; }
body.tps-print .tps-t-modern .tps-head { margin: 0 0 18px; }

@media (max-width: 520px) {
  /* Line items: description on its own line, numbers and the remove button underneath */
  .tps .tps-row { grid-template-columns: repeat(var(--tps-nums, 1), minmax(0, 1fr)) 32px !important; }
  .tps .tps-row > :first-child { grid-column: 1 / -1; }
  .tps .tps-row-head > :first-child { display: none; }
  .tps .tps-row:not(.tps-row-head) + .tps-row { margin-top: 6px; }
  .tps-sheet { padding: 16px; font-size: 11px; }
  .tps-t-modern .tps-head { margin: 0 -16px 16px; padding: 16px; }
  .tps-sheet .tps-head { flex-direction: column; }
  .tps-sheet .tps-title { text-align: left; }
  .tps-sheet .tps-info { grid-template-columns: 1fr; }
  .tps-sheet th, .tps-sheet td { padding: 5px 4px; }
  .tps-side { position: static; }
}
