/* ============================================================
   BuildInvoice — Design System
   Premium dark theme with indigo/purple accent gradient
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

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

/* ── Tokens ── */
:root {
  --bg-primary:    #0a0a14;
  --bg-secondary:  #12121f;
  --bg-card:       #1a1a2e;
  --bg-input:      #0f0f1a;
  --border:        rgba(255,255,255,0.08);
  --border-focus:  rgba(79,70,229,0.5);
  --text-primary:  #f1f1f4;
  --text-secondary:#9ca3af;
  --text-muted:    #6b7280;
  --accent:        #4F46E5;
  --accent-light:  #818cf8;
  --accent-glow:   rgba(79,70,229,0.15);
  --gradient:      linear-gradient(135deg, #4F46E5, #7C3AED);
  --success:       #10b981;
  --danger:        #ef4444;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 4px 24px rgba(0,0,0,0.3);
  --transition:    0.2s ease;
}

/* ── Base ── */
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── Navigation ── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,20,0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
}
.navbar-brand {
  font-size: 1.3rem; font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  text-decoration: none;
}
.navbar-links { display: flex; gap: 1.5rem; align-items: center; }
.navbar-links a {
  color: var(--text-secondary); text-decoration: none; font-size: 0.9rem; font-weight: 500;
  transition: color var(--transition);
}
.navbar-links a:hover { color: var(--text-primary); }

/* ── Hero Banner ── */
.hero-banner {
  text-align: center; padding: 2.5rem 1.5rem 1.5rem;
  background: linear-gradient(180deg, rgba(79,70,229,0.08) 0%, transparent 100%);
}
.hero-banner h1 {
  font-size: 2.2rem; font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}
.hero-banner p { color: var(--text-secondary); font-size: 1.05rem; max-width: 560px; margin: 0 auto; }

/* ── Main Layout ── */
.app-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 2rem 4rem;
}

/* ── Form Panel ── */
.form-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
}

.form-section { margin-bottom: 1.5rem; }
.form-section-header {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 1rem; padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.form-section-header h3 {
  font-size: 0.85rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--accent-light);
}
.form-section-icon {
  width: 20px; height: 20px; opacity: 0.7;
}

/* ── Form Fields ── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 0.75rem; }
.form-row.full { grid-template-columns: 1fr; }

.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label {
  font-size: 0.75rem; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.form-group input,
.form-group textarea,
.form-group select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
  color: var(--text-primary);
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text-muted); }

/* ── Color Picker Row ── */
.color-row { display: flex; align-items: center; gap: 0.75rem; }
.color-row input[type="color"] {
  width: 40px; height: 36px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; padding: 2px;
  background: var(--bg-input);
}

/* ── Line Items ── */
.line-items-header {
  display: grid; grid-template-columns: 1fr 70px 100px 100px 36px;
  gap: 0.5rem; padding-bottom: 0.5rem;
}
.line-items-header span {
  font-size: 0.7rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}

.line-item-row {
  display: grid; grid-template-columns: 1fr 70px 100px 100px 36px;
  gap: 0.5rem; margin-bottom: 0.5rem; align-items: center;
  animation: slideIn 0.2s ease;
}
.line-item-row input {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.5rem 0.6rem;
  font-size: 0.85rem; color: var(--text-primary); font-family: inherit;
  outline: none; transition: border-color var(--transition);
}
.line-item-row input:focus { border-color: var(--border-focus); }

.line-item-amount {
  font-size: 0.85rem; font-weight: 600; color: var(--text-primary);
  text-align: right; padding-right: 0.3rem;
}

.btn-remove-item {
  background: none; border: 1px solid rgba(239,68,68,0.3); border-radius: var(--radius-sm);
  color: var(--danger); cursor: pointer; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
  transition: all var(--transition);
}
.btn-remove-item:hover { background: rgba(239,68,68,0.15); border-color: var(--danger); }

.btn-add-item {
  background: var(--accent-glow); border: 1px dashed var(--accent);
  border-radius: var(--radius-sm); padding: 0.5rem;
  color: var(--accent-light); cursor: pointer; font-size: 0.85rem; font-weight: 600;
  width: 100%; margin-top: 0.5rem; font-family: inherit;
  transition: all var(--transition);
}
.btn-add-item:hover { background: rgba(79,70,229,0.25); }

/* ── Totals Row ── */
.totals-display {
  background: rgba(79,70,229,0.06); border: 1px solid rgba(79,70,229,0.15);
  border-radius: var(--radius-sm); padding: 1rem; margin-top: 1rem;
}
.totals-row {
  display: flex; justify-content: space-between; padding: 0.25rem 0;
  font-size: 0.9rem; color: var(--text-secondary);
}
.totals-row.total {
  border-top: 2px solid var(--accent); padding-top: 0.5rem; margin-top: 0.5rem;
  font-size: 1.1rem; font-weight: 700; color: var(--text-primary);
}

