:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #121826;
  --bg-tertiary: #1a2133;
  --bg-card: #1e2638;
  --border-color: #2a344a;
  --text-primary: #ffffff;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  --accent-primary: #4361ee;
  --accent-secondary: #3f37c9;
  --accent-hover: #3a56d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* iOS SAFARI FIXES */
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  overflow-x: hidden !important;
  width: 100%;
  max-width: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, var(--bg-primary) 0%, #070b11 100%);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  padding-top: 20px;
  padding-bottom: 20px;
  overflow-x: hidden !important;
  width: 100%;
  max-width: 100%;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  width: 100%;
  box-sizing: border-box;
}

/* ====== HEADER ====== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0 24px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 24px;
  width: 100%;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 22px;
  color: white;
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
}

.brand-info h1 {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(90deg, #ffffff 0%, #a0aec0 100%);
  -webkit-background-clip: text;
  background-clip: text; /* STANDARD PROPERTY ADDED */
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}

.brand-info p {
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
}

/* ====== MAIN CONTENT ====== */
.content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  margin-bottom: 32px;
  width: 100%;
}

@media (min-width: 1024px) {
  .content {
    grid-template-columns: 1fr 480px;
    gap: 32px;
  }
}

/* ====== FORM SECTION ====== */
.form-section {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  width: 100%;
  box-sizing: border-box;
}

@media (min-width: 768px) {
  .card {
    padding: 28px;
  }
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  width: 100%;
}

@media (min-width: 768px) {
  .card-header {
    margin-bottom: 24px;
  }
}

.card-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

@media (min-width: 768px) {
  .card-title {
    font-size: 20px;
  }
}

.card-title svg {
  width: 22px;
  height: 22px;
  color: var(--accent-primary);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 20px;
  width: 100%;
}

@media (min-width: 768px) {
  .form-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
  }
}

.form-group {
  margin-bottom: 16px;
  width: 100%;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.form-label svg {
  width: 16px;
  height: 16px;
  color: var(--accent-primary);
}

.form-control {
  width: 100%;
  padding: 14px 16px;
  background: rgba(30, 38, 56, 0.7);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  transition: var(--transition);
  -webkit-appearance: none;
  appearance: none; /* STANDARD PROPERTY ADDED */
}

/* iOS specific input fixes */
input[type="date"],
input[type="datetime-local"],
input[type="month"],
input[type="time"],
input[type="week"],
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none; /* STANDARD PROPERTY ADDED */
  font-size: 16px !important;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

.form-control::placeholder {
  color: var(--text-muted);
}

textarea.form-control {
  min-height: 100px;
  resize: vertical;
  width: 100%;
}

/* Logo & Stamp Upload */
.upload-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: rgba(30, 38, 56, 0.5);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-color);
  width: 100%;
}

.upload-preview {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.upload-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.upload-label {
  cursor: pointer;
  padding: 10px 20px;
  background: rgba(67, 97, 238, 0.15);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-md);
  color: var(--accent-primary);
  font-weight: 500;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  justify-content: center;
}

.upload-label:hover {
  background: rgba(67, 97, 238, 0.25);
}

.upload-hint {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  margin-top: 8px;
  width: 100%;
}

/* VAT Toggle */
.toggle-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
  width: 100%;
}

@media (min-width: 768px) {
  .toggle-group {
    flex-direction: row;
    gap: 16px;
  }
}

