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

:root {
  --color-primary: #1a1a1a;
  --color-secondary: #4a4a4a;
  --color-accent: #2563eb;
  --color-background: #fafafa;
  --color-surface: #ffffff;
  --color-border: #e5e5e5;
  --color-text: #1a1a1a;
  --color-text-secondary: #6b7280;
  --color-success: #10b981;
  --color-error: #ef4444;

  --font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --radius: 8px;
}

body {
  font-family: var(--font-family);
  background: var(--color-background);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-primary);
}

.header-actions {
  display: flex;
  gap: 0.75rem;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-upload,
.btn-add {
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-family);
}

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

.btn-primary:hover {
  background: var(--color-secondary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-background);
  border-color: var(--color-secondary);
}

.btn-upload {
  background: var(--color-background);
  color: var(--color-text);
  border: 1px dashed var(--color-border);
  width: 100%;
  justify-content: center;
}

.btn-upload:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.btn-add {
  background: var(--color-surface);
  color: var(--color-accent);
  border: 1px solid var(--color-border);
  width: 100%;
  justify-content: center;
}

.btn-add:hover {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

/* Main Content */
.main-content {
  display: flex;
  flex: 1;
  gap: 2rem;
  padding: 2rem;
  max-width: 1800px;
  margin: 0 auto;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
  max-height: calc(100vh - 120px);
  padding-right: 1rem;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--color-secondary);
}

.section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.section-title {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  margin-bottom: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="tel"],
.form-group input[type="date"],
.form-group input[type="number"],
.form-group textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: var(--font-family);
  transition: all 0.2s;
  background: var(--color-surface);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.file-input {
  display: none;
}

/* Items List */
#itemsList {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
}

.item-row {
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  position: relative;
}

.item-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.item-number {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.item-remove {
  background: none;
  border: none;
  color: var(--color-error);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.item-remove:hover {
  background: rgba(239, 68, 68, 0.1);
}

.item-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.item-row-flex {
  display: flex;
  gap: 0.5rem;
}

.item-row-flex .form-group {
  flex: 1;
  margin-bottom: 0;
}

/* Invoice Preview */
.invoice-preview {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem;
  background: var(--color-background);
  border-radius: var(--radius);
}

.a4-container {
  width: 210mm;
  min-height: 297mm;
  background: white;
  box-shadow: var(--shadow-lg);
  padding: 20mm;
  position: relative;
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 2px solid var(--color-primary);
}

.invoice-logo {
  flex-shrink: 0;
}

.logo-placeholder {
  width: 120px;
  height: 60px;
  background: var(--color-background);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  font-size: 0.875rem;
}

.invoice-logo img {
  max-width: 150px;
  max-height: 80px;
  object-fit: contain;
}

.invoice-title {
  text-align: right;
}

.invoice-title h1 {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
}

.invoice-meta {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.meta-item {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  font-size: 0.875rem;
}

.meta-label {
  color: var(--color-text-secondary);
  font-weight: 500;
}

.meta-value {
  color: var(--color-text);
  font-weight: 600;
}

.invoice-addresses {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3rem;
  margin-bottom: 3rem;
}

.address-block h4 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  margin-bottom: 0.75rem;
}

.company-name {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.address {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre-line;
  margin-bottom: 0.5rem;
}

.contact {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 2rem;
}

.invoice-table thead {
  background: var(--color-primary);
  color: white;
}

.invoice-table th {
  padding: 0.875rem;
  text-align: left;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.invoice-table th:last-child,
.invoice-table td:last-child {
  text-align: right;
}

.invoice-table tbody tr {
  border-bottom: 1px solid var(--color-border);
}

.invoice-table td {
  padding: 1rem 0.875rem;
  font-size: 0.875rem;
}

.empty-state {
  text-align: center !important;
  color: var(--color-text-secondary);
  font-style: italic;
  padding: 2rem !important;
}

.invoice-totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 3rem;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  min-width: 300px;
  font-size: 0.875rem;
}

.totals-row.total {
  font-size: 1.25rem;
  font-weight: 700;
  padding-top: 0.75rem;
  border-top: 2px solid var(--color-primary);
  margin-top: 0.5rem;
}

.invoice-notes {
  background: var(--color-background);
  padding: 1.5rem;
  border-radius: var(--radius);
  margin-bottom: 2rem;
}

.invoice-notes h4 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.invoice-notes p {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  line-height: 1.6;
  white-space: pre-line;
}

.invoice-footer {
  text-align: center;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: 0.875rem;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--color-surface);
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-content.modal-large {
  max-width: 900px;
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--color-background);
  color: var(--color-text);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.full-preview {
  background: white;
  padding: 2rem;
  border-radius: var(--radius);
}

/* Responsive */
@media (max-width: 1400px) {
  .a4-container {
    transform: scale(0.85);
    transform-origin: top center;
  }
}

@media (max-width: 1200px) {
  .main-content {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: none;
  }

  .a4-container {
    transform: scale(0.7);
  }
}

@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 1rem;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .header-actions button {
    flex: 1;
    min-width: 150px;
  }

  .a4-container {
    transform: scale(0.5);
    width: 210mm;
  }

  .invoice-addresses {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
}

/* Print Styles */
@media print {
  body {
    background: white;
  }

  .header,
  .sidebar {
    display: none;
  }

  .main-content {
    padding: 0;
  }

  .invoice-preview {
    padding: 0;
    background: white;
  }

  .a4-container {
    box-shadow: none;
    transform: none;
    width: 100%;
    min-height: auto;
  }
}

/* Added spin animation for loading state */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.spin {
  animation: spin 1s linear infinite;
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