/* ── Download Button ── */
.btn-download {
  width: 100%; padding: 0.9rem; margin-top: 1.5rem;
  background: var(--gradient); border: none; border-radius: var(--radius-sm);
  color: #fff; font-size: 1rem; font-weight: 700; font-family: inherit;
  cursor: pointer; transition: all var(--transition);
  box-shadow: 0 4px 16px rgba(79,70,229,0.3);
}
.btn-download:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(79,70,229,0.4);
}
.btn-download:active { transform: translateY(0); }
.btn-download:disabled {
  opacity: 0.5; cursor: not-allowed; transform: none;
}
.btn-download .spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.6s linear infinite;
  vertical-align: middle; margin-right: 0.5rem;
}

/* ── Preview Panel ── */
.preview-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: sticky; top: 80px;
  max-height: calc(100vh - 200px);
}
.preview-header {
  padding: 0.75rem 1.25rem;
  background: rgba(79,70,229,0.08);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.preview-header h3 {
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--accent-light);
}
.preview-body {
  padding: 2rem;
  background: #ffffff;
  color: #1a1a1a;
  min-height: 600px;
  font-family: 'Inter', sans-serif;
  overflow-y: auto;
  max-height: calc(100vh - 260px);
}

/* ── Invoice Preview Styles (white background) ── */
.inv-header { display: flex; justify-content: space-between; margin-bottom: 1.5rem; }
.inv-company-name { font-size: 1.4rem; font-weight: 800; }
.inv-company-detail { font-size: 0.75rem; color: #666; margin-top: 2px; }
.inv-title { font-size: 1.8rem; font-weight: 800; color: #E5E7EB; text-align: right; }
.inv-number { font-size: 1rem; font-weight: 700; text-align: right; margin-top: 4px; }
.inv-date { font-size: 0.75rem; color: #666; text-align: right; }
.inv-divider { border: none; border-top: 1px solid #E5E7EB; margin: 1rem 0; }
.inv-bill-to-label { font-size: 0.65rem; font-weight: 700; color: #999; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.inv-client-name { font-size: 1rem; font-weight: 700; color: #1a1a1a; }
.inv-client-detail { font-size: 0.75rem; color: #666; }

.inv-table { width: 100%; border-collapse: collapse; margin: 1.25rem 0; font-size: 0.8rem; }
.inv-table th {
  padding: 0.5rem 0.6rem; text-align: left; font-size: 0.65rem;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: #fff;
}
.inv-table th:nth-child(2),
.inv-table th:nth-child(3),
.inv-table th:nth-child(4) { text-align: right; }
.inv-table td { padding: 0.5rem 0.6rem; color: #1a1a1a; }
.inv-table td:nth-child(2),
.inv-table td:nth-child(3),
.inv-table td:nth-child(4) { text-align: right; }
.inv-table tbody tr:nth-child(even) { background: #FAFAFA; }

.inv-totals { display: flex; justify-content: flex-end; margin-top: 0.5rem; }
.inv-totals-table { width: 220px; }
.inv-totals-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 0.8rem; color: #666; }
.inv-totals-row.inv-total-final {
  font-size: 1rem; font-weight: 800; padding-top: 8px;
  margin-top: 6px;
}

.inv-notes { margin-top: 1.5rem; }
.inv-notes-label { font-size: 0.65rem; font-weight: 700; color: #999; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }
.inv-notes-text { font-size: 0.75rem; color: #666; }
.inv-watermark { text-align: center; font-size: 0.65rem; color: #bbb; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #eee; }

/* ── Footer ── */
.site-footer {
  text-align: center; padding: 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.85rem;
}
.site-footer a { color: var(--accent-light); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* ── Animations ── */
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 2rem; right: 2rem; z-index: 1000;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 1rem 1.5rem;
  box-shadow: var(--shadow); display: none; animation: slideIn 0.3s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .app-container { grid-template-columns: 1fr; }
  .preview-panel { position: static; max-height: none; }
  .form-panel { max-height: none; }
  .hero-banner h1 { font-size: 1.6rem; }
  .line-items-header,
  .line-item-row { grid-template-columns: 1fr 60px 80px 80px 32px; }
}
@media (max-width: 600px) {
  .navbar { padding: 0 1rem; }
  .app-container { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
  .line-items-header { display: none; }
  .line-item-row {
    grid-template-columns: 1fr;
    gap: 0.3rem; padding: 0.5rem;
    background: var(--bg-input); border-radius: var(--radius-sm);
  }
}
