/* ============================================
   Create Invoice Page
   ============================================ */

.create-invoice-page {
  padding: var(--space-6);
  max-width: 960px;
  margin: 0 auto;
  min-height: 100vh;
}

@media (min-width: 1600px) {
  .create-invoice-page { max-width: 1100px; }
  .invoice-header-compact h1 { font-size: 1.5rem; }
  .form-field-compact input,
  .form-field-compact select,
  .form-field-compact textarea { height: 42px; font-size: 15px; }
  .btn-submit-compact,
  .btn-cancel-compact { height: 44px; font-size: 15px; }
  .line-desc-compact,
  .line-qty-compact,
  .line-price-compact,
  .line-tax-compact { height: 38px; font-size: 14px; }
}

.invoice-header-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-5);
}

.invoice-header-compact h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.btn-back {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  transition: border-color var(--transition-fast), color var(--transition-fast);
  height: 32px;
}

.btn-back:hover {
  color: var(--text-primary);
  border-color: var(--gray-300);
  background: transparent;
}

.btn-template {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  height: 32px;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn-template:hover { background: var(--primary); color: #fff; }

/* Template panel */
.template-panel {
  margin-bottom: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.template-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--primary-light);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
}

.template-panel-close {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
  padding: 0 0.2rem;
}
.template-panel-close:hover { color: var(--danger); background: transparent; }

.template-list {
  max-height: 240px;
  overflow-y: auto;
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.template-loading {
  margin: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
}

.template-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.12s ease, border-color 0.12s ease;
}
.template-item:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

.template-item-number { font-weight: 600; font-size: 0.825rem; min-width: 100px; }
.template-item-client { flex: 1; font-size: 0.8rem; color: var(--text-secondary); }
.template-item:hover .template-item-client { color: inherit; }
.template-item-total { font-size: 0.8rem; font-weight: 500; white-space: nowrap; }

:root[data-theme='dark'] .template-panel { border-color: rgba(255,255,255,0.08); }
:root[data-theme='dark'] .template-panel-header { background: rgba(37,99,235,0.1); border-color: rgba(255,255,255,0.08); }
:root[data-theme='dark'] .template-item { border-color: rgba(255,255,255,0.08); }
:root[data-theme='dark'] .template-item:hover { background: rgba(37,99,235,0.12); border-color: rgba(37,99,235,0.4); }

.invoice-form-compact {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
}

.form-grid-compact {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.notes-grid-compact {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.form-field-compact {
  display: flex;
  flex-direction: column;
}

.form-field-compact.full-width {
  grid-column: 1 / -1;
}

.form-field-compact label {
  font-weight: 500;
  margin-bottom: var(--space-1);
  color: var(--text-secondary);
  font-size: 13px;
}

.form-field-compact input,
.form-field-compact select,
.form-field-compact textarea {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--card-bg);
  resize: vertical;
  font-family: inherit;
  transition: border-color var(--transition-fast);
  height: 36px;
}

.form-field-compact textarea {
  height: auto;
  min-height: 64px;
}

.form-field-compact input:focus,
.form-field-compact select:focus,
.form-field-compact textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.date-input-wrapper {
  position: relative;
  display: flex;
  align-items: stretch;
}

.date-input-wrapper input[type="date"] {
  flex: 1;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.date-input-wrapper input[type="date"]:focus {
  z-index: 1;
}

.date-picker-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.75rem;
  background: var(--primary);
  color: white;
  border: 1px solid var(--primary);
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.date-picker-btn:hover {
  background: var(--primary-hover, #1d4ed8);
}

.date-picker-btn:active {
  transform: scale(0.96);
}

.lines-section-compact {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--space-5);
}

.create-invoice-page .lines-section-compact {
  flex: 1;
  overflow: hidden;
}

.lines-header-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
}

.lines-header-compact h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.btn-add-compact {
  background: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  transition: border-color var(--transition-fast);
  height: 32px;
}

.btn-add-compact:hover {
  border-color: var(--gray-300);
}

.lines-table-compact {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.create-invoice-page .lines-table-compact {
  flex: 1;
  overflow-y: auto;
}

.line-row-compact {
  display: grid;
  grid-template-columns: 4fr 0.8fr 1.2fr 0.8fr 1.2fr auto;
  gap: var(--space-2);
  align-items: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
}

.line-desc-compact,
.line-qty-compact,
.line-price-compact,
.line-tax-compact {
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--card-bg);
  color: var(--text-primary);
  font-family: inherit;
  transition: border-color var(--transition-fast);
  height: 32px;
}

.line-desc-compact {
  width: 100%;
}

.line-desc-compact:focus,
.line-qty-compact:focus,
.line-price-compact:focus,
.line-tax-compact:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.line-total-compact {
  font-weight: 500;
  color: var(--text-primary);
  font-size: 13px;
  text-align: right;
  padding-right: var(--space-2);
  font-variant-numeric: tabular-nums;
}

.btn-delete-compact {
  background: transparent;
  color: var(--gray-400);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast), background-color var(--transition-fast);
  flex-shrink: 0;
  padding: 0;
}

.btn-delete-compact:hover {
  color: var(--danger);
  background: var(--red-50);
  border-color: transparent;
}

.form-actions-compact {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-color);
}

.btn-cancel-compact {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: border-color var(--transition-fast), color var(--transition-fast);
  height: 36px;
}

.btn-cancel-compact:hover {
  color: var(--text-primary);
  border-color: var(--gray-300);
  background: transparent;
}

.btn-submit-compact {
  background: var(--primary);
  color: white;
  border: none;
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: background-color var(--transition-fast);
  height: 36px;
}

.btn-submit-compact:hover {
  background: var(--primary-hover);
}

.btn-submit-compact:disabled {
  background: var(--gray-200);
  color: var(--gray-400);
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .create-invoice-page {
    padding: var(--space-3);
  }

  .form-grid-compact {
    grid-template-columns: 1fr;
  }

  .form-field-compact.full-width {
    grid-column: 1;
  }

  .notes-grid-compact {
    grid-template-columns: 1fr;
  }

  .line-row-compact {
    grid-template-columns: 1fr auto;
    gap: var(--space-2);
    padding: var(--space-3);
  }
}

:root[data-theme='dark'] .invoice-form-compact {
  background: #081226;
  border-color: #1e2f4d;
}

:root[data-theme='dark'] .line-row-compact {
  background: rgba(15, 23, 42, 0.6);
  border-color: #1e2f4d;
}

:root[data-theme='dark'] .line-desc-compact,
:root[data-theme='dark'] .line-qty-compact,
:root[data-theme='dark'] .line-price-compact,
:root[data-theme='dark'] .line-tax-compact {
  background: #0b1220;
  border-color: #1e2f4d;
  color: var(--text-primary);
}

:root[data-theme='dark'] .btn-add-compact {
  background: #0b1220;
  border-color: #1e2f4d;
  color: var(--text-primary);
}

:root[data-theme='dark'] .btn-add-compact:hover {
  border-color: #2d4a7a;
}

:root[data-theme='dark'] .btn-submit-compact:disabled {
  background: #1e2f4d;
  color: var(--text-secondary);
}
