/* ===== Reset & Base ===== */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: #111827;
  background: #FFFFFF;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: #2563EB;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ===== Typography ===== */

h1 {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 1rem;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.75rem;
}

h3 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 0.5rem;
}

p {
  margin-bottom: 1rem;
}

/* ===== Layout ===== */

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
}

.editor-container {
  max-width: 900px;
  margin: 0 auto;
}

/* ===== Header / Nav ===== */

.site-header {
  border-bottom: 1px solid #E5E7EB;
  padding: 1rem 0;
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.site-logo {
  font-size: 1.25rem;
  font-weight: 800;
  color: #2563EB;
  text-decoration: none;
}

.site-logo:hover {
  text-decoration: none;
}

.site-nav {
  display: flex;
  gap: 1.5rem;
  list-style: none;
}

.site-nav a {
  color: #6B7280;
  font-size: 0.9rem;
  font-weight: 500;
}

.site-nav a:hover {
  color: #111827;
  text-decoration: none;
}

/* ===== Footer ===== */

.site-footer {
  border-top: 1px solid #E5E7EB;
  padding: 2rem 0;
  margin-top: 3rem;
  color: #6B7280;
  font-size: 0.875rem;
}

.site-footer .container {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
  list-style: none;
}

.footer-links a {
  color: #6B7280;
}

.footer-links a:hover {
  color: #111827;
}

/* ===== Ad & Affiliate Zones ===== */

.ad-zone {
  min-height: 0;
  overflow: hidden;
}

.ad-zone-leaderboard {
  text-align: center;
  margin: 1rem 0;
}

.ad-zone-sidebar {
  display: none;
}

.ad-zone-incontent {
  margin: 2rem 0;
}

.ad-zone-sticky {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  text-align: center;
  display: none;
}

.affiliate-zone {
  margin: 2rem 0;
}

/* ===== Buttons ===== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-primary {
  background: #2563EB;
  color: #FFFFFF;
}

.btn-primary:hover {
  background: #1D4ED8;
}

.btn-download {
  background: #059669;
  color: #FFFFFF;
  font-size: 1.125rem;
  padding: 1rem 2rem;
  border-radius: 0.5rem;
}

.btn-download:hover {
  background: #047857;
}

.btn-download:disabled {
  background: #9CA3AF;
  cursor: not-allowed;
}

/* ===== Forms ===== */

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.25rem;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #E5E7EB;
  border-radius: 0.375rem;
  font-size: 1rem;
  font-family: inherit;
  color: #111827;
  background: #FFFFFF;
  transition: border-color 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #2563EB;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea {
  resize: vertical;
  min-height: 4rem;
}

/* ===== Utility ===== */

.text-secondary {
  color: #6B7280;
}

.text-error {
  color: #DC2626;
}

.text-success {
  color: #059669;
}

