/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand: #2563eb;
  --brand-light: #EEF2FF;
  --brand-dark: #3730A3;
  --text: #111827;
  --text-muted: #64748b;
  --border: #0f172a;
  --bg: #F9FAFB;
  --white: #FFFFFF;
  --danger: #EF4444;
  --success: #059669;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.10);
}

.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;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ===== HEADER ===== */
.site-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--brand);
  text-decoration: none;
}
.header-nav { display: flex; gap: 8px; }
.badge-free {
  background: var(--brand-light);
  color: var(--brand);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
}

/* ===== APP LAYOUT ===== */
.app-layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 24px;
  min-height: calc(100vh - 61px - 72px);
}

@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; padding: 16px; }
}

/* ===== FORM PANEL ===== */
.form-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.form-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.full-span { grid-column: 1 / -1; }

.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-group label { font-size: 12px; font-weight: 500; color: var(--text-muted); }

.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  font-family: inherit;
}
.input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.textarea { resize: vertical; min-height: 80px; }
select.input { cursor: pointer; }

/* ===== LOGO UPLOAD ===== */
.logo-upload-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.logo-upload-btn {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  background: var(--brand-light);
  color: var(--brand);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px dashed var(--brand);
  transition: background .15s;
}
.logo-upload-btn:hover { background: #E0E7FF; }
#logoPreviewThumb { max-height: 36px; border-radius: 4px; }

/* ===== ITEMS TABLE ===== */
.items-header {
  display: grid;
  grid-template-columns: 1fr 60px 90px 90px 32px;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding: 0 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.item-row {
  display: grid;
  grid-template-columns: 1fr 60px 90px 90px 32px;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.item-amount {
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  text-align: right;
}
.btn-del-item {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}
.btn-del-item:hover { background: #FEE2E2; color: var(--danger); }

.btn-add-item {
  margin-top: 8px;
  background: none;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
  padding: 8px;
  width: 100%;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn-add-item:hover { border-color: var(--brand); background: var(--brand-light); }

/* ===== TOTALS ===== */
.totals-section { }
.totals-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ===== ACTIONS ===== */
.action-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-secondary {
  background: var(--white);
  color: var(--brand);
  border: 1.5px solid var(--brand);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--brand-light); }
.btn-ghost {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s;
  font-family: inherit;
}
.btn-ghost:hover { border-color: var(--text-muted); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ===== PREVIEW PANEL ===== */
.preview-panel {
  position: sticky;
  top: 85px;
  align-self: start;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}
.preview-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ===== INVOICE PREVIEW ===== */
.invoice-preview {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  min-height: 600px;
}

.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 36px;
  gap: 20px;
}
.inv-logo { max-height: 64px; max-width: 180px; object-fit: contain; }
.inv-logo-placeholder {
  width: 64px;
  height: 64px;
  background: var(--brand-light);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
  font-size: 22px;
  font-weight: 700;
}
.inv-title-block { text-align: right; }
.inv-title {
  font-size: 32px;
  font-weight: 800;
  color: var(--brand);
  letter-spacing: -.02em;
  line-height: 1;
}
.inv-number { font-size: 14px; color: var(--text-muted); margin-top: 4px; }

.inv-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}
.inv-party-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--brand);
  margin-bottom: 6px;
}
.inv-party-name { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.inv-party-detail { font-size: 13px; color: var(--text-muted); line-height: 1.6; }

.inv-dates {
  display: flex;
  gap: 24px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.inv-date-item { }
.inv-date-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }
.inv-date-val { font-size: 14px; font-weight: 600; }

/* Items table */
.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.inv-table th {
  background: var(--brand);
  color: white;
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.inv-table th:last-child, .inv-table td:last-child { text-align: right; }
.inv-table th:nth-child(2), .inv-table th:nth-child(3),
.inv-table td:nth-child(2), .inv-table td:nth-child(3) { text-align: center; }
.inv-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: top;
}
.inv-table tr:last-child td { border-bottom: none; }
.inv-table tbody tr:hover { background: var(--bg); }

/* Totals */
.inv-totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  margin-bottom: 28px;
}
.inv-total-row {
  display: flex;
  justify-content: flex-end;
  gap: 40px;
  width: 260px;
  font-size: 13px;
}
.inv-total-row.subtotal { color: var(--text-muted); }
.inv-total-row.discount { color: var(--success); }
.inv-total-row.tax { color: var(--text-muted); }
.inv-total-row.total {
  font-size: 16px;
  font-weight: 800;
  border-top: 2px solid var(--text);
  padding-top: 8px;
  margin-top: 4px;
}
.inv-total-label { }
.inv-total-val { font-weight: 600; text-align: right; min-width: 90px; }

.inv-notes {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 8px;
}
.inv-notes-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.inv-notes-text { font-size: 13px; color: var(--text-muted); white-space: pre-wrap; }

.inv-footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 11px;
  color: #334155;
}

/* ===== FOOTER ===== */
.site-footer {
  background: var(--white);
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 20px 24px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.8;
}
.footer-small { font-size: 11px; color: #5b6878; }

/* ===== AD BANNER ===== */
.ad-banner {
  max-width: 1400px;
  margin: 0 auto 16px;
  padding: 0 24px;
}

/* ===== PRINT ===== */
@media print {
  .site-header, .form-panel, .preview-label, .site-footer { display: none !important; }
  .app-layout { display: block; padding: 0; max-width: none; }
  .preview-panel { position: static; max-height: none; overflow: visible; }
  .invoice-preview { border: none; box-shadow: none; padding: 20px; }
}
