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

:root {
  --bg-color: #f8fafc;
  --header-bg: rgba(255, 255, 255, 0.8);
  --panel-bg: rgba(255, 255, 255, 0.6);
  --panel-border: rgba(255, 255, 255, 0.8);
  --preview-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2828;
  --input-bg: #ffffff;
  --input-border: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius: 12px;
  --glass-blur: blur(12px);
}

[data-bs-theme="dark"] {
  --bg-color: #0f172a;
  --header-bg: rgba(15, 23, 42, 0.8);
  --panel-bg: rgba(30, 41, 59, 0.6);
  --panel-border: rgba(255, 255, 255, 0.05);
  --preview-bg: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --input-bg: #0f172a;
  --input-border: #334155;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

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



/* Main Layout */
.main-content {
  flex: 1;
  padding: 40px 0;
}

.grid-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 32px;
}

@media (min-width: 1024px) {
  .grid-layout {
    grid-template-columns: 500px 1fr;
  }
  .grid-layout > * {
    min-width: 0;
  }
}

/* Panels */
.panel {
  background: var(--panel-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  transition: all 0.3s ease;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.panel-title {
  font-size: 1.5rem;
  font-weight: 600;
}

/* Form Controls */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: end;
}

@media (min-width: 768px) {
  .form-grid-2 { grid-template-columns: 1fr 1fr; }
  .form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

input, textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--input-border);
  color: var(--text-main);
}

.btn-outline:hover {
  background: var(--input-bg);
}

.btn-icon {
  padding: 8px;
  border-radius: 50%;
  color: var(--danger);
  background: transparent;
}

.btn-icon:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* File Input */
.file-upload {
  position: relative;
  overflow: hidden;
  display: inline-block;
}
.file-upload input[type=file] {
  position: absolute;
  font-size: 100px;
  opacity: 0;
  right: 0;
  top: 0;
  cursor: pointer;
}

/* Line Items */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  background: var(--input-bg);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--input-border);
  align-items: end;
}

@media (min-width: 768px) {
  .item-row {
    grid-template-columns: 2.5fr 0.8fr 1.2fr auto;
    padding: 12px;
  }
}

/* Preview Section */
.preview-container {
  position: sticky;
  top: 104px;
}

.preview-scroll-wrapper {
  overflow-x: auto;
  padding: 16px 0;
}

.invoice-preview {
  --preview-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --input-bg: #f8fafc;
  --input-border: #e2e8f0;
  
  background: var(--preview-bg);
  padding: 48px;
  border-radius: 0;
  box-shadow: var(--shadow-lg);
  color: var(--text-main);
  /* A4 Proportions (96 PPI) */
  width: 794px;
  min-height: 1123px;
  margin: 0 auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--input-border);
  padding-bottom: 32px;
  margin-bottom: 32px;
}

.preview-logo {
  max-height: 80px;
  max-width: 200px;
  margin-bottom: 16px;
  object-fit: contain;
}

.preview-title {
  font-size: 2.5rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-main);
}