.surface {
  background: #F9FAFB;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Invoice Editor ===== */

.invoice-editor {
  border: 1px solid #E5E7EB;
  border-radius: 0.5rem;
  background: #FFFFFF;
}

.editor-section {
  border: none;
  border-bottom: 1px solid #E5E7EB;
  padding: 1.5rem;
}

.editor-section:last-of-type {
  border-bottom: none;
}

.editor-section legend {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6B7280;
  margin-bottom: 1rem;
}

.field-group {
  margin-bottom: 0.75rem;
}

.field-group:last-child {
  margin-bottom: 0;
}

/* header layout */

.editor-row-header {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.editor-col-logo {
  flex: 0 0 auto;
  text-align: center;
}

.editor-col-business {
  flex: 1 1 220px;
  min-width: 0;
}

.editor-col-invoice {
  flex: 0 0 200px;
}

.editor-row-inline {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.editor-row-inline > .field-group {
  flex: 1 1 180px;
  min-width: 0;
}

/* logo upload */

.logo-upload {
  width: 120px;
  height: 80px;
  border: 2px dashed #E5E7EB;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.logo-upload:hover {
  border-color: #2563EB;
}

.logo-placeholder {
  color: #9CA3AF;
  font-size: 0.875rem;
}

.logo-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-remove {
  background: none;
  border: none;
  color: #DC2626;
  font-size: 0.75rem;
  cursor: pointer;
  margin-top: 0.25rem;
  padding: 0;
}

.logo-remove:hover {
  text-decoration: underline;
}

/* line items */

.line-item {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.375rem 0;
}

.line-item-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6B7280;
  border-bottom: 1px solid #E5E7EB;
  padding-bottom: 0.5rem;
  margin-bottom: 0.25rem;
}

.line-item .li-desc,
.line-item-header .li-desc {
  flex: 1 1 auto;
  min-width: 0;
}

.line-item .li-qty,
.line-item-header .li-qty {
  flex: 0 0 70px;
  text-align: right;
}

.line-item .li-rate,
.line-item-header .li-rate {
  flex: 0 0 100px;
  text-align: right;
}

.line-item .li-amount,
.line-item-header .li-amount {
  flex: 0 0 110px;
  text-align: right;
  font-weight: 600;
}

.line-item .li-actions,
.line-item-header .li-actions {
  flex: 0 0 32px;
  text-align: center;
}

.li-remove {
  background: none;
  border: none;
  color: #9CA3AF;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.li-remove:hover {
  color: #DC2626;
}

.line-item input[type="number"] {
  text-align: right;
}

.btn-add-row {
  margin-top: 0.75rem;
  background: none;
  border: 1px dashed #E5E7EB;
  color: #6B7280;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  cursor: pointer;
  width: 100%;
}

.btn-add-row:hover {
  border-color: #2563EB;
  color: #2563EB;
}

/* totals */

.editor-totals {
  border-bottom: none;
}

.totals-grid {
  max-width: 320px;
  margin-left: auto;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.375rem 0;
  gap: 1rem;
}

.totals-row label {
  margin-bottom: 0;
  flex-shrink: 0;
}

.totals-row input[type="number"] {
  width: 80px;
  text-align: right;
}

.totals-total {
  border-top: 2px solid #111827;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  font-size: 1.125rem;
  font-weight: 800;
}

.discount-input {
  display: flex;
  gap: 0.25rem;
}

.discount-input input {
  width: 80px;
  text-align: right;
}

.discount-input select {
  width: auto;
  min-width: 70px;
}

/* terms details */

.terms-details summary {
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  color: #6B7280;
  margin-bottom: 0.5rem;
}

.terms-details[open] summary {
  margin-bottom: 0.75rem;
}

/* download section */

.editor-download {
  padding: 1.5rem;
  text-align: center;
}

/* ===== Editor mobile overrides ===== */

@media (max-width: 640px) {
  .editor-row-header {
    flex-direction: column;
  }

  .editor-col-invoice {
    flex: 1 1 auto;
  }

  .line-item-header {
    display: none;
  }

  .line-item {
    flex-wrap: wrap;
  }

  .line-item .li-desc {
    flex: 1 1 100%;
  }

  .line-item .li-qty,
  .line-item .li-rate {
    flex: 1 1 calc(50% - 1.5rem);
  }

  .line-item .li-amount {
    flex: 1 1 auto;
  }

  .totals-grid {
    max-width: 100%;
  }
}

/* ===== Desktop layout with sidebar ===== */

@media (min-width: 768px) {
  .page-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
  }

  .page-layout .page-main {
    min-width: 0;
  }

  .ad-zone-sidebar {
    display: block;
  }
}

/* ===== Mobile ===== */

@media (max-width: 767px) {
  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .btn-download {
    width: 100%;
  }

  .ad-zone-sticky {
    display: block;
  }

  .site-header .container {
    justify-content: center;
  }

  .site-nav {
    gap: 1rem;
  }
}

/* ===== Template Grid ===== */

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  list-style: none;
  padding: 0;
  margin: 1rem 0 2rem;
}

.template-card {
  display: block;
  padding: 1.25rem 1.5rem;
  background: #F9FAFB;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  text-decoration: none;
  color: #111827;
  font-weight: 600;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.template-card:hover {
  border-color: #2563EB;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
  color: #2563EB;
}
