/*
 * Billtoolbox Invoice Generator — styles use the brand constants from CLAUDE.md §6.
 * Every rule is scoped under #invoice-app (ID selector). This isn't just
 * hygiene — Astra's theme CSS ships selectors like `.entry-content button`
 * and `.entry-content h3` (class+element, specificity 0,1,1) that otherwise
 * silently override plain class selectors here (0,1,0): the download button
 * rendered theme-black instead of brand-orange, and headings got
 * text-transform:capitalize forced on them, until this was scoped by ID.
 */

#invoice-app {
  --btb-navy: #1e3a5f;
  --btb-navy-dark: #16293f;
  --btb-orange: #FF9900;
  --btb-text: #374151;
  --btb-heading: #111827;
  --btb-border: #e5e7eb;
  --btb-border-hover: #cbd5e1;
  --btb-row-alt: #f9fafb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--btb-text);
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  box-sizing: border-box;
}
#invoice-app *, #invoice-app *::before, #invoice-app *::after { box-sizing: border-box; }
/* Several elements below set `display` on classes (e.g. .btb-inv-field,
   .btb-inv-linkbtn) with higher specificity than the browser's default
   `[hidden]{display:none}` UA rule, which silently defeated the `hidden`
   attribute on #logoRemoveBtn and #dueDateField — both rendered visible when
   they shouldn't have. This restores `hidden` as an unconditional override. */
#invoice-app [hidden] { display: none !important; }

#invoice-app .btb-inv-shell {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 28px;
  align-items: start;
}
@media (max-width: 860px) {
  #invoice-app .btb-inv-shell { grid-template-columns: 1fr; }
}

#invoice-app .btb-inv-h1 { font-size: 2rem; font-weight: 800; color: var(--btb-heading); margin: 0 0 0.25rem; text-transform: none; }
#invoice-app .btb-inv-sub { font-size: 0.95rem; line-height: 1.6; margin: 0 0 1.25rem; }
#invoice-app .btb-inv-sub a { color: var(--btb-navy); }
#invoice-app .btb-inv-h2 { font-size: 1.1rem; font-weight: 700; color: var(--btb-heading); margin: 0 0 1rem; text-transform: none; }

#invoice-app .btb-inv-card {
  border: 1px solid var(--btb-border);
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin-bottom: 20px;
  background: #fff;
}

#invoice-app .btb-inv-field {
  display: block;
  margin-bottom: 16px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--btb-heading);
}
#invoice-app .btb-inv-field span { display: block; margin-bottom: 6px; }
#invoice-app .btb-inv-field input,
#invoice-app .btb-inv-field select,
#invoice-app .btb-inv-field textarea {
  width: 100%;
  font: inherit;
  font-weight: 400;
  font-size: 0.95rem;
  color: var(--btb-text);
  border: 1px solid var(--btb-border);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
#invoice-app .btb-inv-field input:hover,
#invoice-app .btb-inv-field select:hover,
#invoice-app .btb-inv-field textarea:hover {
  border-color: var(--btb-border-hover);
}
#invoice-app .btb-inv-field input:focus,
#invoice-app .btb-inv-field select:focus,
#invoice-app .btb-inv-field textarea:focus {
  outline: none;
  border-color: var(--btb-navy);
  box-shadow: 0 0 0 3px rgba(30,58,95,0.12);
}
#invoice-app .btb-inv-field textarea { resize: vertical; }
#invoice-app .btb-inv-card > .btb-inv-field:last-child,
#invoice-app .btb-inv-card > .btb-inv-grid2:last-child { margin-bottom: 0; }

#invoice-app .btb-inv-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 480px) { #invoice-app .btb-inv-grid2 { grid-template-columns: 1fr; } }

#invoice-app .btb-inv-logo-row { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
#invoice-app .btb-inv-logo-preview {
  width: 72px; height: 72px; border-radius: 8px; border: 1.5px dashed var(--btb-border);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; overflow: hidden;
  background: #f9fafb; color: #9ca3af; font-size: 0.72rem; font-weight: 600; cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
