:root {
  --primary: #6c5ce7;
  --secondary: #a29bfe;
  --success: #00b894;
  --warning: #fdcb6e;
  --danger: #ff7675;
  --light: #f8f9fa;
  --dark: #343a40;
  --text: #2d3436;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;
  padding: 2rem;
  color: var(--text);
  padding-bottom: 60px; /* Prevents footer overlap */
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 2.5rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.tagline {
  color: var(--dark);
  font-size: 1.1rem;
}

.app-grid {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 1.5rem;
}

.card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 10px 20px rgba(0,0,0,0.05);
  transition: transform 0.3s ease;
}

.card:hover {
  transform: translateY(-5px);
}

.card h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

input, select, textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.3s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

.logo-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
  border: 2px dashed #ddd;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}

.logo-upload:hover {
  border-color: var(--primary);
  background: rgba(108, 92, 231, 0.05);
}

.upload-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary);
  font-weight: 500;
  margin-top: 0.5rem;
}

#items-list {
  margin-bottom: 1rem;
}

.item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 0.5fr;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  align-items: center;
}

.delete-btn {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.2rem;
}

.totals-card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 10px 20px rgba(0,0,0,0.05);
}

.total-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #eee;
}

.total-row:last-child {
  border-bottom: none;
}

.grand-total {
  font-weight: bold;
  font-size: 1.1rem;
  color: var(--primary);
}

.action-btns {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

button {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.primary-btn {
  background: var(--primary);
  color: white;
}

.primary-btn:hover {
  background: #5a4bd8;
  transform: translateY(-2px);
}

.success-btn {
  background: var(--success);
  color: white;
}

.success-btn:hover {
  background: #00a884;
  transform: translateY(-2px);
}

.secondary-btn {
  background: #6c757d;
  color: white;
}

.secondary-btn:hover {
  background: #5a6268;
  transform: translateY(-2px);
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
}

.modal-content {
  background: white;
  margin: 5% auto;
  padding: 2rem;
  width: 90%;
  max-width: 800px;
  border-radius: 12px;
  position: relative;
  max-height: 80vh;
  overflow-y: auto;
}

.close-btn {
  position: absolute;
  right: 1rem;
  top: 1rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--dark);
}

.close-btn:hover {
  color: var(--primary);
}

/* History Items */
.history-item {
  padding: 1rem;
  border-bottom: 1px solid #eee;
  margin-bottom: 0.5rem;
}

.history-item h3 {
  margin-bottom: 0.25rem;
}

.history-item small {
  color: #666;
  display: block;
  margin-bottom: 0.5rem;
}

.history-item button {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

/* ===== Mobile Optimization ===== */
@media (max-width: 768px) {
  .app-grid {
    grid-template-columns: 1fr;
  }

  input, select, textarea {
    font-size: 16px !important;
    min-height: 44px !important;
  }
  
  .modal-content {
    width: 95% !important;
    margin: 2% auto !important;
    padding: 15px !important;
  }
  
  .logo-upload img {
    max-height: 120px !important;
  }
}

/* ===== PDF Preview Fix ===== */
#live-preview {
  transform-origin: top left;
  transform: scale(0.8);
  width: 125%;
}

/* ===== Color Pickers ===== */
input[type="color"] {
  width: 100%;
  height: 50px;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  cursor: pointer;
}

/* ===== Footer ===== */
footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 10px;
  background: white;
  z-index: 100;
  border-top: 1px solid #eee;
  color: #666;
  font-size: 0.9rem;
}

/* ===== Support Buttons ===== */
.support-section {
  text-align: center;
  margin: 20px 0;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.support-btn, .feedback-btn {
  padding: 12px 20px;
  border-radius: 50px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  transition: all 0.3s;
}

.support-btn {
  background: #FFDD00;
  color: #000;
}

.feedback-btn {
  background: var(--primary);
  color: white;
}

.support-btn:hover, .feedback-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

/* RTL Support */
[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

[dir="rtl"] .item-row {
  grid-template-columns: 0.5fr 1fr 1fr 2fr;
}

[dir="rtl"] .total-row {
  flex-direction: row-reverse;
}

/* ===== Mobile Close Button Fix ===== */
.close-btn {
  position: absolute;
  right: 1rem;
  top: 1rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--dark);
  z-index: 101;
  padding: 15px; /* Larger tap area */
  margin: -15px;
  -webkit-tap-highlight-color: transparent;
}

/* ===== PDF Preview Scaling Fix ===== */
#invoice-preview {
  transform-origin: top left;
  width: 100%;
  overflow: hidden;
}

/* ===== Mobile Download Button ===== */
@media (max-width: 768px) {
  #download-pdf {
    min-height: 44px; /* Better touch target */
  }
}
/* PDF Dimension Fixes */
#pdf-content {
  box-sizing: border-box;
  width: 100% !important;
  max-width: 760px;
  margin: 0 auto;
  padding: 20px;
  background: white;
}

.invoice-pdf {
  width: 100% !important;
  overflow: visible !important;
}

table {
  width: 100% !important;
  table-layout: fixed;
}

@media print {
  body, #pdf-content {
    width: 210mm !important;
    height: 297mm !important;
  }
}
/* Sharp text rendering */
#pdf-content {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Force crisp fonts */
.invoice-pdf, .invoice-pdf * {
  font-smooth: always !important;
}

/* High-res images */
.invoice-pdf img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}