.toggle-option {
  flex: 1;
  padding: 16px;
  background: rgba(30, 38, 56, 0.7);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.toggle-option:hover {
  border-color: var(--accent-primary);
  background: rgba(67, 97, 238, 0.1);
}

.toggle-option.selected {
  border-color: var(--accent-primary);
  background: rgba(67, 97, 238, 0.15);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

.toggle-option input {
  display: none;
}

.toggle-label {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}

.toggle-sublabel {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Items Table */
.items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
  table-layout: fixed;
  word-wrap: break-word;
}

@media (min-width: 768px) {
  .items-table {
    font-size: 15px;
  }
}

.items-table th {
  background: rgba(30, 38, 56, 0.9);
  padding: 12px 10px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 13px;
  border-bottom: 2px solid var(--border-color);
  word-wrap: break-word;
}

@media (min-width: 768px) {
  .items-table th {
    font-size: 14px;
    padding: 14px 12px;
  }
}

.items-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 14px;
  word-wrap: break-word;
}

@media (min-width: 768px) {
  .items-table td {
    font-size: 15px;
    padding: 14px 12px;
  }
}

.items-table tr:last-child td {
  border-bottom: none;
}

.items-table input {
  background: white;
  border: none;
  color: black;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  text-align: center;
  width: 100%;
  padding: 4px 0;
  box-sizing: border-box;
}

@media (min-width: 768px) {
  .items-table input {
    font-size: 15px;
  }
}

.items-table input:focus {
  outline: none;
  border-bottom: 1px solid var(--accent-primary);
}

.items-table input[type="number"] {
  text-align: center;
}

.items-table input[type="text"] {
  text-align: center;
}

.action-cell {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.btn-remove {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  max-width: 100px;
  margin: 0 auto;
}

.btn-remove:hover {
  background: rgba(239, 68, 68, 0.25);
}

.table-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
  width: 100%;
}

@media (min-width: 768px) {
  .table-footer {
    flex-direction: row;
    justify-content: flex-end;
    gap: 12px;
  }
}

/* Buttons */
.btn {
  padding: 14px 24px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: none;
  min-width: 120px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-sizing: border-box;
}

.btn-primary {
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  box-shadow: 0 4px 14px rgba(67, 97, 238, 0.35);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(67, 97, 238, 0.45);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  height: 36px;
  width: 36px;
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-block {
  display: block;
  width: 100%;
  box-sizing: border-box;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ====== PREVIEW SECTION ====== */
.preview-section {
  position: sticky;
  top: 20px;
  align-self: flex-start;
  z-index: 10;
  width: 100%;
}

@media (max-width: 1023px) {
  .preview-section {
    position: static;
    margin-top: 24px;
    width: 100% !important;
  }
  
  .preview-container {
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  
  .preview-header,
  .preview-content,
  .preview-footer,
  .preview-actions {
    padding: 16px;
  }
}

.preview-container {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
}

.preview-header {
  padding: 28px 32px;
  border-bottom: 3px solid var(--accent-primary);
  background: white;
  flex-shrink: 0;
  width: 100%;
}

@media (min-width: 768px) {
  .preview-header {
    padding: 32px 40px;
  }
}

.preview-logo {
  width: 90px;
  height: 90px;
  border-radius: var(--radius-md);
  background: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  border: 1px solid #e2e8f0;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .preview-logo {
    width: 100px;
    height: 100px;
  }
}

.preview-title {
  font-size: 32px;
  font-weight: 800;
  color: #1a202c;
  margin: 8px 0;
  letter-spacing: -0.5px;
}

@media (min-width: 768px) {
  .preview-title {
    font-size: 36px;
  }
}

.preview-subtitle {
  font-size: 17px;
  color: var(--accent-primary);
  font-weight: 700;
}

@media (min-width: 768px) {
  .preview-subtitle {
    font-size: 18px;
  }
}

.preview-content {
  padding: 28px 32px;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  box-sizing: border-box;
}

@media (min-width: 768px) {
  .preview-content {
    padding: 32px 40px;
  }
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
  margin-bottom: 24px;
  width: 100%;
}

@media (min-width: 768px) {
  .preview-grid {
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 28px;
  }
}

.preview-section-title {
  font-size: 17px;
  font-weight: 700;
  color: #2d3748;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent-primary);
  text-align: center;
  width: 100%;
}

@media (min-width: 768px) {
  .preview-section-title {
    font-size: 18px;
    margin-bottom: 16px;
  }
}

.preview-info {
  font-size: 14px;
  line-height: 1.6;
  color: #4a5568;
  width: 100%;
}

@media (min-width: 768px) {
  .preview-info {
    font-size: 15px;
  }
}

.preview-info strong {
  color: #2d3748;
  font-weight: 600;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 13px;
  table-layout: fixed;
  word-wrap: break-word;
}

@media (min-width: 768px) {
  .preview-table {
    margin: 24px 0;
    font-size: 14px;
  }
}

.preview-table th {
  background: #f8f9fa;
  padding: 10px 8px;
  text-align: left;
  font-weight: 600;
  color: #4a5568;
  border-bottom: 2px solid #e2e8f0;
  word-wrap: break-word;
}

@media (min-width: 768px) {
  .preview-table th {
    padding: 12px;
  }
}

.preview-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #edf2f7;
  color: #2d3748;
  word-wrap: break-word;
}

@media (min-width: 768px) {
  .preview-table td {
    padding: 12px;
  }
}

.preview-table tr:last-child td {
  border-bottom: none;
}

.preview-table .text-right {
  text-align: right;
}

.preview-totals {
  margin-top: 20px;
  text-align: right;
  width: 100%;
}

@media (min-width: 768px) {
  .preview-totals {
    margin-top: 24px;
  }
}

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
  color: #4a5568;
  width: 100%;
}

@media (min-width: 768px) {
  .total-row {
    font-size: 15px;
    padding: 10px 0;
  }
}

.total-row.total {
  font-weight: 700;
  font-size: 19px;
  color: var(--accent-primary);
  border-top: 2px solid var(--accent-primary);
  padding-top: 14px;
  margin-top: 10px;
}

@media (min-width: 768px) {
  .total-row.total {
    font-size: 20px;
    padding-top: 16px;
    margin-top: 12px;
  }
}

.preview-footer {
  padding: 24px 32px;
  border-top: 1px solid #e2e8f0;
  text-align: center;
  color: #718096;
  font-size: 12px;
  line-height: 1.5;
  flex-shrink: 0;
  width: 100%;
}

@media (min-width: 768px) {
  .preview-footer {
    padding: 28px 40px;
    font-size: 13px;
  }
}

/* PDF Button Container at Bottom of Preview */
.preview-actions {
  padding: 20px 32px;
  border-top: 1px solid #e2e8f0;
  background: #f8f9fa;
  text-align: center;
  flex-shrink: 0;
  width: 100%;
}

@media (min-width: 768px) {
  .preview-actions {
    padding: 24px 40px;
  }
}

.preview-actions .btn {
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  font-size: 17px;
  padding: 16px 28px;
}

@media (min-width: 768px) {
  .preview-actions .btn {
    font-size: 18px;
    padding: 18px 32px;
  }
}

/* ====== FOOTER ====== */
.footer {
  text-align: center;
  padding: 28px 0;
  color: var(--text-muted);
  font-size: 14px;
  border-top: 1px solid var(--border-color);
  margin-top: 24px;
  width: 100%;
}

@media (min-width: 768px) {
  .footer {
    font-size: 15px;
    padding: 32px 0;
  }
}

.footer a {
  color: var(--accent-primary);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

.footer a:hover {
  color: var(--accent-hover);
}

/* ====== UTILITIES ====== */
.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--text-muted);
}

