/* ============================================================
   The Client Billing Kit - Master Stylesheet
   Atelier Minimalist Design & Print-Tested Layout Engine
   ============================================================ */

:root {
  --bg-app: #f4f4f5;
  --bg-surface: #ffffff;
  --bg-sidebar: #ffffff;
  --text-main: #09090b;
  --text-muted: #71717a;
  --border-subtle: #e4e4e7;
  --border-focus: #18181b;
  --accent: #18181b;
  --accent-light: #f4f4f5;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-sheet: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* App Header */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.brand-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* App Container (2 Columns) */
.app-container {
  display: grid;
  grid-template-columns: 460px 1fr;
  min-height: calc(100vh - 57px);
}

/* Left Sidebar Editor */
.editor-sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  padding: 24px;
  overflow-y: auto;
  max-height: calc(100vh - 57px);
}

.editor-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
}

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

.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-group {
  margin-bottom: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-main);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
}

textarea {
  resize: vertical;
  min-height: 60px;
}

/* Line Items Editor */
.line-item-row {
  display: grid;
  grid-template-columns: 1fr 70px 90px 32px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.btn-remove-item {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.btn-remove-item:hover {
  color: #ef4444;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--bg-app);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

/* Preview Canvas (Right Column) */
.preview-canvas {
  padding: 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  max-height: calc(100vh - 57px);
}

/* The Printable Invoice Sheet */
.invoice-sheet {
  background: #ffffff;
  width: 100%;
  max-width: 800px;
  min-height: 1050px;
  padding: 56px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sheet);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
}

/* Invoice Header */
.invoice-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 40px;
}

.invoice-logo-container {
  max-width: 180px;
  max-height: 70px;
}

.invoice-logo-container img {
  max-width: 100%;
  max-height: 70px;
  object-fit: contain;
}

.invoice-header-title {
  text-align: right;
}

.invoice-title-text {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 6px;
}

.invoice-meta-number {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
}

/* Parties Info (From & Bill To) */
.invoice-parties-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-bottom: 36px;
}

.party-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.party-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.party-details {
  font-size: 13px;
  color: #3f3f46;
  white-space: pre-line;
}

/* Dates Bar */
.invoice-dates-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  margin-bottom: 36px;
}

.date-item-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.date-item-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

/* Table of Line Items */
.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 32px;
}

.invoice-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--text-main);
  padding: 10px 12px;
}

.invoice-table th.col-right,
.invoice-table td.col-right {
  text-align: right;
}

.invoice-table td {
  padding: 14px 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

.item-desc-cell {
  font-weight: 500;
}

.item-num-cell {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* Summary Totals Box */
.invoice-summary-box {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 40px;
}

.totals-table {
  width: 300px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  color: #3f3f46;
}

.totals-row.grand-total {
  border-top: 2px solid var(--text-main);
  margin-top: 6px;
  padding-top: 10px;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
}

.totals-row.balance-due {
  background: var(--accent-light);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  font-weight: 700;
  color: var(--text-main);
}

/* Payment Instructions & Notes */
.invoice-footer-notes {
  border-top: 1px solid var(--border-subtle);
  padding-top: 24px;
  font-size: 12px;
  color: var(--text-muted);
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

.notes-heading {
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
  text-transform: uppercase;
  font-size: 11px;
}

.notes-body {
  white-space: pre-line;
  line-height: 1.6;
}

/* Contextual Upsell Cards */
.upsell-card {
  background: #fdf4ff;
  border: 1px solid #f0abfc;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 20px;
}

.upsell-header {
  font-size: 13px;
  font-weight: 700;
  color: #86198f;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.upsell-body {
  font-size: 12px;
  color: #701a75;
  margin-bottom: 12px;
  line-height: 1.5;
}

/* Modal dialog for Backup/Restore */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: #fff;
  border-radius: var(--radius-md);
  padding: 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-sheet);
}

/* ============================================================
   PRINT STYLES ENGINE (A4 & US Letter Pixel-Perfect)
   ============================================================ */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .app-header,
  .editor-sidebar,
  .modal-overlay,
  .btn,
  .upsell-card,
  .no-print {
    display: none !important;
  }

  .app-container {
    display: block !important;
  }

  .preview-canvas {
    padding: 0 !important;
    display: block !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .invoice-sheet {
    max-width: 100% !important;
    min-height: auto !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
  }

  @page {
    size: auto;
    margin: 15mm 15mm 15mm 15mm;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* Responsive Breakpoints */
@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
  }
  .editor-sidebar {
    max-height: none;
  }
  .preview-canvas {
    padding: 20px;
    max-height: none;
  }
}

/* Post-Action Value Bridge Modal */
.post-action-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.post-action-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
}

.post-action-content {
  position: relative;
  background: #0f172a;
  border: 1px solid rgba(56, 189, 248, 0.3);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 40px rgba(56, 189, 248, 0.15);
  border-radius: 16px;
  max-width: 480px;
  width: 100%;
  padding: 32px;
  color: #f8fafc;
  animation: modalFadeIn 0.25s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.post-action-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.post-action-close:hover {
  color: #ffffff;
}

.post-action-badge {
  display: inline-block;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #10b981;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 14px;
}

.post-action-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
  margin-bottom: 12px;
  line-height: 1.3;
}

.post-action-desc {
  font-size: 14px;
  color: #94a3b8;
  line-height: 1.5;
  margin-bottom: 18px;
}

.post-action-features {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.paf-item {
  font-size: 13px;
  color: #cbd5e1;
  font-weight: 500;
}