#invoice-app .btb-inv-logo-preview:hover,
#invoice-app .btb-inv-logo-preview.is-dragover {
  border-color: var(--btb-navy); background: #eef2f7; color: var(--btb-navy);
}
#invoice-app .btb-inv-logo-preview img { width: 100%; height: 100%; object-fit: contain; }
#invoice-app .btb-inv-logo-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
#invoice-app .btb-inv-filebtn {
  display: inline-block; background: var(--btb-navy); color: #fff; font-weight: 600;
  font-size: 0.85rem; padding: 9px 16px; border-radius: 6px; cursor: pointer; text-transform: none;
  transition: background-color .15s ease;
}
#invoice-app .btb-inv-filebtn:hover { background: var(--btb-navy-dark); }
#invoice-app .btb-inv-linkbtn {
  display: inline-block; background: none; border: none; color: var(--btb-navy);
  font-size: 0.82rem; font-weight: 600; text-decoration: underline; cursor: pointer;
  padding: 6px 0; text-transform: none;
}
#invoice-app .btb-inv-linkbtn:hover { color: #dc2626; }
#invoice-app .btb-inv-hint { font-size: 0.78rem; color: #6b7280; font-weight: 400; margin: 0 0 20px; }

#invoice-app .btb-inv-lineitems-head {
  display: grid;
  grid-template-columns: 2.4fr 0.6fr 0.9fr 0.6fr 0.8fr 28px;
  gap: 8px;
  padding: 0 8px 6px;
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: #9ca3af;
}
#invoice-app .btb-inv-lineitems-head span:not(:first-child) { text-align: right; }
@media (max-width: 640px) { #invoice-app .btb-inv-lineitems-head { display: none; } }

#invoice-app .btb-inv-lineitems { display: flex; flex-direction: column; gap: 10px; }
#invoice-app .btb-inv-row {
  display: grid;
  grid-template-columns: 2.4fr 0.6fr 0.9fr 0.6fr 0.8fr 28px;
  gap: 8px;
  align-items: center;
}
@media (max-width: 640px) {
  #invoice-app .btb-inv-row {
    grid-template-columns: 1fr 28px;
    grid-template-areas: "desc remove" "qty qty" "price price" "tax tax" "total total";
    gap: 6px 8px;
    padding: 10px; border: 1px solid var(--btb-border); border-radius: 8px;
  }
  #invoice-app .btb-inv-row .li-desc { grid-area: desc; }
  #invoice-app .btb-inv-row .li-remove { grid-area: remove; }
  #invoice-app .btb-inv-row .li-qty { grid-area: qty; }
  #invoice-app .btb-inv-row .li-price { grid-area: price; }
  #invoice-app .btb-inv-row .li-tax { grid-area: tax; }
  #invoice-app .btb-inv-row .li-total { grid-area: total; text-align: right; padding-top: 4px; }
}
#invoice-app .btb-inv-row input {
  width: 100%; font-size: 0.88rem; border: 1px solid var(--btb-border); border-radius: 6px;
  padding: 7px 8px; font-family: inherit; transition: border-color .15s ease, box-shadow .15s ease;
}
#invoice-app .btb-inv-row input:hover { border-color: var(--btb-border-hover); }
#invoice-app .btb-inv-row input:focus {
  outline: none; border-color: var(--btb-navy); box-shadow: 0 0 0 3px rgba(30,58,95,0.12);
}
#invoice-app .li-total { font-weight: 700; color: var(--btb-heading); font-size: 0.88rem; text-align: right; }
#invoice-app .li-remove {
  background: none; border: none; color: #9ca3af; cursor: pointer; font-size: 0.85rem;
  width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  transition: background-color .15s ease, color .15s ease;
}
#invoice-app .li-remove:hover { color: #dc2626; background: #fee2e2; }

#invoice-app .btb-inv-addrow {
  margin-top: 12px; background: none; border: 1px dashed var(--btb-navy); color: var(--btb-navy);
  font-weight: 600; font-size: 0.85rem; padding: 9px 14px; border-radius: 6px; cursor: pointer; width: 100%;
  text-transform: none; transition: background-color .15s ease;
}
#invoice-app .btb-inv-addrow:hover { background: #f0f4f8; }

#invoice-app .btb-inv-discount-row { display: flex; gap: 8px; }
#invoice-app .btb-inv-discount-row input { flex: 1; }
#invoice-app .btb-inv-discount-row select { width: 90px; }

#invoice-app .btb-inv-download {
  display: block; width: 100%; background: var(--btb-orange); color: #fff; font-weight: 700;
  font-size: 1.05rem; padding: 16px; border: none; border-radius: 8px; cursor: pointer; margin-top: 8px;
  text-transform: none; transition: opacity .15s ease, transform .1s ease;
}
#invoice-app .btb-inv-download:hover { opacity: 0.92; }
#invoice-app .btb-inv-download:active { transform: translateY(1px); }
#invoice-app > .btb-inv-shell > .btb-inv-form > .btb-inv-linkbtn { display: block; text-align: center; margin: 12px auto 0; }

