/* ============================================================
   Invoice.page — styles.css
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
  --accent: #6366f1;
  --accent-dark: #4f46e5;
  --accent-light: #e0e7ff;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-on-accent: #ffffff;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);
  --shadow-paper: 0 8px 32px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.06);

  --radius: 8px;
  --radius-lg: 12px;
  --radius-sm: 5px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;

  --header-height: 60px;
  --form-panel-width: 440px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Header
   ============================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.app-header-inner {
  max-width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-decoration: none;
  user-select: none;
}

.app-logo svg {
  flex-shrink: 0;
}

.app-logo span {
  color: var(--text);
}

.app-logo strong {
  color: var(--accent);
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--border-light);
  color: var(--text);
  border-color: var(--border);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-add-item {
  margin-top: 0.75rem;
  width: 100%;
  justify-content: center;
  border-style: dashed;
  color: var(--text-secondary);
}

.btn-add-item:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* ============================================================
   Main Layout
   ============================================================ */
.app-main {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* ============================================================
   Form Panel
   ============================================================ */
.form-panel {
  width: var(--form-panel-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 1;
}

.form-panel-inner {
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Form Sections */
.form-section {
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border-light);
}

.form-section:last-child {
  border-bottom: none;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.875rem;
}

/* Form Groups */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  flex: 1;
}

.form-row {
  display: flex;
  gap: 0.75rem;
}

.form-row.align-end {
  align-items: flex-end;
}

label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.optional {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
}

.form-control {
  font-family: var(--font);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.625rem;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  resize: none;
  line-height: 1.5;
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  padding-right: 2rem;
  cursor: pointer;
}

/* Color Swatches */
.color-swatches {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.25rem 0;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  padding: 0;
  outline: none;
}

.swatch:hover {
  transform: scale(1.15);
}

.swatch.active {
  border-color: white;
  box-shadow: 0 0 0 2.5px var(--accent), 0 2px 6px rgba(0,0,0,0.2);
}

/* Logo Upload */
.logo-upload-area {
  position: relative;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
  min-height: 80px;
  cursor: pointer;
}

.logo-upload-area:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.logo-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.logo-upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 1.25rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
  min-height: 80px;
  pointer-events: none;
}

.logo-upload-placeholder svg {
  color: var(--text-muted);
}

.logo-preview-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  position: relative;
  min-height: 80px;
}

.logo-preview-wrap img {
  max-height: 64px;
  max-width: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.logo-remove {
  position: absolute;
  top: 0.375rem;
  right: 0.375rem;
  width: 22px;
  height: 22px;
  background: rgba(0,0,0,0.5);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  transition: background 0.12s;
}

.logo-remove:hover {
  background: rgba(244,63,94,0.9);
}

/* Line Items Header */
.line-items-header {
  display: grid;
  grid-template-columns: 1fr 60px 80px 70px 28px;
  gap: 0.5rem;
  padding: 0.25rem 0;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* Line Item Rows */
.line-item-row {
  display: grid;
  grid-template-columns: 1fr 60px 80px 70px 28px;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.line-item-row .form-control {
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
}

.li-total-display {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}

.btn-remove-item {
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1.5px solid transparent;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  transition: all 0.12s;
  flex-shrink: 0;
}

.btn-remove-item:hover {
  background: #fef2f2;
  border-color: #fecaca;
  color: #ef4444;
}

/* Form Totals */
.form-totals .form-row {
  justify-content: flex-end;
}

.form-totals .form-group {
  max-width: 160px;
}

/* ============================================================
   Preview Panel
   ============================================================ */
.preview-panel {
  flex: 1;
  overflow-y: auto;
  background: #dde3ec;
  display: flex;
  flex-direction: column;
}

.preview-scroll {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1.5rem;
  min-height: 100%;
}

/* Invoice Paper */
.invoice-paper {
  width: 100%;
  max-width: 720px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-paper);
  padding: 2.5rem 2.75rem;
  font-family: var(--font);
  color: var(--text);
  position: relative;
  overflow: hidden;
}

/* Invoice Header */
.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.inv-from {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  flex: 1;
}

.inv-logo {
  flex-shrink: 0;
}

.inv-logo img {
  max-height: 56px;
  max-width: 120px;
  object-fit: contain;
  display: block;
}

.inv-from-details {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.inv-business-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.inv-from-address,
.inv-from-contact {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
}

.inv-title-block {
  text-align: right;
  flex-shrink: 0;
}

.inv-title {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent);
  line-height: 1;
}

.inv-number {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  font-weight: 500;
}

/* Accent Bar */
.inv-accent-bar {
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  margin: 1.25rem 0;
}

/* Meta Row */
.inv-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1.75rem;
}

.inv-bill-to {
  flex: 1;
}

.inv-meta-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}

.inv-client-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.inv-client-address,
.inv-client-email {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
}

.inv-meta-details {
  flex-shrink: 0;
}

.inv-details-table {
  border-collapse: collapse;
}

