/* Online Invoice Generator - Premium Modern UI */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #64748b;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
  --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Typography */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.25; }
h1 { font-size: 1.875rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }

/* Layout */
.container { max-width: 1400px; margin: 0 auto; padding: 0 1rem; }
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.logo {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.logo span { color: var(--primary); }

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}

/* Builder Layout */
.builder {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  padding: 1.5rem 0 3rem;
  align-items: start;
}
@media (max-width: 1024px) {
  .builder { grid-template-columns: 1fr; }
  .preview-panel { order: -1; }
}

.editor-panel { min-width: 0; }
.preview-panel {
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

/* Forms */
.form-group { margin-bottom: 0.85rem; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="color"],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
textarea { resize: vertical; min-height: 70px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  background: #f1f5f9;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #e2e8f0; }
.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-lg { padding: 0.85rem 1.5rem; font-size: 1rem; }

/* Items Table */
.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.items-table th {
  text-align: left;
  padding: 0.5rem;
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
.items-table td {
  padding: 0.4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.items-table input {
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}
.items-table .col-qty { width: 70px; }
.items-table .col-price { width: 90px; }
.items-table .col-tax { width: 70px; }
.items-table .col-disc { width: 80px; }
.items-table .col-total { width: 90px; font-weight: 600; }
.items-table .col-actions { width: 40px; }

/* Totals */
.totals-box {
  margin-top: 1rem;
  background: #f8fafc;
  border-radius: 8px;
  padding: 1rem;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  font-size: 0.9rem;
}
.totals-row.grand {
  font-size: 1.15rem;
  font-weight: 700;
  border-top: 2px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.6rem;
  color: var(--primary);
}

/* Template Selector */
.template-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}
@media (max-width: 600px) {
  .template-grid { grid-template-columns: repeat(2, 1fr); }
}
.template-option {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  text-align: center;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  transition: all 0.15s;
  background: #fff;
}
.template-option:hover { border-color: var(--primary); }
.template-option.active {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
}

/* Color presets */
.color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--primary); }

/* Retention */
.retention-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}
.retention-option {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.5rem;
  text-align: center;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s;
}
.retention-option:hover { border-color: var(--primary); }
.retention-option.active {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
}
.retention-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
  line-height: 1.4;
}

/* Logo Upload */
.logo-upload {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.logo-upload:hover { border-color: var(--primary); }
.logo-preview {
  max-width: 160px;
  max-height: 80px;
  margin: 0.5rem auto;
  display: block;
}
.logo-upload input[type="file"] { display: none; }

/* Preview Invoice */
.invoice-preview {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  font-size: 0.8rem;
  box-shadow: var(--shadow-lg);
  min-height: 500px;
}
.invoice-preview .inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 3px solid var(--inv-primary, #2563eb);
}
.invoice-preview .inv-logo { max-height: 60px; max-width: 140px; }
.invoice-preview .inv-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--inv-primary, #2563eb);
  letter-spacing: 0.05em;
}
.invoice-preview .inv-meta { text-align: right; font-size: 0.75rem; }
.invoice-preview .inv-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.invoice-preview .party-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  font-weight: 600;
}
.invoice-preview table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}
.invoice-preview th {
  background: var(--inv-primary, #2563eb);
  color: #fff;
  padding: 0.45rem 0.5rem;
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
}
.invoice-preview td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #eee;
}
.invoice-preview .totals { margin-left: auto; width: 220px; }
.invoice-preview .totals .row {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
}
.invoice-preview .totals .grand {
  font-weight: 700;
  font-size: 1rem;
  border-top: 2px solid var(--inv-primary, #2563eb);
  margin-top: 0.3rem;
  padding-top: 0.4rem;
  color: var(--inv-primary, #2563eb);
}
.invoice-preview .qr-area {
  margin-top: 1.5rem;
  text-align: center;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
.invoice-preview .qr-area img { width: 90px; height: 90px; }
.invoice-preview .notes-area {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }

/* Success Screen */
.success-screen {
  max-width: 640px;
  margin: 2rem auto;
  text-align: center;
}
.success-icon {
  width: 72px;
  height: 72px;
  background: #dcfce7;
  color: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0 auto 1.25rem;
}
.url-box {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-family: monospace;
  font-size: 0.9rem;
  word-break: break-all;
  margin: 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.url-box input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
}
.share-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 1.25rem 0;
}

/* Draft indicator */
.draft-indicator {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.draft-indicator.saved { color: var(--success); }

/* Landing / SEO */
.hero {
  text-align: center;
  padding: 3rem 1rem 2rem;
  background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 100%);
}
.hero h1 {
  font-size: 2.25rem;
  margin-bottom: 0.75rem;
}
.hero p {
  font-size: 1.1rem;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto 1.5rem;
}
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  padding: 2rem 0;
}
.feature-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
  text-align: center;
}
.feature-card .icon {
  font-size: 1.75rem;
  margin-bottom: 0.75rem;
}
.faq details {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  padding: 1rem 1.25rem;
}
.faq summary {
  font-weight: 600;
  cursor: pointer;
}

/* Mobile preview toggle */
.mobile-preview-btn {
  display: none;
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 200;
  box-shadow: var(--shadow-lg);
}
@media (max-width: 1024px) {
  .mobile-preview-btn { display: inline-flex; }
  .preview-panel.hidden-mobile { display: none; }
}

/* Print */
@media print {
  body * { visibility: hidden; }
  .invoice-print, .invoice-print * { visibility: visible; }
  .invoice-print {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
  .no-print { display: none !important; }
}

/* Utility */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
