/* ===== CSS Variables ===== */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --secondary: #0ea5e9;
  --accent: #f59e0b;
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --error: #ef4444;
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  scroll-behavior: smooth;
}

body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  background-image:
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0, transparent 50%),
    radial-gradient(at 100% 0%, rgba(14, 165, 233, 0.1) 0, transparent 50%);
  background-attachment: fixed;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header {
  background: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  text-align: center;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.logo-icon {
  width: 36px;
  height: 36px;
  color: var(--primary);
}

.logo-text {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-secondary);
  font-size: 0.95rem;
}
.main-content {
  flex: 1;
  padding: 2rem;
}
.content-wrapper {
  max-width: 900px;
  margin: 0 auto;
}
.form-section {
  animation: fadeInUp 0.5s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.form-card {
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  transition: var(--transition-normal);
}

.form-card:hover {
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow: var(--shadow-lg);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.card-title svg {
  width: 22px;
  height: 22px;
  color: var(--primary);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.form-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.form-group.full-width {
  grid-column: 1 / -1;
}
.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input,
textarea,
select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: var(--transition-fast);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}
textarea {
  resize: vertical;
  min-height: 60px;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 18px;
  padding-right: 2.5rem;
}

/* Color Picker */
.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.5rem 1rem;
  transition: var(--transition-fast);
}

.color-picker-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.color-picker-wrapper input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
}

.color-value {
  font-size: 0.9rem;
  font-family: monospace;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.items-table-wrapper {
  overflow-x: auto;
  margin-bottom: 1rem;
}
.items-table {
  width: 100%;
  border-collapse: collapse;
}

.items-table th {
  text-align: left;
  padding: 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.items-table td {
  padding: 0.5rem;
  vertical-align: middle;
}
.items-table .col-desc {
  width: 45%;
}
.items-table .col-qty {
  width: 12%;
}
.items-table .col-price {
  width: 20%;
}
.items-table .col-total {
  width: 18%;
}
.items-table .col-action {
  width: 5%;
}
.items-table input {
  padding: 0.6rem 0.75rem;
}
.item-total {
  font-weight: 600;
  color: var(--primary-light);
}

.btn-remove {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.25rem;
  transition: var(--transition-fast);
}

.btn-remove:hover {
  background: rgba(239, 68, 68, 0.2);
}

.btn-add-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.875rem;
  transition: var(--transition-fast);
}

.btn-add-item:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}
.btn-add-item svg {
  width: 18px;
  height: 18px;
}

.totals-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
}

.totals-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 280px;
  padding: 0.5rem 0;
}

.totals-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}
.totals-label input {
  width: 60px;
  padding: 0.4rem 0.5rem;
  text-align: center;
}
.totals-value {
  font-weight: 600;
  font-size: 1rem;
  min-width: 120px;
  text-align: right;
}
.total-final {
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.total-final .totals-label,
.total-final .totals-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-light);
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  padding: 1rem 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn svg {
  width: 20px;
  height: 20px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow:
    var(--shadow-md),
    0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow:
    var(--shadow-lg),
    0 8px 25px rgba(99, 102, 241, 0.4);
}
.btn-secondary {
  background: rgba(14, 165, 233, 0.1);
  color: var(--secondary);
  border: 1px solid rgba(14, 165, 233, 0.3);
}
.btn-secondary:hover {
  background: rgba(14, 165, 233, 0.2);
  border-color: var(--secondary);
}
.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--text-secondary);
}

.preview-section {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(10px);
  z-index: 200;
  padding: 2rem;
  overflow-y: auto;
  animation: fadeIn 0.3s ease;
}

.preview-section.active {
  display: block;
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 800px;
  margin: 0 auto 1.5rem;
}
.preview-header h2 {
  font-size: 1.25rem;
}

.btn-close {
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.5rem;
  transition: var(--transition-fast);
}