.inv-details-table td {
  padding: 0.2rem 0;
  font-size: 0.8125rem;
  vertical-align: top;
}

.detail-label {
  color: var(--text-muted);
  font-weight: 500;
  padding-right: 1.25rem;
  white-space: nowrap;
}

.detail-value {
  color: var(--text);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

/* Line Items Table */
.inv-items-wrap {
  margin-bottom: 1.25rem;
  overflow: hidden;
  border-radius: var(--radius-sm);
}

.inv-items-table {
  width: 100%;
  border-collapse: collapse;
}

.inv-items-table thead tr {
  background: var(--accent);
}

.inv-items-table thead th {
  padding: 0.6rem 0.875rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-on-accent);
  text-align: left;
}

.inv-items-table thead th:last-child,
.inv-items-table thead th.col-qty,
.inv-items-table thead th.col-price,
.inv-items-table thead th.col-total {
  text-align: right;
}

.inv-items-table tbody tr {
  border-bottom: 1px solid var(--border-light);
}

.inv-items-table tbody tr:last-child {
  border-bottom: none;
}

.inv-items-table tbody tr:nth-child(even) {
  background: #fafbfc;
}

.inv-items-table tbody td {
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  color: var(--text);
  vertical-align: top;
}

.inv-items-table tbody td.col-qty,
.inv-items-table tbody td.col-price,
.inv-items-table tbody td.col-total {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.inv-items-table tbody td.col-desc {
  word-break: break-word;
}

.col-qty { width: 60px; }
.col-price { width: 100px; }
.col-total { width: 100px; }

/* Totals */
.inv-totals-wrap {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1.5rem;
}

.inv-totals-table {
  border-collapse: collapse;
  min-width: 240px;
}

.inv-totals-table td {
  padding: 0.35rem 0.5rem;
  font-size: 0.875rem;
  vertical-align: middle;
}

.totals-label {
  color: var(--text-secondary);
  font-weight: 500;
  padding-right: 1.5rem;
  text-align: left;
}

.totals-value {
  color: var(--text);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.totals-grand td {
  border-top: 2px solid var(--accent);
  padding-top: 0.5rem;
  margin-top: 0.25rem;
}

.totals-grand .totals-label {
  color: var(--text);
  font-weight: 700;
  font-size: 0.9375rem;
}

.totals-grand .totals-value {
  color: var(--accent);
  font-size: 1.0625rem;
  font-weight: 800;
}

/* Notes */
.inv-notes {
  background: var(--border-light);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.875rem 1rem;
  margin-bottom: 1.5rem;
}

.inv-notes-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}

.inv-notes-text {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
}

/* Footer */
.inv-footer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
  padding-top: 1rem;
  margin-top: 0.5rem;
}

/* ============================================================
   Upsell Toast
   ============================================================ */
.upsell-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 500;
  max-width: 400px;
  width: calc(100vw - 3rem);
  animation: slide-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.upsell-toast-inner {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  padding: 1rem 1.125rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  position: relative;
}

.upsell-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  line-height: 1;
  margin-top: 2px;
}

.upsell-content {
  flex: 1;
  min-width: 0;
}

.upsell-content strong {
  display: block;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.upsell-content p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.upsell-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-top: 0.125rem;
}

.upsell-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.12s, background 0.12s;
  padding: 0;
}

.upsell-close:hover {
  color: var(--text);
  background: var(--border-light);
}

/* ============================================================
   Responsive — Mobile
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --form-panel-width: 100%;
    --header-height: 56px;
  }

  .app-main {
    flex-direction: column;
    overflow: visible;
    min-height: auto;
  }

  .form-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible;
    box-shadow: none;
  }

  .preview-panel {
    min-height: 500px;
  }

  .preview-scroll {
    padding: 1rem 0.75rem;
  }

  .invoice-paper {
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius);
  }

  .inv-header {
    flex-direction: column;
    gap: 0.75rem;
  }

  .inv-title-block {
    text-align: left;
  }

  .inv-meta-row {
    flex-direction: column;
    gap: 1rem;
  }

  .line-items-header {
    display: none;
  }

  .line-item-row {
    grid-template-columns: 1fr 48px 70px 60px 28px;
    gap: 0.375rem;
  }

  .app-header-actions .btn-ghost {
    display: none;
  }

  .upsell-toast {
    bottom: 1rem;
    right: 1rem;
    left: 1rem;
    width: auto;
    max-width: none;
  }

  .upsell-toast-inner {
    flex-wrap: wrap;
  }

  .upsell-actions {
    width: 100%;
    margin-top: 0.5rem;
  }
}

/* ============================================================
   Utility / Accessibility
   ============================================================ */
.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;
}

/* Smooth scrollbars */
.form-panel,
.preview-panel {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.form-panel::-webkit-scrollbar,
.preview-panel::-webkit-scrollbar {
  width: 5px;
}

.form-panel::-webkit-scrollbar-track,
.preview-panel::-webkit-scrollbar-track {
  background: transparent;
}

.form-panel::-webkit-scrollbar-thumb,
.preview-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