/* ---- Preview column ---- */
#invoice-app .btb-inv-previewcol { position: relative; }
#invoice-app .btb-inv-preview-sticky { position: sticky; top: 16px; }

#invoice-app .btb-inv-preview {
  border: 1px solid var(--btb-border);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  background: #fff;
  overflow: hidden;
  font-size: 0.82rem;
}
#invoice-app .btb-inv-preview-band {
  background: var(--btb-navy); color: #fff; padding: 20px 22px;
  display: flex; align-items: center; justify-content: space-between;
}
#invoice-app .btb-inv-preview-logo { max-height: 40px; max-width: 140px; }
#invoice-app .btb-inv-preview-title { font-size: 1.4rem; font-weight: 800; letter-spacing: 0.05em; }

#invoice-app .btb-inv-preview-meta {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; padding: 18px 22px;
  border-bottom: 1px solid var(--btb-border);
}
@media (max-width: 480px) { #invoice-app .btb-inv-preview-meta { grid-template-columns: 1fr; } }
#invoice-app .btb-inv-preview-label {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: #9ca3af; margin-bottom: 4px;
}
#invoice-app .btb-inv-preview-block { white-space: pre-line; line-height: 1.5; color: var(--btb-text); }

#invoice-app .btb-inv-preview-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
#invoice-app .btb-inv-preview-table thead tr { background: var(--btb-navy); color: #fff; }
#invoice-app .btb-inv-preview-table th, #invoice-app .btb-inv-preview-table td { padding: 9px 12px; text-align: left; border: 1px solid var(--btb-border); }
#invoice-app .btb-inv-preview-table th:nth-child(2), #invoice-app .btb-inv-preview-table td:nth-child(2),
#invoice-app .btb-inv-preview-table th:nth-child(3), #invoice-app .btb-inv-preview-table td:nth-child(3),
#invoice-app .btb-inv-preview-table th:nth-child(4), #invoice-app .btb-inv-preview-table td:nth-child(4),
#invoice-app .btb-inv-preview-table th:nth-child(5), #invoice-app .btb-inv-preview-table td:nth-child(5) { text-align: right; }
#invoice-app .btb-inv-preview-table tbody tr:nth-child(odd) { background: #fff; }
#invoice-app .btb-inv-preview-table tbody tr:nth-child(even) { background: var(--btb-row-alt); }

#invoice-app .btb-inv-preview-totals { padding: 16px 22px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#invoice-app .btb-inv-preview-totals .row { display: flex; justify-content: space-between; width: 220px; max-width: 100%; font-size: 0.85rem; }
#invoice-app .btb-inv-preview-totals .row.grand { font-size: 1.05rem; font-weight: 800; color: var(--btb-navy); border-top: 1px solid var(--btb-border); padding-top: 6px; margin-top: 4px; }

#invoice-app .btb-inv-preview-notes { padding: 16px 22px; border-top: 1px solid var(--btb-border); white-space: pre-line; color: var(--btb-text); font-size: 0.82rem; }

/* ---- Affiliate / links cards ---- */
#invoice-app .btb-inv-affiliate-card, #invoice-app .btb-inv-links-card {
  border: 1px solid var(--btb-border); border-radius: 10px; padding: 18px 20px; margin-top: 18px; background: #fff;
}
#invoice-app .btb-inv-affiliate-card h3, #invoice-app .btb-inv-links-card h3 { font-size: 1rem; font-weight: 700; color: var(--btb-heading); margin: 0 0 8px; text-transform: none; }
#invoice-app .btb-inv-affiliate-card p { font-size: 0.85rem; line-height: 1.6; margin: 0 0 12px; }
#invoice-app .btb-inv-affiliate-cta {
  display: inline-block; background: var(--btb-navy); color: #fff; font-weight: 700; font-size: 0.85rem;
  padding: 10px 20px; border-radius: 6px; text-decoration: none; text-transform: none;
  transition: background-color .15s ease;
}
#invoice-app .btb-inv-affiliate-cta:hover { background: var(--btb-navy-dark); }
#invoice-app .btb-inv-links-card ul { margin: 0; padding-left: 18px; }
#invoice-app .btb-inv-links-card li { font-size: 0.85rem; margin-bottom: 6px; }
#invoice-app .btb-inv-links-card a { color: var(--btb-navy); }
