/* ---------- Layout ---------- */
.tin { --tin-blue: #356df1; --tin-ink: #111827; --tin-muted: #64748b; --tin-line: #d1d5db; --tin-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(--tin-ink); }
.tin *, .tin *::before, .tin *::after { box-sizing: border-box; }
.tin [hidden] { display: none !important; }
.tin-side { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.tin-form { min-width: 0; }

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

/* Items */
.tin-rows { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 8px; }
.tin-row { display: grid; grid-template-columns: minmax(0, 2.6fr) minmax(0, .8fr) minmax(0, .9fr) minmax(0, 1.1fr) minmax(0, 1fr) 32px; gap: 6px; align-items: center; }
.tin-row-head { font-size: 12px; color: var(--tin-muted); font-weight: 600; }
.tin .tin-row input { margin: 0; padding: 7px 8px; }
.tin-row-amount { font-size: 14px; font-weight: 700; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tin .tin-row .tin-del { width: 32px; height: 32px; padding: 0; border: 1px solid #c62828; color: #c62828; background: #fff; border-radius: 6px; cursor: pointer; line-height: 1; }
.tin .tin-row .tin-del:hover { background: #c62828; color: #fff; }
@media (max-width: 520px) {
  .tin .tin-row { grid-template-columns: repeat(3, minmax(0, 1fr)) 32px !important; }
  .tin .tin-row > :first-child { grid-column: 1 / -1; }
  .tin .tin-row-head { display: none; }
  .tin .tin-row-amount { grid-column: 1 / span 3; text-align: left; }
  .tin .tin-row + .tin-row { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--tin-line); }
}

/* Buttons */
.tin .tin-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(--tin-blue); line-height: 1.2; margin: 0;
  transition: background .15s, color .15s; }
.tin .tin-btn-primary { background: var(--tin-blue); color: #fff; box-shadow: 0 2px 6px rgba(53, 109, 241, .35); }
.tin .tin-btn-primary:hover:not(:disabled) { background: #2453c9; }
.tin .tin-btn-ghost { background: #fff; color: var(--tin-blue); }
.tin .tin-btn-ghost:hover:not(:disabled) { background: var(--tin-blue); color: #fff; }
.tin .tin-btn-link { background: none; border-color: transparent; color: var(--tin-muted); text-decoration: underline; padding: 9px 6px; }
.tin .tin-btn:disabled { opacity: .6; cursor: progress; }
.tin-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tin-status { min-height: 1.2em; margin: 0; font-size: 14px; font-weight: 600; }
.tin-status.tin-error { color: #c62828; }

/* ---------- Invoice sheet (preview + print) ---------- */
.tin-preview { border: 1px solid var(--tin-line, #d1d5db); border-radius: 10px; background: #fff; box-shadow: 0 4px 18px rgba(15, 23, 42, .08); overflow: hidden; }
.tin-sheet { --accent: #356df1; position: relative; font-family: "Noto Sans", Arial, Helvetica, sans-serif; color: #111827; font-size: 12px;
  line-height: 1.45; padding: 26px; background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.tin-sheet * { box-sizing: border-box; }
.tin-sheet p { margin: 0; }
.tin-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; padding-bottom: 16px; margin-bottom: 18px; border-bottom: 1px solid #d1d5db; }
.tin-co { display: flex; gap: 12px; align-items: flex-start; min-width: 0; }
.tin-co img { max-height: 52px; max-width: 150px; object-fit: contain; }
.tin-co-name { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.tin-co-sub { color: #64748b; font-size: 11px; white-space: pre-line; overflow-wrap: anywhere; }
.tin-title { text-align: right; flex-shrink: 0; }
.tin-title strong { display: block; font-size: 24px; letter-spacing: .04em; }
.tin-title span { color: #64748b; font-size: 12px; }
.tin-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; margin-bottom: 18px; }
.tin-meta h4 { margin: 0 0 4px; font-size: 10px; letter-spacing: .06em; color: #64748b; text-transform: uppercase; }
.tin-billto-name { font-weight: 700; font-size: 13px; }
.tin-billto-sub { white-space: pre-line; color: #374151; overflow-wrap: anywhere; }
.tin-pairs { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; justify-self: end; text-align: right; }
.tin-pairs dt { color: #64748b; }
.tin-pairs dd { margin: 0; font-weight: 600; }
.tin-sheet table { width: 100%; border-collapse: collapse; margin: 0; font-size: 12px; }
.tin-sheet th, .tin-sheet td { padding: 7px 8px; text-align: left; border: 0; border-bottom: 1px solid #e5e7eb; vertical-align: top; }
.tin-sheet th { font-size: 10.5px; color: #64748b; font-weight: 700; background: #f3f4f6; }
.tin-sheet .n { text-align: right; white-space: nowrap; }
.tin-totals { margin: 14px 0 0 auto; width: min(100%, 290px); }
.tin-totals div { display: flex; justify-content: space-between; gap: 12px; padding: 4px 8px; }
.tin-totals .tin-total { margin-top: 6px; padding: 10px 12px; border-radius: 6px; background: #f3f4f6; font-weight: 800; font-size: 15px; }
.tin-totals .tin-balance { font-weight: 800; font-size: 13px; border-top: 1px solid #9ca3af; margin-top: 6px; padding-top: 8px; }
.tin-pay { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; margin-top: 20px; padding-top: 14px; border-top: 1px solid #e5e7eb; }
.tin-pay h4, .tin-extra h4 { margin: 0 0 4px; font-size: 10px; letter-spacing: .06em; color: #64748b; text-transform: uppercase; }
.tin-pay-text { white-space: pre-line; overflow-wrap: anywhere; min-width: 0; }
.tin-pay-link { color: var(--accent); overflow-wrap: anywhere; }
.tin-qr { width: 84px; height: 84px; flex-shrink: 0; }
.tin-extra { margin-top: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.tin-totals-wrap { position: relative; }
.tin-stamp { position: absolute; top: 30px; left: 6%; transform: rotate(-14deg); border: 4px solid #16a34a; color: #16a34a;
  font-weight: 800; font-size: 34px; letter-spacing: .12em; padding: 4px 18px; border-radius: 8px; opacity: .85; pointer-events: none; }

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

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

@media (max-width: 520px) {
  .tin-sheet { padding: 16px; font-size: 11px; }
  .tin-t-modern .tin-head { margin: 0 -16px 16px; padding: 16px; }
  .tin-head { flex-direction: column; }
  .tin-title { text-align: left; }
  .tin-meta { grid-template-columns: 1fr; }
  .tin-pairs { justify-self: start; text-align: left; }
  .tin-side { position: static; }
  .tin-stamp { top: auto; bottom: -46px; left: 4px; font-size: 22px; }
}