.d-flex {
  display: flex;
}

.justify-between {
  justify-content: space-between;
}

.align-center {
  align-items: center;
}

.gap-2 {
  gap: 8px;
}

.gap-3 {
  gap: 12px;
}

.gap-4 {
  gap: 16px;
}

.mb-2 {
  margin-bottom: 8px;
}

.mb-3 {
  margin-bottom: 12px;
}

.mb-4 {
  margin-bottom: 16px;
}

.mt-2 {
  margin-top: 8px;
}

.mt-3 {
  margin-top: 12px;
}

.mt-4 {
  margin-top: 16px;
}

.hidden {
  display: none;
}

/* ====== MOBILE ITEM TABLE FIX - 3 LINES PER ITEM ====== */
@media (max-width: 767px) {
  /* Ensure symmetric padding on mobile */
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom) 12px;
  }
  
  .container {
    padding: 0 12px; /* Equal padding on both sides */
  }
  
  .card {
    padding: 20px 16px; /* Equal horizontal padding */
  }
  
  .items-table {
    display: block;
    border-collapse: separate !important;
  }
  
  .items-table thead {
    display: none;
  }
  
  .items-table tbody,
  .items-table tr {
    display: block;
    width: 100% !important;
  }
  
  .items-table tr {
    border-bottom: 1px solid var(--border-color);
    padding: 16px 0 !important;
    margin-bottom: 12px;
    background: rgba(30, 38, 56, 0.3);
    border-radius: var(--radius-md);
    width: 100% !important;
    box-sizing: border-box;
  }
  
  .items-table td {
    display: block;
    width: 100% !important;
    padding: 6px 0 !important;
    text-align: center !important; /* CENTER ALL CONTENT */
    border: none !important;
    font-size: 14px !important;
    box-sizing: border-box;
  }
  
  /* Line 1: Бараа / Үйлчилгээний нэр (full width, centered) */
  .items-table tr td:first-child {
    font-weight: 600;
    font-size: 15px !important;
    margin-bottom: 10px;
  }
  
  /* Line 2: Тоо, Нэгж үнэ, Хөнгөлөлт (%) in a row */
  .items-table tr td:nth-child(2),
  .items-table tr td:nth-child(3),
  .items-table tr td:nth-child(4) {
    display: inline-block !important;
    width: 32% !important;
    vertical-align: top;
    text-align: center !important;
    font-size: 13px !important;
    margin: 4px 0 !important;
  }
  
  /* Add labels for the second line */
  .items-table tr td:nth-child(2):before { 
    content: "Тоо"; 
    display: block; 
    font-size: 11px; 
    color: var(--text-secondary); 
    margin-bottom: 4px;
    font-weight: 500;
  }
  
  .items-table tr td:nth-child(3):before { 
    content: "Нэгж үнэ"; 
    display: block; 
    font-size: 11px; 
    color: var(--text-secondary); 
    margin-bottom: 4px;
    font-weight: 500;
  }
  
  .items-table tr td:nth-child(4):before { 
    content: "Хөнгөлөлт"; 
    display: block; 
    font-size: 11px; 
    color: var(--text-secondary); 
    margin-bottom: 4px;
    font-weight: 500;
  }
  
  /* Line 3: Нийт (full width, centered, bold) */
  .items-table tr td:last-child {
    font-weight: 700;
    font-size: 16px !important;
    color: var(--accent-primary) !important;
    margin-top: 10px;
    padding-top: 10px !important;
    border-top: 1px solid var(--border-color) !important;
  }
  
  .items-table tr td:last-child:before { 
    content: "Нийт:"; 
    display: block; 
    font-size: 12px; 
    color: var(--text-secondary); 
    margin-bottom: 4px;
    font-weight: 500;
  }
  
  /* Action cell styling */
  .action-cell {
    display: block !important;
    width: 100% !important;
    margin-top: 12px !important;
    text-align: center !important;
  }
  
  .btn-remove {
    width: 100% !important;
    max-width: none !important;
    padding: 8px !important;
    font-size: 14px !important;
  }
}