.btn-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.preview-actions .btn {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

.preview-container {
  max-width: 800px;
  margin: 0 auto;
}

.invoice-preview {
  background: #ffffff;
  color: #1a1a1a;
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  min-height: 1000px;
}

.invoice-preview .invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 40px;
  padding-bottom: 30px;
  border-bottom: 2px solid #e5e7eb;
}
.invoice-preview .sender-info h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 10px;
}
.invoice-preview .sender-info p {
  font-size: 0.875rem;
  color: #6b7280;
  line-height: 1.6;
  margin: 0;
}
.invoice-preview .invoice-title {
  text-align: left;
}
.invoice-preview .invoice-title h2 {
  font-size: 2.5rem;
  font-weight: 800;
  color: #6366f1;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}
.invoice-preview .invoice-title p {
  font-size: 0.9rem;
  color: #6b7280;
  margin: 4px 0;
}
.invoice-preview .invoice-title strong {
  color: #1a1a1a;
}
.invoice-preview .invoice-date {
  text-align: right;
  align-self: flex-start;
  padding-top: 10px;
}
.invoice-preview .invoice-date p {
  font-size: 0.8rem;
  color: #6b7280;
  margin: 2px 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.invoice-preview .invoice-date p strong {
  color: #374151;
  font-weight: 500;
}
.invoice-preview .parties-banner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-bottom: 30px;
  padding: 24px 30px;
  background: linear-gradient(135deg, #0f2744 0%, #1a3a5c 100%);
  border-radius: 8px;
}
.invoice-preview .party-col h3 {
  font-size: 0.85rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 12px;
}
.invoice-preview .party-col p {
  font-size: 0.85rem;
  color: #94a3b8;
  line-height: 1.7;
  margin: 0;
}
.invoice-preview .party-col .name {
  font-weight: 600;
  color: #e2e8f0;
  font-size: 0.9rem;
}
.invoice-preview .parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-bottom: 40px;
}
.invoice-preview .party h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.invoice-preview .party p {
  font-size: 0.9rem;
  color: #374151;
  line-height: 1.7;
  margin: 0;
}
.invoice-preview .party .name {
  font-weight: 600;
  color: #1a1a1a;
  font-size: 1rem;
}
.invoice-preview .items-section {
  margin-bottom: 30px;
}
.invoice-preview .items-table th {
  background: #f3f4f6;
  padding: 12px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  text-align: left;
  border: none;
}
.invoice-preview .items-table th:last-child {
  text-align: right;
}
.invoice-preview .items-table td {
  padding: 16px;
  font-size: 0.9rem;
  color: #374151;
  border-bottom: 1px solid #e5e7eb;
}
.invoice-preview .items-table td:last-child {
  text-align: right;
  font-weight: 600;
}
.invoice-preview .items-table .item-name {
  font-weight: 500;
  color: #1a1a1a;
}
.invoice-preview .totals-box {
  margin-left: auto;
  width: 280px;
  margin-bottom: 40px;
}
.invoice-preview .totals-box .row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.9rem;
}
.invoice-preview .totals-box .row.label {
  color: #6b7280;
}
.invoice-preview .totals-box .row.value {
  color: #374151;
}
.invoice-preview .totals-box .row.grand-total {
  padding-top: 12px;
  margin-top: 8px;
  border-top: 2px solid #e5e7eb;
  font-size: 1.1rem;
  font-weight: 700;
}
.invoice-preview .totals-box .row.grand-total .label {
  color: #1a1a1a;
}
.invoice-preview .totals-box .row.grand-total .value {
  color: #6366f1;
}
.invoice-preview .notes-section {
  margin-top: 40px;
  padding-top: 30px;
  border-top: 1px solid #e5e7eb;
}
.invoice-preview .notes-section h4 {
  font-size: 0.75rem;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.invoice-preview .notes-section p {
  font-size: 0.85rem;
  color: #6b7280;
  line-height: 1.6;
  margin-bottom: 20px;
  white-space: pre-line;
}

.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
  .header {
    padding: 1rem;
  }
  .logo-text {
    font-size: 1.5rem;
  }
  .main-content {
    padding: 1rem;
  }
  .form-card {
    padding: 1.25rem;
  }
  .form-grid,
  .form-grid.cols-3 {
    grid-template-columns: 1fr;
  }
  .items-table th {
    font-size: 0.7rem;
    padding: 0.5rem;
  }
  .items-table td {
    padding: 0.25rem;
  }
  .items-table input {
    padding: 0.5rem;
    font-size: 0.85rem;
  }
  .totals-section {
    align-items: stretch;
  }
  .totals-row {
    min-width: 100%;
  }
  .action-buttons {
    flex-direction: column;
  }
  .btn {
    width: 100%;
    justify-content: center;
  }
  .preview-section {
    padding: 1rem;
  }
  .invoice-preview {
    padding: 20px;
  }
  .invoice-preview .invoice-header {
    flex-direction: column;
    gap: 20px;
  }
  .invoice-preview .invoice-title {
    text-align: left;
  }
  .invoice-preview .parties-banner {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 20px;
  }
  .invoice-preview .parties {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  .invoice-preview .totals-box {
    width: 100%;
  }
}

@media print {
  body {
    background: white;
  }
  .header,
  .footer,
  .form-section,
  .preview-header {
    display: none !important;
  }
  .preview-section {
    position: static;
    background: white;
    padding: 0;
  }
  .invoice-preview {
    box-shadow: none;
    border-radius: 0;
  }
}