.preview-subtitle {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.preview-text {
  color: var(--text-muted);
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 0.95rem;
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-bottom: 48px;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 48px;
}

.preview-table th {
  background: var(--input-bg);
  padding: 12px 16px;
  text-align: left;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 2px solid var(--input-border);
}

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

.preview-table td {
  padding: 16px;
  border-bottom: 1px solid var(--input-border);
  font-size: 0.95rem;
}

.preview-totals {
  display: flex;
  justify-content: flex-end;
}

.totals-wrapper {
  width: 100%;
  max-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.total-row.grand-total {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  padding-top: 12px;
  border-top: 1px solid var(--input-border);
}

.preview-notes {
  margin-top: auto;
  padding-top: 24px;
  border-top: 1px solid var(--input-border);
}

.notes-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}

footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Utility */
.hidden { display: none !important; }
.text-danger { color: var(--danger); }

/* Icons */
.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.animate-spin {
  animation: spin 1s linear infinite;
}

/* Print/PDF Page Break Handling */
.preview-header, 
.preview-grid, 
.preview-table tr, 
.preview-totals, 
.preview-notes-container {
  page-break-inside: avoid;
}

/* --- THEME OVERRIDES FOR LIVE PREVIEW --- */

/* 1. Bold Corporate */
.theme-bold .preview-header { background: #1e293b; color: white; padding: 32px; margin: -48px -48px 32px -48px; border-radius: 0; min-height: 170px; box-sizing: border-box; }
.theme-bold .preview-title, .theme-bold #prev-from-name { color: white !important; }
.theme-bold #prev-from-address { color: #cbd5e1; }
.theme-bold .preview-table thead th { background: #1e293b; color: white; border-bottom: none; }

/* 2. Centered Minimalist */
.theme-centered .preview-header { justify-content: center; text-align: center; flex-direction: column; gap: 16px; border-bottom: none; padding-bottom: 24px; margin-bottom: 24px; position: relative; }
.theme-centered .preview-header::after { content: ""; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 220px; height: 1px; background: var(--input-border); }
.theme-centered .preview-header > div { text-align: center !important; }
.theme-centered .preview-grid { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 24px; }
.theme-centered .preview-grid > div { text-align: center !important; justify-content: center; align-items: center; }
.theme-centered .preview-table th, .theme-centered .preview-table td { text-align: center; }
.theme-centered .preview-grid > div:nth-child(2) { display: flex !important; flex-wrap: wrap; justify-content: center; gap: 16px; width: 100%; }

/* 3. Elegant Serif */
.theme-elegant { font-family: 'Times New Roman', Times, serif; }
.theme-elegant .preview-title { font-weight: normal; letter-spacing: 4px; }
.theme-elegant .preview-table { border-top: 3px solid black; }
.theme-elegant .preview-table th { border-bottom: 2px solid black; color: black; text-transform: uppercase; letter-spacing: 1px; }
.theme-elegant .preview-table td { border-bottom: 1px solid #e2e8f0; }
.theme-elegant .grand-total { border-top: 2px solid black; color: black; }

/* 4. Structured Grid */
.theme-bordered .preview-grid > div { border: 1px solid var(--input-border); padding: 16px; border-radius: 4px; }
.theme-bordered .preview-table th, .theme-bordered .preview-table td { border: 1px solid var(--input-border); padding: 12px 16px; }
.theme-bordered .preview-table th { border-bottom: 2px solid var(--input-border); }

/* 5. Vibrant Accent */
.theme-accent .preview-title { color: #3b82f6 !important; }
.theme-accent .notes-title { color: #3b82f6; }
.theme-accent .preview-table th { background: #3b82f6; color: white; border: none; }
.theme-accent .grand-total { color: #3b82f6; }
.theme-accent .preview-header { border-top: 30px solid #3b82f6; margin: -48px -48px 32px -48px; padding: 40px 48px 0 48px; }

/* 6. Modern Tech */
.theme-modern { background: #f8fafc; padding: 32px; }
.theme-modern .preview-header { background: white; border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); padding: 32px; margin-bottom: 24px; }
.theme-modern .preview-grid { background: white; border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); padding: 32px; margin-bottom: 24px; }

/* 7. Strict Monochrome */
.theme-monochrome { color: black !important; }
.theme-monochrome * { border-color: black !important; }
.theme-monochrome .preview-header { border-bottom: 4px solid black; padding-bottom: 24px; margin-bottom: 24px; }
.theme-monochrome .preview-title, .theme-monochrome .notes-title, .theme-monochrome .grand-total { color: black !important; font-weight: 900; }
.theme-monochrome #prev-from-name, .theme-monochrome #prev-to-name { color: black !important; font-weight: bold; }
.theme-monochrome #prev-from-address, .theme-monochrome #prev-to-address, .theme-monochrome .preview-text { color: black !important; }
.theme-monochrome .preview-table { border: 1px solid black; }
.theme-monochrome .preview-table th { border: 1px solid black; color: black; background: white; text-transform: uppercase; font-weight: 900; }
.theme-monochrome .preview-table td { border: 1px solid black; color: black; }

/* 8. Vintage Retro */
.theme-retro { font-family: 'Courier New', Courier, monospace; }
.theme-retro .preview-title { display: inline-block; color: #333 !important; }
.theme-retro .preview-header { border-bottom: 1px dashed #ccc; padding-bottom: 24px; margin-bottom: 24px; }
.theme-retro .preview-table th { border-top: 1px dashed #333; border-bottom: 1px dashed #333; background: transparent; color: #333; }
.theme-retro .preview-table td { border-bottom: 1px dashed #ccc; }
.theme-retro .notes-title, .theme-retro .grand-total, .theme-retro #prev-from-name, .theme-retro #prev-to-name { color: #333 !important; }

/* 9. Earthy Nature */
.theme-nature .preview-header { border-left: 8px solid #166534; padding-left: 24px; margin-bottom: 24px; }
.theme-nature .preview-title { color: #166534 !important; }
.theme-nature .notes-title { color: #166534; }
.theme-nature .preview-table th { background: #f0fdf4; color: #166534; border: none; }
.theme-nature .preview-table td { border-bottom: 1px solid #166534; }
.theme-nature .grand-total { color: #166534; }

/* 10. Deep Ocean */
.theme-ocean .preview-header { background: #0284c7; color: white; padding: 32px; margin: -48px -48px 32px -48px; border-radius: 0; min-height: 170px; box-sizing: border-box; }
.theme-ocean .preview-title, .theme-ocean #prev-from-name { color: white !important; }
.theme-ocean #prev-from-address { color: #e0f2fe; }
.theme-ocean .preview-table th { background: #0284c7; color: white; border: none; border-radius: 4px; }
.theme-ocean .preview-table td { border-bottom: 1px solid #0284c7; }
.theme-ocean .notes-title { color: #0284c7; }

/* 11. High Density Compact */
.theme-compact { font-size: 0.85rem; }
.theme-compact .preview-header { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--input-border); }
.theme-compact .preview-title { font-size: 1.5rem; }
.theme-compact .preview-subtitle { font-size: 1rem !important; }
.theme-compact .preview-grid { display: flex; flex-direction: row; justify-content: space-between; gap: 16px; margin-bottom: 16px; align-items: flex-start; }
.theme-compact .preview-grid > div:last-child { display: flex; flex-direction: column; gap: 4px !important; text-align: right; }
.theme-compact .preview-table td, .theme-compact .preview-table th { padding: 8px 12px; font-size: 0.85rem; }
.theme-compact .notes-title { font-size: 0.75rem; margin-bottom: 4px; }
.theme-compact .preview-notes { padding-top: 16px; margin-top: 16px; }