/* ====== RESPONSIVE DESIGN ====== */
@media (max-width: 1023px) {
  .header {
    flex-direction: column;
    gap: 16px;
    text-align: center;
    width: 100%;
  }
  
  .logo-container {
    flex-direction: column;
    gap: 12px;
    width: 100%;
  }
  
  .brand-info h1 {
    font-size: 24px;
  }
  
  .brand-info p {
    font-size: 14px;
  }
  
  .preview-container {
    max-width: 800px;
    margin: 0 auto;
  }
}

@media (max-width: 767px) {
  .header {
    padding: 12px 0 20px;
  }
  
  .logo {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
  
  .brand-info h1 {
    font-size: 22px;
  }
  
  .brand-info p {
    font-size: 13px;
  }
  
  .card-title {
    font-size: 18px;
  }
  
  .preview-header,
  .preview-content,
  .preview-footer,
  .preview-actions {
    padding: 20px;
  }
  
  .preview-title {
    font-size: 28px;
  }
  
  .preview-subtitle {
    font-size: 16px;
  }
  
  .preview-section-title {
    font-size: 16px;
    text-align: center; /* Centered on mobile */
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .toggle-group {
    flex-direction: column;
  }
  
  .items-table th,
  .items-table td {
    padding: 10px 8px;
    font-size: 13px;
  }
  
  .form-control {
    padding: 12px 14px;
    font-size: 15px;
  }
  
  .btn {
    padding: 12px 20px;
    font-size: 15px;
  }
  
  .preview-actions .btn {
    padding: 14px 24px;
    font-size: 16px;
  }
  
  /* Fix for iOS input zooming */
  input, select, textarea {
    font-size: 16px !important;
  }
  
  /* Full width cards on mobile */
  .card, .form-section, .content {
    width: 100% !important;
  }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
  /* Prevent zoom on input focus */
  input, select, textarea {
    font-size: 16px !important;
  }
  
  /* Improve tap targets */
  .btn, .toggle-option, .upload-label {
    padding-top: 16px;
    padding-bottom: 16px;
  }
  
  /* Fix for safe area on iPhone X and newer */
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  
  .preview-container {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
}

/* Custom scrollbar for dark theme */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb {
  background: var(--accent-primary);
  border-radius: var(--radius-sm);
  border: 2px solid var(--bg-secondary);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-hover);
}

/* Animation for loading spinner */
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ====== CRITICAL FIX: PREVENT RIGHT-SIDE OVERFLOW ====== */
@media (max-width: 767px) {
  /* Target ONLY the overflowing elements */
  .items-table,
  .items-table tr,
  .items-table td,
  .preview-table,
  .preview-table td {
      max-width: 100% !important;
      overflow-x: hidden !important;
      box-sizing: border-box !important;
  }
  
  /* Force item rows to stay within container */
  .items-table tr {
      display: block !important;
      width: calc(100% - 16px) !important; /* Account for container padding */
      margin: 0 8px !important; /* Equal spacing on both sides */
      padding: 12px 8px !important;
      box-sizing: border-box !important;
  }
  
  /* Ensure "Нийт" cell doesn't push content right */
  .items-table tr td:last-child {
      width: 100% !important;
      text-align: center !important;
      padding: 8px 0 !important;
      margin-top: 8px !important;
      border-top: 1px solid var(--border-color) !important;
  }
  
  /* Remove any residual right-margin on containers */
  .card, .container, .form-section, .preview-section {
      margin-right: 0 !important;
      margin-left: 0 !important;
  }
  
  /* Critical: Reset body padding to symmetric values */
  body {
      padding-left: env(safe-area-inset-left) !important;
      padding-right: env(safe-area-inset-right) !important;
      overflow-x: hidden !important;
  }
  
  /* Container must have equal padding */
  .container {
      padding-left: 12px !important;
      padding-right: 12px !important;
  }
}

/* ====== UPLOAD CONTAINERS SIDE-BY-SIDE ON DESKTOP ====== */
.upload-containers-wrapper {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  margin-top: 16px; /* Matches spacing after form-grid */
}

/* Desktop: Side-by-side layout */
@media (min-width: 768px) {
  .upload-containers-wrapper {
    flex-direction: row;
  }
  
  .upload-containers-wrapper .upload-container {
    flex: 1;
    min-width: 0; /* Prevent overflow */
  }
  
  /* Equal gap between containers */
  .upload-containers-wrapper .upload-container:not(:last-child) {
    margin-right: 16px;
  }
}

/* Mobile: Keep stacked (default flex-direction: column) */
@media (max-width: 767px) {
  .upload-containers-wrapper {
    margin-top: 12px; /* Slightly tighter on mobile */
  }
  
  .upload-containers-wrapper .upload-container {
    width: 100%;
  }
}